Jump to content
Sign in to follow this  
igneous01

RUIS - Random Unit Invasion Script

Recommended Posts

Here is something i recently finished.

This script randomly spawns enemy units in a random position (or positions) you define. These newly created groups will then move to a waypoint location that you specify as well.

The types of forces this script spawns are random with a percentage chance of being spawned. For example, Infantry might always spawn (100% chance) but the number of groups that are spawned may differ (random of max 10 groups - you can define this as well inside the script)

so you can specify and customize whatever types of units you want it to spawn, it supports custom factions as well, all you have to do is add that faction classname into the script (template already inside), and fill the arrays with the classnames of the groups there (individual units will not work)

You can adjust the amount of waves the script will produce (1 wave = 1 iteration of the script spawning stuff)

You can also adjust the timer before a new wave begins (old units that are alive will still stay on the field, but dead units and empty groups will be deleted to preserve cpu and space) - thanks demonized for the empty group feature

This script is Multiplayer compatible, works with both dedicated and listen servers (however the host will probably be lagging quite a bit with this script)

How to Use:

nul = [RUguy, [spawn1, spawn2, spawn3], attackwp, spawntimer, Scripttime] execVM "RUIS.sqf"

where:

RUguy - The name of a unit on the field, the script will take this units faction and side and spawn units of this type, works with BIS_US, USMC, RU, TAKI_INS, and Taki Army

[spawn1, ..... ] - the spawn locations on the map (best to use gamelogics with names here)

attackwp - an object or gamelogic where the units spawned will move to

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

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

link:

mission example (UPDATED**):http://www.mediafire.com/?0wye5wxtgt69z47

Script:

// RUIS script (Random Unit Invasion Script) v1.2

// changed attak waypoint to function as array - allows for spawned group to randomly select a position to move to

// example: nul = [RUguy, [spawn1, spawn2, spawn3], attackwp, spawntimer, Scripttime] execVM "RUIS.sqf"

// unit - this unit will be checked for what side and faction to spawn

// [spawn1, ...] - gamelogics for units to spawn on

// attackwp - an array of positions spawned units will move to (chosen randomly per group)

// spawntimer - amount of time to wait until the spawning of a new unit

// scripttime - the amount of waves this script will run (1 wave = 1 iteration of script spawning stuff)

