Jump to content
Sign in to follow this  
colinm9991

AI Spawn Limitator - Spawning as AI Die

Recommended Posts

I am working on a Base Defense mission which spawns dozens of enemies and sends them to the base which you must defend; obviously for optimization purposes I am trying to limit the amount of AI that spawn, I've tried using the following as a wrapper with the rest of the code being executed inside

if (( {(side _x) == east} count allUnits) <= 30 ) then { } else { } ;

Doesn't work, over 80-100+ AI will spawn.

This is the spawning section of the script, I'm thinking myself that it may be something to do with the loop

if (isnil "DZ_Spawn_INF") then {
DZ_Spawn_INF = {
       private ["_unit", "_loc", "_wp", "_spawned", "_logicS", "_logicE", "_unitarray", "_side", "_faction", "_MaxInf", "_locA"];
       _unit = _this select 0;
       _logicS = _this select 1;
       _logicE = _this select 2;
       _side = _this select 3;
       _faction = _this select 4;
       _MaxInf = _this select 5;
// spawn infantry a random of 5 times
   for "_i" from 1 to (ceil(random _MaxInf)) + 5 do 
       {
           _unitarray = (_unit getVariable "infantry") select floor(random(count (_unit getVariable "infantry")));
           _loc = _logicS select floor(random(count _logicS));
           // spawn random units
           _spawned = [getPos _loc, _side, (configFile >> "CfgGroups" >> (str _side) >> _faction >> "Infantry" >> _unitarray),[],[],[],[],[],180] call BIS_fnc_spawnGroup;
           // move units to waypoint
           _locA = _logicE select floor (random(count _logicE));
           _wp = _spawned addWaypoint [position _locA, 0];
           _wp setWaypointType "SAD"; 
           _wp setWaypointSpeed "NORMAL";
           [_spawned, 0] setWaypointBehaviour "AWARE";
           sleep (random 20);
       };
   };	
};

Share this post


Link to post
Share on other sites

Give me more information about

_unit = _this select 0;

_logicS = _this select 1;

_logicE = _this select 2;

_side = _this select 3;

_faction = _this select 4;

_MaxInf = _this select 5;

And How you call the script ! i am sure i can help

Share this post


Link to post
Share on other sites

The loop responsible for spawning in this script is at the very end of the script.

Here's a modified version I used to somehow limit the number of units:

http://pastebin.com/3eYYgGm5

Note that this doesn't really limit the number, it just waits until the total count of units is under 200 before starting a new wave. Knowing about how many units you spawn each wave, it's enough for me.

Let's add that this script was originally written by Igneous01.

Share this post


Link to post
Share on other sites

Thank you BlackMamb, I will try that out.

Ios, the script in question is this one here Random Unit Invasion Script

--Update--

Doesn't work BlackMamb, brought the number down to 30; over 200 units spawn still.

Edited by ColinM9991

Share this post


Link to post
Share on other sites

Hmmm. Maybe I've changed something else. Damn me and not documenting my stuff.

How many units do you spawn each wave?

Share this post


Link to post
Share on other sites

"nul = [RUS, [R1, R2, R3], [A1, A2, A3], 600, 20] execVM "scripts\RUIS.sqf"

600 seconds, 20 waves.

spawntimer - the amount of time to wait before spawning new units (in seconds)

Scripttime - the amount of waves you wish the script to run

If I'm reading correctly, it should wait 600 seconds before spawning a new wave (I increased the timer for testing purposes) but it seems that it just spawns waves regardless of what timer is set.

Three markers should equal to 30 people per wave.

