Jump to content


Photo

Скрипт полной перезагрузки забагованного AI юнита


  • Please log in to reply
No replies to this topic

#1 OFFLINE   Ibragim

Ibragim

    Сержант

  • Пользователи
  • 161 posts

Posted 27 January 2021 - 01:32

PC_fn_get_unit_position_id = 
	{
		params ["_unit"];
		private ["_position_in_group"];
		for "_i" from 0 to (count units group _unit) - 1 do 
			{
				if (units group _unit select _i == _unit) then 
					{
						_position_in_group = _i + 1;
					};
			};
		_position_in_group;	
	};

PC_fn_unstuck = 
	{ 
		params ["_unit"];
		
		//if ((isPlayer _unit) || (lifeState _unit in PC_UNSATISFACTORY_LIFESTATE)) exitWith {};
		
		private _group = group _unit;
		private _position_in_group = _unit call PC_fn_get_unit_position_id;
		private _face = face _unit;
		private _name = name _unit;
		private _name_and_surname = (name _unit splitString "([ ]/:)"); 
		private _type = typeOf _unit;
		private _rank = rank _unit;
		private _skill = skill _unit;
		
		private _damage = damage _unit;
		private _suppression = getSuppression _unit;
		private _animation_speed = getAnimSpeedCoef _unit;
		private _behaviour = behaviour _unit;
		
		private _position = position _unit;
		private _direction = getDir _unit;
		private _unit_pos = unitPos _unit;
		private _animation = animationState _unit;
		
		private _assigned_items = assignedItems _unit;
		private _uniform_items = uniformItems _unit;
		private _vest_items = vestItems _unit;
		private _backpack_items = backpackItems _unit;
		
		private _magazines = magazines _unit; 
		private _magazinesAmmoFull = magazinesAmmoFull _unit; 
		
		private _primary_weapon = primaryWeapon _unit;
		private _primary_weapon_items = primaryWeaponItems _unit;
		
		private _secondary_weapon = secondaryWeapon _unit;
		private _secondary_weapon_items = secondaryWeaponItems _unit;
		
		private _handgun_weapon = handgunWeapon _unit;
		private _handgun_weapon_items = handgunItems _unit;
		
		private _headgear = headgear _unit;
		private _uniform = uniform _unit;
		private _vest = vest _unit;
		private _backpack = backpack _unit;
		private _hmd = hmd _unit;
		private _goggles = goggles _unit;
		
		private _magazines_to_add_after_weapon = [];
		
		//private _all_traits = getAllUnitTraits _unit;
		private _all_traits = [];
			{
				_all_traits pushBack [_x, (_unit getUnitTrait _x)];
			} forEach ["audibleCoef","camouflageCoef","loadCoef","engineer","explosiveSpecialist","medic","UAVHacker"];
		
		private _all_hit_points = getAllHitPointsDamage _unit;
		
		/// Убираем магазины из списка экипировки, они добавляются с учетом зарядов в них:
		
			{
				if (_x in _magazines) then 
					{
						_uniform_items = _uniform_items - [_x];
					};
			} forEach _uniform_items;
			{
				if (_x in _magazines) then 
					{
						_backpack_items = _backpack_items - [_x];
					};
			} forEach _backpack_items;
			{
				if (_x in _magazines) then 
					{
						_vest_items = _vest_items - [_x];
					};
			} forEach _vest_items;
		
		/// Создаем копию юнита, переносим личные характеристики:
		
		private _new_unit = (createGroup [side _unit, true]) createUnit [_type, _position, [], 0, "CAN_COLLIDE"];
		_new_unit setDir _direction;
		_new_unit setUnitPos _unit_pos;
		_new_unit switchMove _animation; 
		_new_unit setSkill _skill;
		_new_unit setRank _rank;
		_new_unit setName [_name, _name_and_surname select 0, _name_and_surname select 1];
		_new_unit setFace _face; 
		
		if (_unit == leader _group) then 
			{
				_group selectLeader _new_unit;
				_group setCurrentWaypoint [_group,((currentWaypoint _group))]; 
			};
		if (_unit in switchableUnits) then 
			{
				addSwitchableUnit _new_unit;
			};
		_new_unit setSuppression _suppression;
		_new_unit setDamage _damage; 
		_new_unit setAnimSpeedCoef _animation_speed;
		_new_unit setBehaviour _behaviour;
		
			{				
				_new_unit setUnitTrait [(_x select 0), (_x select 1)];
			} forEach _all_traits;
			
			for "_i" from 0 to 11 do 
				{					
					_new_unit setHitPointDamage [(_all_hit_points select 0 select _i), (_all_hit_points select 2 select _i)];
				};
		
		/// Меняем экипировку:
		
		removeUniform _new_unit;
		_new_unit forceAddUniform _uniform;
			
		removeVest _new_unit;
		_new_unit addVest _vest;
			
		removeBackpack _new_unit;
		_new_unit addBackpack _backpack;
		
		removeHeadgear _new_unit;
		_new_unit addHeadgear _headgear;

		_new_unit unlinkItem (goggles _new_unit);
		_new_unit addGoggles _goggles;
		_new_unit linkItem _goggles;
			
		
		/// Добавляем магазины:
		
			{
				if (_new_unit canAdd (_x select 0)) then 
					{ 
						_new_unit addMagazine [_x select 0, _x select 1];
					} else 
						{
							_magazines_to_add_after_weapon = _magazines_to_add_after_weapon + [_x];
						};
			} forEach _magazinesAmmoFull;
			
		/// Заменяем оружие:
		
		_new_unit removeWeapon (primaryWeapon _new_unit); 
		_new_unit addWeapon _primary_weapon;
			{
				_new_unit addPrimaryWeaponItem _x; 
			} forEach _primary_weapon_items;
			
		_new_unit removeWeapon (secondaryWeapon _new_unit); 
		_new_unit addWeapon _secondary_weapon;
			{
				_new_unit addSecondaryWeaponItem _x; 
			} forEach _secondary_weapon_items;
			
		_new_unit removeWeapon (handgunWeapon _new_unit); 
		_new_unit addWeapon _handgun_weapon;
			{
				_new_unit addHandgunItem _x; 
			} forEach _handgun_weapon_items;
		
			{
				_new_unit addMagazine [_x select 0, _x select 1];
			} forEach _magazines_to_add_after_weapon;
			
		/// Добавляем вещи по карманам:
				
			{
				_new_unit addItem _x; 
			} forEach (_uniform_items)+(_vest_items)+(_backpack_items);			
			
		/// Меняем все закрепленные вещи:
		
			{
				_new_unit unassignItem _x;
				_new_unit removeItem _x;
			} forEach assignedItems _new_unit;
			{
				_new_unit addItem _x;
				_new_unit assignItem _x;
			} forEach _assigned_items;
			
		/// Удаляем старого юнита и подключаем к группе нового:
		
		deleteVehicle _unit;
		_new_unit joinAsSilent [_group, _position_in_group];
	};

/// Запуск перезагрузки:

[_unit] call PC_fn_unstuck;

  • 0




Яндекс.Метрика