Halvhjearne

DZMSAISpawn.sqf

Feb 28th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.10 KB | None | 0 0
  1. /*                                                                      //
  2.     DZMSAISpawn.sqf by Vampire
  3.     Usage: [position,unitcount,skillLevel] execVM "dir\DZMSAISpawn.sqf";
  4.         Position is the coordinates to spawn at [X,Y,Z]
  5.         UnitCount is the number of units to spawn
  6.         SkillLevel is the skill number defined in DZMSAIConfig.sqf
  7. */                                                                      //
  8. private ["_position","_unitcount","_skill","_wpRadius","_xpos","_ypos","_unitGroup","_aiskin","_unit","_weapon","_magazine","_wppos1","_wppos2","_wppos3","_wppos4","_wp1","_wp2","_wp3","_wp4","_wpfin","_unitArrayName","_unitMissionCount"];
  9. _position = _this select 0;
  10. _unitcount = _this select 1;
  11. _skill = _this select 2;
  12. _unitArrayName = _this select 3;
  13.  
  14. //diag_log text format ["[DZMS]: AI Pos:%1 / AI UnitNum: %2 / AI SkillLev:%3",_position,_unitcount,_skill];
  15.  
  16. _wpRadius = 20;
  17.  
  18. _xpos = _position select 0;
  19. _ypos = _position select 1;
  20.  
  21. //Create the unit group. We use east by default.
  22. _unitGroup = createGroup east;
  23.  
  24. //Probably unnecessary, but prevents client AI stacking
  25. if (!isServer) exitWith {};
  26.  
  27. for "_x" from 1 to _unitcount do {
  28.  
  29.     //Lets pick a skin from the array
  30.     _aiskin = DZMSBanditSkins call BIS_fnc_selectRandom;
  31.    
  32.     //Lets spawn the unit
  33.     _unit = _unitGroup createUnit [_aiskin, [(_position select 0),(_position select 1),(_position select 2)], [], 10, "PRIVATE"];
  34.    
  35.     //Make him join the correct team
  36.     [_unit] joinSilent _unitGroup;
  37.    
  38.     //Add the behaviour
  39.     _unit enableAI "TARGET";
  40.     _unit enableAI "AUTOTARGET";
  41.     _unit enableAI "MOVE";
  42.     _unit enableAI "ANIM";
  43.     _unit enableAI "FSM";
  44.     _unit setCombatMode "YELLOW";
  45.     _unit setBehaviour "COMBAT";
  46.    
  47.     //Remove the items he spawns with by default
  48.     removeAllWeapons _unit;
  49.     removeAllItems _unit;
  50.    
  51.     //Now we need to figure out their loadout, and assign it
  52.    
  53.     //Get the weapon array based on skill
  54.     _weaponArray = [_skill] call DZMSGetWeapon;
  55.    
  56.     _weapon = _weaponArray select 0;
  57.     _magazine = _weaponArray select 1;
  58.    
  59.     //diag_log text format ["[DZMS]: AI Weapon:%1 / AI Magazine:%2",_weapon,_magazine];
  60.    
  61.     //Get the gear array
  62.     _gearmagazines = DZMSGear0 select 0;
  63.     _geartools = DZMSGear0 select 1;
  64. //  _aigearArray = [DZMSGear0,DZMSGear1,DZMSGear2,DZMSGear3,DZMSGear4];
  65. //  _aigear = _aigearArray call BIS_fnc_selectRandom;
  66. //  _gearmagazines = _aigear select 0;
  67. //  _geartools = _aigear select 1;
  68.    
  69.     //Gear the AI backpack
  70.     _aipack = DZMSPacklist call BIS_fnc_selectRandom;
  71.  
  72.     //Lets add it to the Unit
  73.     for "_i" from 1 to 3 do {
  74.         _unit addMagazine _magazine;
  75.     };
  76.     _unit addWeapon _weapon;
  77.     _unit selectWeapon _weapon;
  78.    
  79.     _unit addBackpack _aipack;
  80.    
  81.     if (DZMSUseNVG) then {
  82.         //not all ai get nvg
  83.         _rnd = (random 99);
  84.         _chn = 35;
  85.         if(_rnd < _chn)then{
  86.             _unit addWeapon "NVGoggles";
  87.         };
  88.     };
  89.    
  90.     {
  91.         _mc = _x;
  92.         _mag = _mc select 0;
  93.         _chn = _mc select 1;
  94.         _rnd=floor(random 99);
  95.         if(_rnd < _chn)then{
  96.             _unit addMagazine _mag;
  97. //          diag_log format ["[DZMS]: AI added:%1 / _rnd:%2 _chn:%3",_mag,_rnd,_chn];
  98.         };
  99.     } forEach _gearmagazines;
  100.    
  101.     {
  102.         _wc = _x;
  103.         _wea = _wc select 0;
  104.         _chn = _wc select 1;
  105.         _rnd=floor(random 99);
  106.         if(_rnd < _chn)then{
  107.             _unit addWeapon _wea;
  108. //          diag_log format ["[DZMS]: AI added:%1 / _rnd:%2 _chn:%3",_wea,_rnd,_chn];
  109.         };
  110.     } forEach _geartools;
  111. /*
  112.     {
  113.         _unit addMagazine _x
  114.     } forEach _gearmagazines;
  115.    
  116.     {
  117.         _unit addWeapon _x
  118.     } forEach _geartools;
  119. */
  120.     //Lets set the skills
  121.     switch (_skill) do {
  122.         case 0: {_aicskill = DZMSSkills1;};
  123.         case 1: {_aicskill = DZMSSkills2;};
  124.         case 2: {_aicskill = DZMSSkills3;};
  125.     };
  126.    
  127.     {
  128.         _unit setSkill [(_x select 0),(_x select 1)]
  129.     } forEach _aicskill;
  130.    
  131.     //Lets prepare the unit for cleanup
  132.     _unit addEventHandler ["Killed",{ [(_this select 0), (_this select 1)] ExecVM DZMSAIKilled; }];
  133.     _unit setVariable ["DZMSAI", true];
  134. };
  135.  
  136. //Lets give a launcher if enabled
  137. //The last _unit should still be defined from the FOR above
  138. if (DZMSUseRPG) then {
  139.     //not all ai get rpg
  140.     _rnd = (random 99);
  141.     _chn = 35;
  142.     if(_rnd < _chn)then{
  143.         _unit addWeapon "RPG7V";
  144.         _unit addMagazine "PG7V";
  145.         _unit addMagazine "PG7V";
  146.     };
  147. };
  148.  
  149. // These are 4 waypoints in a NorthSEW around the center
  150. _wppos1 = [_xpos, _ypos+20, 0];
  151. _wppos2 = [_xpos+20, _ypos, 0];
  152. _wppos3 = [_xpos, _ypos-20, 0];
  153. _wppos4 = [_xpos-20, _ypos, 0];
  154.  
  155. // We add the 4 waypoints
  156. _wp1 = _unitGroup addWaypoint [_wppos1, _wpRadius];
  157. _wp1 setWaypointType "MOVE";
  158. _wp2 = _unitGroup addWaypoint [_wppos2, _wpRadius];
  159. _wp2 setWaypointType "MOVE";
  160. _wp3 = _unitGroup addWaypoint [_wppos3, _wpRadius];
  161. _wp3 setWaypointType "MOVE";
  162. _wp4 = _unitGroup addWaypoint [_wppos4, _wpRadius];
  163. _wp4 setWaypointType "MOVE";
  164.  
  165. // Then we add a center waypoint that tells them to visit the rest
  166. _wpfin = _unitGroup addWaypoint [[_xpos,_ypos, 0], _wpRadius];
  167. _wpfin setWaypointType "CYCLE";
  168.  
  169. //diag_log text format ["[DZMS]: Spawned %1 AI at %2",_unitcount,_position];
  170.  
  171. // load the unit groups into a passed array name so they can be cleaned up later
  172. call compile format["
  173. %1 = %1 + (units _unitGroup);
  174. _unitMissionCount = count %1;
  175. ",_unitArrayName];
  176.  
  177. diag_log text format["[DZMS]: (%3) %1 AI Spawned, %2 units in mission.",count (units _unitGroup),_unitMissionCount,_unitArrayName];
Advertisement
Add Comment
Please, Sign In to add comment