if (isServer || isDedicated) then {

private ["_spawntime", "_logicS", "_logicE", "_temptime", "_scripttime", "_unit", "_perc", "_faction", "_side", "_MaxInf", "_MaxV", "_MaxLA", "_MaxArm", "_MaxAir", "_PInf", "_PV", "_PLA", "_PArm", "_PAir", "_EmptyGroups"];

_unit = _this select 0;

_logicS = _this select 1;

_logicE = _this select 2;

_spawntime = _this select 3;

_scripttime = _this select 4; // this sets the amount of waves the script will do

_faction = faction _unit;

_side = side _unit;

_EmptyGroups = 0;

// EDIT THESE VARIABLES TO CUSTOMIZE RUIS

_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 = 75; // Percentage chance of Light vehicles being spawned

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

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

// DO NOT EDIT PAST THIS

// check what side was chosen, and assimilate proper values

// blacklisted: "RU_SniperTeam", "USMC_SniperTeam", "USMC_FRTeam", "USMC_FRTeam_Razor"

// A2 Russian faction

if (_faction == "RU") then {

_unit setVariable ["infantry", ["RU_InfSquad", "RU_InfSection_MG", "RU_InfSection_AT", "RU_InfSection_AA", "RU_InfSection"], true];

_unit setVariable ["vehicle", ["RU_MotInfSection_Recon", "RU_MotInfSection_Patrol"], true];

_unit setVariable ["lightarmor", ["RU_MechInfSquad_1", "RU_MechInfSquad_2"], true];

_unit setVariable ["armor", ["RU_TankPlatoon"], true];

_unit setVariable ["air", ["RU_Mi24VSquadron", "RU_Mi24PSquadron"], true];

};

// A2 USMC faction

if (_faction == "USMC") then {

_unit setVariable ["infantry", ["USMC_InfSquad", "USMC_FireTeam", "USMC_FireTeam_MG", "USMC_FireTeam_AT", "USMC_FireTeam_Support", "USMC_HeavyATTeam"], true];

_unit setVariable ["vehicle", ["USMC_MotInfSection", "USMC_MotInfSection_AT"], true];

_unit setVariable ["lightarmor", ["USMC_MechInfSquad", "USMC_MechReconSection"], true];

_unit setVariable ["armor", ["USMC_TankPlatoon"], true];

_unit setVariable ["air", ["USMC_AH1ZSquadron", "USMC_UH1YSquadron", "USMC_MV22Squadron", "USMC_F35Squadron", "USMC_AV8BFighterSquadron", "USMC_AV8BBomberSquadron"], true];

};

// OA US Army faction

if (_faction == "BIS_US") then {

_unit setVariable ["infantry", ["US_RifleSquad", "US_WeaponsSquad", "US_Team", "US_TeamMG", "US_TeamAT", "US_TeamSupport", "US_HeavyATTeam", "US_SniperTeam", "US_DeltaForceTeam"], true];

_unit setVariable ["vehicle", ["US_MotorizedSection", "US_MotorizedSectionAT", "US_DeltaPatrolATV", "US_DeltaPatrolHMMWV"], true];

_unit setVariable ["lightarmor", ["US_MechanizedInfantrySquadICVM2", "US_MechanizedInfantrySquadICVMK19", "US_MechanizedReconSection"], true];

_unit setVariable ["armor", ["US_MGSPlatoon", "US_M1A2Platoon", "US_M1A1Platoon", "US_M1A2Section"], true];

_unit setVariable ["air", ["US_A10Flight", "US_AH64DFlight", "US_AH6JFlight", "US_AH6XFlight", "US_MH6JFlight", "US_UH60MFlight"], true];

};

// OA Takistani Army faction

if (_faction == "BIS_TK") then {

_unit setVariable ["infantry", ["TK_InfantrySquad", "TK_InfantrySection", "TK_InfantrySectionAT", "TK_InfantrySectionAA", "TK_InfantrySectionMG", "TK_SniperTeam", "TK_SpecialPurposeSquad"], true];

_unit setVariable ["vehicle", ["TK_MotorizedInfanterySquad", "TK_MotorizedReconSection", "TK_MotorizedPatrol"], true];

_unit setVariable ["lightarmor", ["TK_MechanizedInfantrySquadBMP2", "TK_MechanizedInfantrySquadBTR60", "TK_MechanizedSpecialSquad", "TK_MechanizedReconSection", "TK_MechanizedReconSectionAT"], true];

_unit setVariable ["armor", ["TK_T72Platoon", "TK_T55Platoon", "TK_T34Platoon"], true];

_unit setVariable ["air", ["TK_Mi24_DFlight", "TK_Mi_17Flight", "TK_Su25Flight", "TK_UH1HFlight"], true];

};

// OA Takistani Insurgents faction

if (_faction == "BIS_TK_INS") then {

_unit setVariable ["infantry", ["TK_INS_Group", "TK_INS_Patrol", "TK_INS_AATeam", "TK_INS_ATTeam"], true];

_unit setVariable ["vehicle", ["TK_INS_Technicals", "TK_INS_MotorizedGroup"], true];

_unit setVariable ["lightarmor", [], true];

_unit setVariable ["armor", ["TK_INS_MotorizedPatrolBTR40"], true];

_unit setVariable ["air", [], true];

};

// TO INCLUDE A FACTION,

// Custom Insert faction

if (_faction == "YourFactionHere") then {

_unit setVariable ["infantry", ["Your Infantry Classname Here"], true];

_unit setVariable ["lightarmor", ["Your Vehicle Classname here"], true];

_unit setVariable ["armor", ["Your armor classname here"], true];

_unit setVariable ["air", ["Your air classname here"], true];

};

// Functions for spawn

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);

};

};

};