_MaxInf = 10;    // Maximum amount of infantry that can be spawned in a single wave
_MaxV = 3;	     // Max amount of vehicles to spawn
_MaxLA = 3;     // Max amount of light armored in a single wave
_MaxArm = 1;    // Max amount of armor
_MaxAir = 1;    // Max amount of air
_PInf = 100;    // Percentage chance of Infantry being spawned (100% = everytime, 0% = never)
_PV = 85;       // Percentage chance of vehicles spawning
_PLA = 5;      // Percentage chance of Light vehicles being spawned
_PArm = 5;	    // Percentage chance of Armor being spawned
_PAir = 5;     // Percentage chance of Air being spawned

Share this post


Link to post
Share on other sites

Explication : when you call this script using :

"nul = [RUS, [R1, R2, R3], [A1, A2, A3], 600, 20] execVM "scripts\RUIS.sqf"

and this configuration :

_MaxInf = 10; // Maximum amount of infantry that can be spawned in a single wave

_MaxV = 3; // Max amount of vehicles to spawn

_MaxLA = 3; // Max amount of light armored in a single wave

_MaxArm = 1; // Max amount of armor

_MaxAir = 1; // Max amount of air

_PInf = 100; // Percentage chance of Infantry being spawned (100% = everytime, 0% = never)

_PV = 85; // Percentage chance of vehicles spawning

_PLA = 5; // Percentage chance of Light vehicles being spawned

_PArm = 5; // Percentage chance of Armor being spawned

_PAir = 5; // Percentage chance of Air being spawned

There is 100% chance that 25 groups of 5-15 units spawn, (the script add a minimum of 5 group)

5% chance that 3 light vehicles spawn

5% chance 1 armored vehicle & 5 chance Air vehicle spawn

IN ONE WAVE !

that is pretty too much :)

you have to edit variable is RUIS script , exemple using same script call line

nul = [RUS, [R1, R2, R3], [A1, A2, A3], 600, 20] execVM "scripts\RUIS.sqf"

and modifying variable in the script like that :

_MaxInf = 0; // Maximum amount of infantry that can be spawned in a single wave

_MaxV = 3; // Max amount of vehicles to spawn

_MaxLA = 3; // Max amount of light armored in a single wave

_MaxArm = 1; // Max amount of armor

_MaxAir = 1; // Max amount of air

_PInf = 100; // Percentage chance of Infantry being spawned (100% = everytime, 0% = never)

_PV = 85; // Percentage chance of vehicles spawning

_PLA = 5; // Percentage chance of Light vehicles being spawned

_PArm = 5; // Percentage chance of Armor being spawned

_PAir = 5; // Percentage chance of Air being spawned

There will be 5 group of 5-15 units (cause the script call a minimum of 5 group, you have to change this line

for "_i" from 1 to (ceil(random _MaxInf)) + 5 do
5 is the minimum group the script add.

trying to explain you but its hard if you have an exact number of ennemy you want to spawn, maybe i can give you an exemple mission

Share this post


Link to post
Share on other sites
Explication : when you call this script using :

and this configuration :

There is 100% chance that 25 groups of 5-15 units spawn, (the script add a minimum of 5 group)

5% chance that 3 light vehicles spawn

5% chance 1 armored vehicle & 5 chance Air vehicle spawn

IN ONE WAVE !

that is pretty too much :)

you have to edit variable is RUIS script , exemple using same script call line

and modifying variable in the script like that :

