Jump to content

Spawn ai behind selected player

Recommended Posts

Hi, i'm using this script to spawn ai's near a selected player near a marker. Any suggestion how to improve this script? And how could i make so the ai's spawn behind the selected player?

while {true} do {

waitUntil {sleep 10; ({(_x distance2d getMarkerpos "Marker1") < 200} count allPlayers > 0)};

_playercount = []; 

 if (isPlayer _x) then {
   if (_x distance getmarkerpos "Marker1" <200) then {
         _playercount pushBack _x; 
} foreach playableUnits; 

_unit =  _playercount select (floor random count _playercount);

private _grp01 = [_unit getpos [250,random 50], west, ["uns_men_NVA_recon_65_AT2","uns_men_NVA_65_LMG","uns_men_NVA_65_AS5","uns_men_NVA_65_AA","uns_men_NVA_65_HMG"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup;

{_x setBehaviour "Aware"; _x setSpeedMode "FULL"; _x setFormation "LINE"; _x setCombatMode "Red"} forEach [_grp01];

{_x setSkill ["AimingAccuracy",0.01]} forEach (units _grp01);

_grp01 enableDynamicSimulation true;
_grp01 allowFleeing 0;
_grp01 deleteGroupWhenEmpty true;

_wp01 = _grp01 addWaypoint [_unit,(10 + floor (random 10))];
_wp01 setWaypointType "SAD";

{_x addCuratorEditableObjects [units _grp01, true];} foreach allCurators;

waitUntil {sleep 5; {alive _x} count units _grp01 == 0};

{deleteVehicle _x;} forEach units _grp01;
deleteGroup _grp01;
{deleteVehicle _x;} count allDead;

sleep 30;


Share this post

Link to post
Share on other sites

To get the players you can use

_playercount = playableUnits select {_x distance getMarkerPos "Marker1" < 200 && isPlayer _x}


For a random unit just use

_unit = selectRandom _playercount

To spawn the unit behind just change _unit getpos [250,random 50] to _unit getpos [-250,random 50]

Or if you want a random distance: _unit getPos [random[-40, -100, -250], random 50] (-40 is the minimum distance, -100 the mid distance and -250 the maximum distance)


If you ONLY need to wait, remove the sleep from waitUntil.




  • Like 1

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