Jump to content
-ami- mofo

Spawn AI in timed waves with one trigger?

Recommended Posts

Hi guys I'm wanting to spawn a few AI groups every so often at regular intervals (say every 30 seconds) on different markers as players descend onto a town. I've got it working fine by using half a dozen triggers all with their centers at the same point but each one with a smaller radius than the last.

 

But I'd really like to make it all happen with just one trigger.

 

Quick example of what I have now:-

 

The 1st trigger with 1200m radius with this... 

 

Quote

grp = [getmarkerpos "M10", independent, 6] call bis_fnc_spawngroup; 
[grp, getmarkerpos "M10", 150] call BIS_fnc_taskPatrol;
grp setbehaviour "combat";

        _x removeAllEventHandlers "HandleDamage"; 
        _x addEventHandler ["HandleDamage",{ 
            _damage = (_this select 2)*1.5; 
            _damage 
        }]; 
}forEach units grp;

 

 

Then the 2nd trigger with 1150m radius with this...

 

Quote

grp = [getmarkerpos "M11", independent, 6] call bis_fnc_spawngroup; 
[grp, getmarkerpos "M11", 150] call BIS_fnc_taskPatrol;
grp setbehaviour "combat";

        _x removeAllEventHandlers "HandleDamage"; 
        _x addEventHandler ["HandleDamage",{ 
            _damage = (_this select 2)*1.5; 
            _damage 
        }]; 
}forEach units grp;

 

And so on for a total of 6 different triggers, 6 different markers and 6 different timed spawns.

 

So is it possible to put all this scripting into just 1 trigger and have each lot fire at 30 second intervals?

 

Thanks.

Share this post


Link to post
Share on other sites

0 = [] spawn {

private _i =0;

  while {_i < 6} do {

   _i = _i + 1;

   grp = [getmarkerpos "M10", independent, 6] call bis_fnc_spawngroup; 
   [grp, getmarkerpos "M10", 150] call BIS_fnc_taskPatrol;
   grp setbehaviour "combat";
   { 
     _x removeAllEventHandlers "HandleDamage"; 
     _x addEventHandler ["HandleDamage",{ 
       _damage = (_this select 2)*1.5; 
       _damage 
     }]; 
   } forEach units grp;

   sleep 30;

  };

};

Share this post


Link to post
Share on other sites

Hi mate

 

Thanks for that, is there a way to get them to spawn on different markers though as they all spawn on the same one?

 

EDIT- actually don't worry mate, they all head out patrolling in different directions so all good. 

 

Thanks :-)

 

 

Share this post


Link to post
Share on other sites
4 hours ago, -ami- mofo said:

Hi mate

 

Thanks for that, is there a way to get them to spawn on different markers though as they all spawn on the same one?

 

EDIT- actually don't worry mate, they all head out patrolling in different directions so all good. 

 

Thanks :-)

 

 

 

Made something similar sometime ago,

quickly adjusted it for your purpose to spawn at least one group per marker,

each group patrols around the marker it was spawned at,

spawn order is randomized, randomized amount of groups per marker and random amount of units per group,

to add diversity and replayability:

 

//init.sqf or similar

TAG_fnc_spawnGroupsOnMarkers = {

	params ["_markers","_grpSide","_rndGrpSize","_grpsPerMarker","_spawnDelay",["_debug",false]];

	_max = count _markers;
	_totalGroups = 0;
	_totalUnits = 0;

	for "_i" from 1 to count _markers do {
       
	   _rndMarker = selectRandom _markers;
	   _markers = _markers - [_rndMarker];
	   _getGrpsPerMarker = round random _grpsPerMarker;
	   if (_debug) then {
	   _counter = format ["%1/%2",_i,_max];
	   	systemchat format ["%1: Spawning %2 %3 at marker %4!",_counter,_getGrpsPerMarker,["group","groups"] select (_getGrpsPerMarker > 1),_rndMarker];};

	   for "_s" from 1 to _getGrpsPerMarker do {

			_grpSize = round random _rndGrpSize;
			_totalUnits = _totalUnits + _grpSize;
			_totalGroups = _totalGroups + 1;
		   _grp = [getmarkerpos _rndMarker, _grpSide, _grpSize] call bis_fnc_spawngroup;
		   [_grp, getmarkerpos _rndMarker, 150] call BIS_fnc_taskPatrol;
		   
		   if (_debug) then {systemchat format ["Marker %1 %2 group spawned, %3 units! Waiting %4 seconds.",_rndMarker,[_s] call BIS_fnc_ordinalNumber,_grpSize,_spawnDelay];playsound "Click"};
		   sleep _spawnDelay;
		};

	};

	if (_debug) then {systemchat format ["Spawning done! %1 units in %2 groups!",_totalUnits,_totalGroups]};

};

//now to use it:

_markers = ["M1","M2","M3","M4","M5","M6"];//array with all markers that get at least one group
_side = independent;//side to spawn
_groupSize = [4,6,10];//will spawn groups with at least 4 units, mostly 6 and rarely 10 units
_groupsPerMarker = [1,1,5];//will spawn at least one group, mostly one group and rarely 5 groups per marker
_spawnDelay = 30;//delay between spawning each group
_debug = true;//set to false to disable debugging messages
_test = [_markers,_side,_groupSize,_groupsPerMarker,_spawnDelay,_debug] spawn TAG_fnc_spawnGroupsOnMarkers;

Added a few comments, it's probably more than you want but thought I'd share anyway.

It's also possible to modify this to make units patrol between all given markers and random positions around those markers if you want.

You could even use the markers to describe the outter borders of a polygon and make all spawned groups patrol the inside of that polygon but that's probably beyond your needs, heh.

 

Cheers

 

Share this post


Link to post
Share on other sites

Thanks Grumpy that script works a treat. I've altered some of the numbers to lessen the amount of AI a bit and it's crankin :-)

  • Like 1

Share this post


Link to post
Share on other sites

Hey Grumpy can you link this to a "Tower" and make it repeat until the tower is destroyed? Also set it to a RHS special forces group?

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

×