There will be 5 group of 5-15 units (cause the script call a minimum of 5 group, you have to change this line 5 is the minimum group the script add.

trying to explain you but its hard if you have an exact number of ennemy you want to spawn, maybe i can give you an exemple mission

I want high numbers to spawn as it is indeed a base defense mission designed to put the shakes in who ever plays :p

It's just that it spawns a bit too much on its own, so without removing too many numbers I was trying to figure out a way to pause the script with something along the lines of "waitUntil {(count allUnits) < 73};" where when the units are under 60 it will begin spawning again.

This basically means, there are always 60 enemies spawned in. (< 73 also includes the West playable characters).

So to answer your question, I'd say about 60 per wave.

Share this post


Link to post
Share on other sites

http://rapidshare.com/share/76FA5A9E31EEB0CA3DE2FDF85343442B

you can download RUIS.script modified from here,

you can call it like before,

"nul = [RUS, [R1, R2, R3], [A1, A2, A3], 600, 20] execVM "scripts\RUIS.sqf"

600 time between each wave, (wave are set to be between 30-72 units)

and 20 the number of wave,

before spawning a new wave it will waitUntil {(count allUnits) < 73};

you should integrate a cleaner script in your mission, to remove dead body and empty group , there is one in RUS script but it is only run 1 time per wave

Edited by Ios
almost forgot

Share this post


Link to post
Share on other sites

I created a base defense mission for the Unsung Vietnam War Mod with something like what you're after. In my case I wanted hordes of Viet Cong infantry storming the base from different directions all at once (it was pure mayhem). Here's the script I created to spawn the waves of enemies. It checks every 30 sec if there are fewer than 100 enemies on the map, if so it spawns 8 groups of 10 soldiers (80 new units).

markers used:

vc1 through vc8: Enemy spawn locations

am1 though am8: Enemy first waypoint locations

am1_1 through am8_1: Second waypoint location

am1_2 through am8_2: Third waypoint location

if (!isServer) exitWith {};
_enemynumber = 100; //This is the MINIMUM enemies that should be present on the map. Fewer alive enemies than that will spawn another wave.
while {!triggeractivated wintrigger} do 	//WINTRIGGER is the name of the trigger that handles the victory conditions
{
_opforAliveCount = {alive _x && (side _x == east)} count allUnits;
//hint format ["VC on map: %1", _opforAliveCount ]; //Debug message, showing the number of enemies on the map.

if ( _opforAliveCount < _enemynumber ) then {

	// Wait till the Functions module is ready.
	waituntil {!isnil "bis_fnc_init"};

	_startloc1 = getmarkerPos "vc1";
	_startloc2 = getmarkerPos "vc2";
	_startloc3 = getmarkerPos "vc3";
	_startloc4 = getmarkerPos "vc4";
	_startloc5 = getmarkerPos "vc5";
	_startloc6 = getmarkerPos "vc6";
	_startloc7 = getmarkerPos "vc7";
	_startloc8 = getmarkerPos "vc8";


	_targetloc1 = getmarkerPos "am1";
	_targetloc2 = getmarkerPos "am2";
	_targetloc3 = getmarkerPos "am3";
	_targetloc4 = getmarkerPos "am4";
	_targetloc5 = getmarkerPos "am5";
	_targetloc6 = getmarkerPos "am6";
	_targetloc7 = getmarkerPos "am7";
	_targetloc8 = getmarkerPos "am8";

	_targetloc1_1 = getmarkerPos "am1_1";
	_targetloc2_1 = getmarkerPos "am2_1";
	_targetloc3_1 = getmarkerPos "am3_1";
	_targetloc4_1 = getmarkerPos "am4_1";
	_targetloc5_1 = getmarkerPos "am5_1";
	_targetloc6_1 = getmarkerPos "am6_1";
	_targetloc7_1 = getmarkerPos "am7_1";
	_targetloc8_1 = getmarkerPos "am8_1";

	_targetloc1_2 = getmarkerPos "am1_2";
	_targetloc2_2 = getmarkerPos "am2_2";
	_targetloc3_2 = getmarkerPos "am3_2";
	_targetloc4_2 = getmarkerPos "am4_2";
	_targetloc5_2 = getmarkerPos "am5_2";
	_targetloc6_2 = getmarkerPos "am6_2";
	_targetloc7_2 = getmarkerPos "am7_2";
	_targetloc8_2 = getmarkerPos "am8_2";


	_mil1 = [_startloc1, EAST, ["uns_rf_vc8d","uns_rf_vc8d","uns_rf_vc3a","uns_rf_vc2a","uns_rf_vc8b","uns_rf_vc4b","uns_rf_vc6asap","uns_rf_vc8f","uns_rf_vc8f","uns_rf_vc8e"],[],[],[],[],[],270] call BIS_fnc_spawnGroup;
	_mil1 setbehaviour "AWARE";

	_mil2 = [_startloc2, EAST, ["uns_rf_vc8d","uns_rf_vc8d","uns_rf_vc3a","uns_rf_vc2a","uns_rf_vc8b","uns_rf_vc4b","uns_rf_vc6asap","uns_rf_vc8f","uns_rf_vc8f","uns_rf_vc8e"],[],[],[],[],[],270] call BIS_fnc_spawnGroup;
	_mil2 setbehaviour "AWARE";

	_mil3 = [_startloc3, EAST, ["uns_rf_vc8d","uns_rf_vc8d","uns_rf_vc3a","uns_rf_vc2a","uns_rf_vc8b","uns_rf_vc4b","uns_rf_vc6asap","uns_rf_vc8f","uns_rf_vc8f","uns_rf_vc8e"],[],[],[],[],[],270] call BIS_fnc_spawnGroup;
	_mil3 setbehaviour "AWARE";

	_mil4 = [_startloc4, EAST, ["uns_rf_vc8d","uns_rf_vc8d","uns_rf_vc3a","uns_rf_vc2a","uns_rf_vc8b","uns_rf_vc4b","uns_rf_vc6asap","uns_rf_vc8f","uns_rf_vc8f","uns_rf_vc8e"],[],[],[],[],[],270] call BIS_fnc_spawnGroup;
	_mil4 setbehaviour "AWARE";

	_mil5 = [_startloc5, EAST, ["uns_rf_vc8d","uns_rf_vc8d","uns_rf_vc3a","uns_rf_vc2a","uns_rf_vc8b","uns_rf_vc4b","uns_rf_vc6asap","uns_rf_vc8f","uns_rf_vc8f","uns_rf_vc8e"],[],[],[],[],[],270] call BIS_fnc_spawnGroup;
	_mil5 setbehaviour "AWARE";

	_mil6 = [_startloc6, EAST, ["uns_rf_vc8d","uns_rf_vc8d","uns_rf_vc3a","uns_rf_vc2a","uns_rf_vc8b","uns_rf_vc4b","uns_rf_vc6asap","uns_rf_vc8f","uns_rf_vc8f","uns_rf_vc8e"],[],[],[],[],[],270] call BIS_fnc_spawnGroup;
	_mil6 setbehaviour "AWARE";

	_mil7 = [_startloc7, EAST, ["uns_rf_vc8d","uns_rf_vc8d","uns_rf_vc3a","uns_rf_vc2a","uns_rf_vc8b","uns_rf_vc4b","uns_rf_vc6asap","uns_rf_vc8f","uns_rf_vc8f","uns_rf_vc8e"],[],[],[],[],[],270] call BIS_fnc_spawnGroup;
	_mil7 setbehaviour "AWARE";

	_mil8 = [_startloc8, EAST, ["uns_rf_vc8d","uns_rf_vc8d","uns_rf_vc3a","uns_rf_vc2a","uns_rf_vc8b","uns_rf_vc4b","uns_rf_vc6asap","uns_rf_vc8f","uns_rf_vc8f","uns_rf_vc8e"],[],[],[],[],[],270] call BIS_fnc_spawnGroup;
	_mil8 setbehaviour "AWARE";

	{_x allowfleeing 0; _x setunitpos "up";} foreach units _mil1;
	{_x allowfleeing 0; _x setunitpos "up";} foreach units _mil2;
	{_x allowfleeing 0; _x setunitpos "up";} foreach units _mil3;
	{_x allowfleeing 0; _x setunitpos "up";} foreach units _mil4;
	{_x allowfleeing 0; _x setunitpos "up";} foreach units _mil5;
	{_x allowfleeing 0; _x setunitpos "up";} foreach units _mil6;
	{_x allowfleeing 0; _x setunitpos "up";} foreach units _mil7;
	{_x allowfleeing 0; _x setunitpos "up";} foreach units _mil8;

	_mil1wp1 = _mil1 addWaypoint [_targetloc1 ,5];
	_mil1wp1 setWaypointType "MOVE";
	_mil1wp1 setWaypointFormation "STAG COLUMN";
	_mil1wp1 setWaypointStatements ["TRUE", "{_x setunitpos 'auto';} foreach thislist;"];

	_mil2wp1 = _mil2 addWaypoint [_targetloc2, 5];
	_mil2wp1 setWaypointType "MOVE";
	_mil2wp1 setWaypointFormation "STAG COLUMN";
	_mil2wp1 setWaypointStatements ["TRUE", "{_x setunitpos 'auto';} foreach thislist;"];

	_mil3wp1 = _mil3 addWaypoint [_targetloc3, 5];
	_mil3wp1 setWaypointType "MOVE";
	_mil3wp1 setWaypointFormation "STAG COLUMN";
	_mil3wp1 setWaypointStatements ["TRUE", "{_x setunitpos 'auto';} foreach thislist;"];

	_mil4wp1 = _mil4 addWaypoint [_targetloc4, 5];
	_mil4wp1 setWaypointType "MOVE";
	_mil4wp1 setWaypointFormation "STAG COLUMN";
	_mil4wp1 setWaypointStatements ["TRUE", "{_x setunitpos 'auto';} foreach thislist;"];

	_mil5wp1 = _mil5 addWaypoint [_targetloc5, 5];
	_mil5wp1 setWaypointType "MOVE";
	_mil5wp1 setWaypointFormation "STAG COLUMN";
	_mil5wp1 setWaypointStatements ["TRUE", "{_x setunitpos 'auto';} foreach thislist;"];

	_mil6wp1 = _mil6 addWaypoint [_targetloc6, 5];
	_mil6wp1 setWaypointType "MOVE";
	_mil6wp1 setWaypointFormation "STAG COLUMN";
	_mil6wp1 setWaypointStatements ["TRUE", "{_x setunitpos 'auto';} foreach thislist;"];

	_mil7wp1 = _mil7 addWaypoint [_targetloc7, 5];
	_mil7wp1 setWaypointType "MOVE";
	_mil7wp1 setWaypointFormation "STAG COLUMN";
	_mil7wp1 setWaypointStatements ["TRUE", "{_x setunitpos 'auto';} foreach thislist;"];

	_mil8wp1 = _mil8 addWaypoint [_targetloc8, 5];
	_mil8wp1 setWaypointType "MOVE";
	_mil8wp1 setWaypointFormation "STAG COLUMN";
	_mil8wp1 setWaypointStatements ["TRUE", "{_x setunitpos 'auto';} foreach thislist;"];

	_mil1wp2 = _mil1 addWaypoint [_targetloc1_1, 5];
	_mil2wp2 = _mil2 addWaypoint [_targetloc2_1, 5];
	_mil3wp2 = _mil3 addWaypoint [_targetloc3_1, 5];
	_mil4wp2 = _mil4 addWaypoint [_targetloc4_1, 5];
	_mil5wp2 = _mil5 addWaypoint [_targetloc5_1, 5];
	_mil6wp2 = _mil6 addWaypoint [_targetloc6_1, 5];
	_mil7wp2 = _mil7 addWaypoint [_targetloc7_1, 5];
	_mil8wp2 = _mil8 addWaypoint [_targetloc8_1, 5];

	_mil1wp2 setWaypointType "MOVE";
	_mil2wp2 setWaypointType "MOVE";
	_mil3wp2 setWaypointType "MOVE";
	_mil4wp2 setWaypointType "MOVE";
	_mil5wp2 setWaypointType "MOVE";
	_mil6wp2 setWaypointType "MOVE";
	_mil7wp2 setWaypointType "MOVE";
	_mil8wp2 setWaypointType "MOVE";		

	_mil1wp3 = _mil1 addWaypoint [_targetloc1_2, 5];
	_mil2wp3 = _mil2 addWaypoint [_targetloc2_2, 5];
	_mil3wp3 = _mil3 addWaypoint [_targetloc3_2, 5];
	_mil4wp3 = _mil4 addWaypoint [_targetloc4_2, 5];
	_mil5wp3 = _mil5 addWaypoint [_targetloc5_2, 5];
	_mil6wp3 = _mil6 addWaypoint [_targetloc6_2, 5];
	_mil7wp3 = _mil7 addWaypoint [_targetloc7_2, 5];
	_mil8wp3 = _mil8 addWaypoint [_targetloc8_2, 5];

	_mil1wp3 setWaypointType "MOVE";
	_mil2wp3 setWaypointType "MOVE";
	_mil3wp3 setWaypointType "MOVE";
	_mil4wp3 setWaypointType "MOVE";
	_mil5wp3 setWaypointType "MOVE";
	_mil6wp3 setWaypointType "MOVE";
	_mil7wp3 setWaypointType "MOVE";
	_mil8wp3 setWaypointType "MOVE";

	_mil1wp3 setWaypointFormation "DIAMOND";
	_mil2wp3 setWaypointFormation "DIAMOND";
	_mil3wp3 setWaypointFormation "DIAMOND";
	_mil4wp3 setWaypointFormation "DIAMOND";
	_mil5wp3 setWaypointFormation "DIAMOND";
	_mil6wp3 setWaypointFormation "DIAMOND";
	_mil7wp3 setWaypointFormation "DIAMOND";
	_mil8wp3 setWaypointFormation "DIAMOND";		

	_mil1wp4 = _mil1 addWaypoint [_targetloc1_1, 5];
	_mil2wp4 = _mil2 addWaypoint [_targetloc2_1, 5];
	_mil3wp4 = _mil3 addWaypoint [_targetloc3_1, 5];
	_mil4wp4 = _mil4 addWaypoint [_targetloc4_1, 5];
	_mil5wp4 = _mil5 addWaypoint [_targetloc5_1, 5];
	_mil6wp4 = _mil6 addWaypoint [_targetloc6_1, 5];
	_mil7wp4 = _mil7 addWaypoint [_targetloc7_1, 5];
	_mil8wp4 = _mil8 addWaypoint [_targetloc8_1, 5];

	_mil1wp4 setWaypointType "CYCLE";
	_mil2wp4 setWaypointType "CYCLE";
	_mil3wp4 setWaypointType "CYCLE";
	_mil4wp4 setWaypointType "CYCLE";
	_mil5wp4 setWaypointType "CYCLE";
	_mil6wp4 setWaypointType "CYCLE";
	_mil7wp4 setWaypointType "CYCLE";
	_mil8wp4 setWaypointType "CYCLE";

	spawnedvc = spawnedvc + 80;  //Counting total number of spawned enemies, each wave is 8 groups of 10 enemies.
	publicvariable "spawnedvc";

	{if (_x isKindOf "Man") then {deleteVehicle _x}} forEach allDead;  //Delete all bodies (optional, improves performance in massive battles)

};

sleep 30;

}

Share this post


Link to post
Share on other sites
Amphib, is it Dedicated friendly?

Well, you need to add an && !isdedicated to the if - exitwith statement in the first line.

This exact version of the script has not been run live on a dedicated server (only in simple MP). But I have a more advanced (mission specific) version of it that has and works fine, so there's no reason why this fairly slimmed one should cause any problems on dedicated.

Share this post


Link to post
Share on other sites

Unfortunately I am busy for the next day or two so I will try both scripts and let you know how they get on at some point Friday or Saturday.

Thanks folks!

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
Sign in to follow this  

×