if (isnil "DZ_Spawn_V") then {

DZ_Spawn_V = {

private ["_unit", "_loc", "_wp", "_spawned", "_logicS", "_logicE", "_unitarray", "_side", "_faction", "_MaxV", "_locA"];

_unit = _this select 0;

_logicS = _this select 1;

_logicE = _this select 2;

_side = _this select 3;

_faction = _this select 4;

_MaxV = _this select 5;

// spawn vehicle random times

for "_i" from 1 to (ceil(random _MaxV)) do

{

_unitarray = (_unit getVariable "vehicle") select floor(random(count (_unit getVariable "vehicle")));

_loc = _logicS select floor(random(count _logicS));

// spawn random units

_spawned = [getPos _loc, _side, (configFile >> "CfgGroups" >> (str _side) >> _faction >> "Motorized" >> _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);

};

};

};

if (isnil "DZ_Spawn_LA") then {

DZ_Spawn_LA = {

private ["_unit", "_loc", "_wp", "_spawned", "_logicS", "_logicE", "_unitarray", "_side", "_faction", "_MaxLA", "_locA"];

_unit = _this select 0;

_logicS = _this select 1;

_logicE = _this select 2;

_side = _this select 3;

_faction = _this select 4;

_MaxLA = _this select 5;

// spawn light armor random times

for "_i" from 1 to (ceil(random _MaxLA)) do

{

_unitarray = (_unit getVariable "lightarmor") select floor(random(count (_unit getVariable "lightarmor")));

_loc = _logicS select floor(random(count _logicS));

// spawn random units

_spawned = [getPos _loc, _side, (configFile >> "CfgGroups" >> (str _side) >> _faction >> "Mechanized" >> _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);

};

};

};

if (isnil "DZ_Spawn_ARM") then {

DZ_Spawn_ARM = {

private ["_unit", "_loc", "_wp", "_spawned", "_logicS", "_logicE", "_unitarray", "_side", "_faction", "_MaxArm", "_locA"];

_unit = _this select 0;

_logicS = _this select 1;

_logicE = _this select 2;

_side = _this select 3;

_faction = _this select 4;

_MaxArm = _this select 5;

// spawn vehicle a random of 3 times

for "_i" from 1 to (ceil(random _MaxArm)) do

{

_unitarray = (_unit getVariable "armor") select floor(random(count (_unit getVariable "armor")));

_loc = _logicS select floor(random(count _logicS));

// spawn random units

_spawned = [getPos _loc, _side, (configFile >> "CfgGroups" >> (str _side) >> _faction >> "Armored" >> _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);

};

};

};

if (isnil "DZ_Spawn_AIR") then {

DZ_Spawn_AIR = {

private ["_unit", "_loc", "_wp", "_spawned", "_logicS", "_logicE", "_unitarray", "_side", "_faction", "_MaxAir", "_locA"];

_unit = _this select 0;

_logicS = _this select 1;

_logicE = _this select 2;

_side = _this select 3;

_faction = _this select 4;

_MaxAir = _this select 5;

// spawn vehicle a random of 3 times

for "_i" from 1 to (ceil(random _MaxAir)) do

{

_unitarray = (_unit getVariable "air") select floor(random(count (_unit getVariable "air")));

_loc = _logicS select floor(random(count _logicS));

// spawn random units

_spawned = [getPos _loc, _side, (configFile >> "CfgGroups" >> (str _side) >> _faction >> "Air" >> _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);

};

};

};

//player sidechat "getting into loop";

while {_scripttime > 0} do {

_perc = round(random 100);

_scripttime = _scripttime - 1;

_temptime = _spawntime;

//player sidechat format ["percentage: %1", _perc];

if (_perc <= _PInf) then {

_infspawn = [_unit, _logicS, _logicE, _side, _faction, _MaxInf] spawn DZ_Spawn_INF;

};

_perc = round(random 100);

if (_perc <= _PV) then {

_vehspawn = [_unit, _logicS, _logicE, _side, _faction, _MaxV] spawn DZ_SPAWN_V;

};

// check if an index in the array exists

if (count (_unit getVariable "lightarmor") > 0) then {

_perc = round(random 100);

//player sidechat format ["percentage: %1", _perc];

if (_perc <= _PLA) then {

_laspawn = [_unit, _logicS, _logicE, _side, _faction, _MaxLA] spawn DZ_Spawn_LA;

};

};

_perc = round(random 100);

//player sidechat format ["percentage: %1", _perc];

if (_perc <= _PArm) then {

_armspawn = [_unit, _logicS, _logicE, _side, _faction, _MaxArm] spawn DZ_Spawn_ARM;

};

sleep 1;

// check if an index in the array exists

if (count (_unit getVariable "air") > 0) then {

_perc = round(random 100);

//player sidechat format ["percentage: %1", _perc];

if (_perc <= _PAir) then {

_airspawn = [_unit, _logicS, _logicE, _side, _faction, _MaxAir] spawn DZ_Spawn_AIR;

};

};

waitUntil {sleep 1; _temptime = _temptime - 1; _temptime < 1};

{if (({alive _x} count units _x) == 0) then {deleteGroup _x}} foreach allGroups;

{deleteVehicle _x} forEach allDead;

};

};

maybe some people will make use of this - I know ive needed this a few times

Edited by Igneous01

Share this post


Link to post
Share on other sites

forgot to credit you with the delete group problem i was having.

there::

now you are officially credited \o/

Share this post


Link to post
Share on other sites

Hm - Am I doing something wrong...? - no enemies in sight, just the VERY annoying 'pings' from the hints... - were're all the enemise...? - nothing happens... :|

Share this post


Link to post
Share on other sites
Hm - Am I doing something wrong...? - no enemies in sight, just the VERY annoying 'pings' from the hints... - were're all the enemise...? - nothing happens... :|

Really debug messages should be in text instead of hints. Any anything that repeatedly hints *must* use hintSilent. Either make that optional or remove it entirely.

I'm not seeing the script checking for and creating if necessary a center, so it's possible it won't work unless preexisting units of the side are already on the map. So either place people on the map first, or have the script check for a center to have been created first.

Share this post


Link to post
Share on other sites

yes - my mistake not removing those annoying hints. This was made as more of a modifiable script then a finished product.

Currently a preexisting unit must be place in the editor and used for the script. I may change this when I have time to edit the script again

Share this post


Link to post
Share on other sites

How can I remove the text that pops up at the top right?

Thanks in advance

-Bigshot

Share this post


Link to post
Share on other sites

Int last part of the script change this:

waitUntil {sleep 1; _temptime = _temptime - 1; hint format ["timeleft: %1", _temptime]; _temptime < 1};

to this:

waitUntil {sleep 1; _temptime = _temptime - 1; _temptime < 1};

Share this post


Link to post
Share on other sites

Will that also make the AI spawn immediately? Or will it wait the 300 seconds?

Oh and I think I got the sidechat text gone but I'm not sure

Share this post


Link to post
Share on other sites

You could also just change the hint to hintSilent too. :)

Share this post


Link to post
Share on other sites

Well I rather not see it, maybe useful if you want a reinforcments timer to show player, but I'm some situations it seems unnecessary. :)

-Bigshot

Share this post


Link to post
Share on other sites

For some reason some groups refuse to spawn. I've tested the same scenario aprox 100.000 times in all kind of variants - but no matter what these groups simply refuse to spawn:

"RU_MechInfSquad_1", "RU_MechInfSquad_2","RU_MotInfSquad"

I get all kind of aircrafts, T90's, Vodnik's and infantry... - but NO bmp-3, btr-90 or trucks... AT ALL - is this some kind of buggy or...?

Cheers

Woody :)

Share this post


Link to post
Share on other sites

All three of those worked for me, make sure you have ArmA2 loaded and a Russian Unit or Center already on map as well as the Functions Module then:

[getMarkerPos "tankSpawn", EAST, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Mechinized" >> "RU_MechInfSquad_1")] call BIS_fnc_spawnGroup;

[getMarkerPos "tankSpawn", EAST, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Mechanized" >> "RU_MechInfSquad_2")] call BIS_fnc_spawnGroup;

[getMarkerPos "tankSpawn", EAST, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Motorized" >> "RU_MotInfSquad")] call BIS_fnc_spawnGroup;

Oops, just realized this was in releation to this script, not in general. The problem is this script doesn't have "Mechanized" as an option for it's "light armor" option.

Edited by kylania

Share this post


Link to post
Share on other sites

No luck yet... :| - could you post a sample mission...? :)

------------

Edit: I've actually tried several factions: US, Takistan Army, Takistan Milita, Russia... - and it's all the same... neither Bradly's, bmp-2's, bmp-3's, btr-90's or btr-60's show up...

I've used this sample mission:http://www.mediafire.com/?dg3eaud4dy7svba

------------

Edit2:

Got it working now... 'Mechinized' was misspelled... the right term is: 'Mechanized'

Edited by Major Woody

Share this post


Link to post
Share on other sites

So if we can't plug in individual units for addon factions, how do we find out what their classnames are for groups? Is there a command I can run that will give me that value? I've looked through the I44 PBO's and their class list without any luck.

Share this post


Link to post
Share on other sites

Oops, sorry Woody. Fixed my post, thanks!

Hammer, you can find the names for groups here:

http://community.bistudio.com/wiki/Ambient_Combat_Manager_-_Group_types

I44's classnames can be found here in the I44-classlist-v2.51.txt however note the mod uses different SIDES, FACTIONS and TYPES... example:

(configFile >> "CfgGroups" >> "I44_A" >> "I44_A_ARMY" >> "I44_A_Army_Men" >> "I44_A_Assault")

Edited by kylania

Share this post


Link to post
Share on other sites

Ah thanks, probably should have asked in the i44 thread, didn't notice they added a 2.51 readme.

I don't quite understand how I'm supposed to run that line when I don't know what values I'm supposed to put in there.. but it doesn't really matter because i44 only has groups for infantry.

Share this post


Link to post
Share on other sites

You'd use it in place of the (configfile blah blah) stuff in my post above as part of the input for BIS_fnc_spawnGroup.

Share this post


Link to post
Share on other sites

argh, i just looked at it again and your right -- there is no mechanized included in the script (doooh)

I will fix that and post a improved version of this script - but still feel free to modify it to your hearts content

---------- Post added at 07:01 PM ---------- Previous post was at 05:48 PM ----------

*updated the script to fix the motorized/mechanized issue, they are now their own seperate types in the script.

Share this post


Link to post
Share on other sites

I like using this script now... - it really fullfills all my needs... - but it's a bit sad the script is narrowed down to use only the predefined groups... - would it be possible to define my own custom groups...?

Share this post


Link to post
Share on other sites

It could be, spawnGroup can take custom lists of units to spawn. Looking at it though you'd have to change a lot of the logic due to how the script hard codes things for you. It's really more of a random group spawning as opposed to a custom group spawning system.

Share this post


Link to post
Share on other sites

@MajorWoody - thats a great idea, i think ill work on a custom extension for it to allow you to put in custom groups. Taking in an array of unitnames and defining them into a custom group setvariable shouldnt be too hard - ill see what i can do

Share this post


Link to post
Share on other sites

Thanks for your effort but half worked for me, placed function module, followed instructions.

I got errors in the lines 112,140, and 168.

units spawned but didn't move to the attack point.

Does somone had the same problem ?

Share this post


Link to post
Share on other sites
Thanks for your effort but half worked for me, placed function module, followed instructions.

I got errors in the lines 112,140, and 168.

units spawned but didn't move to the attack point.

Does somone had the same problem ?

could you post what the error messages were? I am still using this in a lot of my test missions and it hasn't failed yet. So perhaps something is missing (or perhaps, the soldier unit used to identify the faction was killed, which stops the spawning (have not changed this yet))

Share this post


Link to post
Share on other sites

I used -showscripterrors command. I retreive the errors in .rpt here there are

Error in expression <;

_locA = _logicE select floor (random(count _logicE));

_wp = _spawned addWaypo>

Error position: <count _logicE));

_wp = _spawned addWaypo>

Error count: Type Object, expected Array,Config entry

File C:\Users\ ...\Documents\ArmA 2\missions\RUIS _ RandomUnitInvasionScript.utes\RUIS.sqf, line 112

Error in expression <

_locA = _logicE select floor (random(count _logicE));

_wp = _spawned addWaypo>

Error position: <count _logicE));

_wp = _spawned addWaypo>

Error count: Type Object, expected Array,Config entry

File C:\Users\ ... \Documents\ArmA 2\missions\RUIS _ RandomUnitInvasionScript.utes\RUIS.sqf, line 140

Error in expression <

_locA = _logicE select floor (random(count _logicE));

_wp = _spawned addWaypo>

Error position: <count _logicE));

_wp = _spawned addWaypo>

Error count: Type Object, expected Array,Config entry

File C:\Users\ ... \Documents\ArmA 2\missions\RUIS _ RandomUnitInvasionScript.utes\RUIS.sqf, line 168

I've set up 1 spawn. They spawned well but they didn't move to waypoint.

In your exemple taken from here http://www.armaholic.com/page.php?id=14854&highlight=RUIS nothing happens. I got the same errors.

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  

×