Jump to content
DOA

Help spawning ai group with tracer mags

Recommended Posts

Hi all,

I've cobbled together a few scripts I found to spawn a group of AI, assign them waypoints and cause them to respawn.
The group being spawned is made up of CUP TAK Militia units. I would like the AI units that spawn and again when they respawn to be equipped with green tracer rounds.
It would be great to incorporate this into my existing AISpawnManger.sqf,  but calling a separate script for all units in a waypoint or any other method of changing the AI group members, who are carrying CUP AK 74s, load out to green tracer rounds would be appreciated. I'll post my spawnmanager sqf in this post but again if a separate script run on these men in a trigger or something else is needed that works fine for me. The idea is to have this group spawn in and follow it's waypoints and the riflemen in the spawned group, be equipped with green tracer rounds.
Thanks in advance for your time and efforts helping with this.

// AISpawnManager_group1. 10 men

//Spawn AI Group using BIS_SpawnGroup function. 

//Spawn _group1
_group1 = [getMarkerPos "_group1_spawn", EAST, ["CUP_O_TK_INS_Commander","CUP_O_TK_INS_Mechanic","CUP_O_TK_INS_Soldier_AR","CUP_O_TK_INS_Soldier","CUP_O_TK_INS_Bomber","CUP_O_TK_INS_Soldier_TL","CUP_O_TK_INS_Mechanic","CUP_O_TK_INS_Soldier","CUP_O_TK_INS_Soldier_AT","CUP_O_TK_INS_Guerilla_Medic"]] call BIS_fnc_spawnGroup;

//Assign _group1 WayPoints
_wp1_grp1 = _group1 addWaypoint [getmarkerpos "wp1_grp1", 0];
_wp1_grp1 setWaypointType "MOVE";
_wp1_grp1 setWaypointSpeed "NORMAL";
_wp1_grp1 setWaypointBehaviour "SAFE";
_wp1_grp1 setWaypointFormation "WEDGE";
[_group1, 1] setWaypointTimeout [10, 15, 20];

_wp2_grp1 = _group1 addWaypoint [getmarkerpos "wp2_grp1", 0];
_wp2_grp1 setWaypointType "MOVE"; 
_wp2_grp1 setWaypointSpeed "NORMAL";
_wp2_grp1 setWaypointBehaviour "SAFE";
_wp2_grp1 setWaypointFormation "WEDGE";
[_group1, 2] setWaypointTimeout [10, 15, 20];

_wp3_grp1 = _group1 addWaypoint [getmarkerpos "wp3_grp1", 0];
_wp3_grp1 setWaypointType "MOVE";
_wp3_grp1 setWaypointSpeed "NORMAL";
_wp3_grp1 setWaypointBehaviour "SAFE";
_wp3_grp1 setWaypointFormation "WEDGE";
[_group1, 3] setWaypointTimeout [10, 15, 20];

_wp4_grp1 = _group1 addWaypoint [getmarkerpos "wp4_grp1", 0];
_wp4_grp1 setWaypointType "MOVE";
_wp4_grp1 setWaypointSpeed "NORMAL";
_wp4_grp1 setWaypointBehaviour "SAFE";
_wp4_grp1 setWaypointFormation "WEDGE";
[_group1, 4] setWaypointTimeout [10, 15, 20];

_wp5_grp1 = _group1 addWaypoint [getmarkerpos "wp5_grp1", 0];
_wp5_grp1 setWaypointType "CYCLE";
_wp5_grp1 setWaypointSpeed "NORMAL";
_wp5_grp1 setWaypointBehaviour "SAFE";
_wp5_grp1 setWaypointFormation "WEDGE";
[_group1, 5] setWaypointTimeout [10, 15, 20];

// Respawn _group1
_group1 spawn { 
  _group1 = _this; 
  private "_unit"; 
  while {count units _group1 > 0} do { 
        for "_i" from 0 to count (units _group1) - 1 do { 
          _unit = units _group1 select _i; 
          if !(_unit getVariable ["_ready",false]) then { 
            _unit setVariable ["_type",typeOf _unit]; 
            _unit setVariable ["_dir",getdir _unit]; // not used here
            _unit setVariable ["_side",side _unit]; 
            _unit setVariable ["_group",_group1]; 
            _unit addEventHandler ["killed", { 
              _fellow = _this select 0; 
              _newbie =  (_fellow getVariable "_type") createUnit [getMarkerPos "_group1_spawn", _fellow getVariable "_group"]; 
              _newbie setVariable ["_ready", false]; 
              _fellow setVariable ["_ready", nil]; 
              //deleteVehicle _fellow; 
           }]; 
           _unit setVariable ["_ready", true]; 
         }; 
       }; 
       sleep 1; 
    }; 
  };



 

Share this post


Link to post
Share on other sites

This will replace a units magazines to another compatible mag depending on index given:

 

GOM_fnc_replaceMags = {

	params ["_unit","_weapon","_magIndex"];

	_compatibleMags = getArray (configfile >> "CfgWeapons" >> _weapon >> "magazines");
	_currentAmount = count (magazines _unit select {_x in _compatibleMags}) + 1;//add one for currently loaded mag
	{_unit removeMagazines _x} forEach _compatibleMags;
	_unit removeWeapon _weapon;

	_addedMuzzle = [_unit,_weapon,_currentAmount,_magIndex] call BIS_fnc_addWeapon;
	_unit selectWeapon _addedMuzzle;//to prevent switching animation
	true
};

[player,primaryWeapon player,3] call GOM_fnc_replaceMags;//in case of "CUP_arifle_AK74" you need to use 3 to get red tracers

Cheers

Share this post


Link to post
Share on other sites

Thank you from one grumpy old man to another. Much appreciated.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×