Jump to content
Sign in to follow this  
Morten87

Spawn enemy group, hunting for player

Recommended Posts

Hello :)

Need some help with this :)

When "heli1" is killed, I want the enemy to spawn from 3 diffrent positions. Their objective is to locate and kill the "player".

The player should be held up in a town. There are 3 roads leading in to the town. I want the enemy to spawn by these roads continuasly but never more than around 20-30 Enemy AI at the same time.

How can I do this?

Share this post


Link to post
Share on other sites

I would take a look at Igneous01's Random Unit Invasion Script. You can set it up so that when your conditions are met, the AI will begin to spawn at marker positions you specify. You can designate number of AI, time between waves, etc. Read the instructions!

Share this post


Link to post
Share on other sites

Looks like a good script, but can you help me through it? I mean, what part should go were, is it in init.sqf or somewere else?

Share this post


Link to post
Share on other sites
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

Put RUIS.sqf in your mission folder.

Place one unit from the desired enemy faction somewhere on the map. You can name all of the objects we're placing whatever you'd like, but we'll use the names from the example above. Name this unit RUguy.

I also prefer to make the unit inactive by adding this to the unit's init field as well:

this enableSimulation false; this hideObject true;

Place a gamelogic at each spawn position, and name them. We'll place three, named spawn1, spawn2, and spawn3.

Place another gamelogic at the center of the town where your player will be and name it attackwp.

Place a trigger and group it to the helicopter, heli1.

In the trigger's Cond field, we'll put !alive heli1.

In the trigger's OnAct field we'll call the script:

nul = [RUguy, [spawn1, spawn2, spawn3], attackwp, 300, 5] execVM "RUIS.sqf";

Now, when heli1 is destroyed, RUIS.sqf will run, randomly spawning AI at one of the three gamelogics spawn1, spawn2, and spawn3. They will move to attackwp and engage any enemy the find there. Every five minutes (300 seconds), another wave will spawn. A total of five waves will spawn.

If you open RUIS.sqf, you can edit some settings so that only the desired unit types and group sizes will spawn. The script is well-commented, so it should be pretty straightforward.

Edited by Harzach

Share this post


Link to post
Share on other sites

Well.. I cant get it to work. what I did was as above -

----------- Put RUIS.sqf in your mission folder.

Place one unit from the desired enemy faction somewhere on the map. You can name all of the objects we're placing whatever you'd like, but we'll use the names from the example above. Name this unit RUguy.

I also prefer to make the unit inactive by adding this to the unit's init field as well:

Code:

this enableSimulation false; this hideObject true;

Place a gamelogic at each spawn position, and name them. We'll place three, named spawn1, spawn2, and spawn3.

Place another gamelogic at the center of the town where your player will be and name it attackwp.

Place a trigger and group it to the helicopter, heli1.

In the trigger's Cond field, we'll put !alive heli1.

In the trigger's OnAct field we'll call the script:

Code:

nul = [RUguy, [spawn1, spawn2, spawn3], attackwp, 300, 5] execVM "RUIS.sqf";

Now, when heli1 is destroyed, RUIS.sqf will run, randomly spawning AI at one of the three gamelogics spawn1, spawn2, and spawn3. They will move to attackwp and engage any enemy the find there. Every five minutes (300 seconds), another wave will spawn. A total of five waves will spawn.

If you open RUIS.sqf, you can edit some settings so that only the desired unit types and group sizes will spawn. The script is well-commented, so it should be pretty straightforward. -------------------------------

And then in the RUIS.sqf i copyed and paste from the script.

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

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

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

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

_MaxArm = 0; // Max amount of armor

_MaxAir = 1; // Max amount of air

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

_PV = 25; // Percentage chance of vehicles spawning

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

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

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

// 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];

};

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;

};

};

What am I doing wrong?

Share this post


Link to post
Share on other sites

Not sure if this helps but make sure there's at least 1 enemy on the map (make the probability of him spawning 0) this will create a center for the enemy AI. Without the center the enemy won't spawn.

Alternatively you can just create a center using the createcenter command. ie: enemycenter = createcenter EAST; (place that in the init of the player or any object on the map.

Share this post


Link to post
Share on other sites

And then in the RUIS.sqf i copyed and paste from the script.

What do you mean? Just put the RUIS.sqf into your mission folder.

Not sure if this helps but make sure there's at least 1 enemy on the map (make the probability of him spawning 0) this will create a center for the enemy AI. Without the center the enemy won't spawn.

Alternatively you can just create a center using the createcenter command. ie: enemycenter = createcenter EAST; (place that in the init of the player or any object on the map.

That was my "step 2", so I'm hoping it's not the problem.

Share this post


Link to post
Share on other sites
What do you mean? Just put the RUIS.sqf into your mission folder.

The hole thing? ot just some parts of it?

Share this post


Link to post
Share on other sites
What do you mean? Just put the RUIS.sqf into your mission folder.

The hole thing? ot just some parts of it?

He means the RUIS.sqf file itself must be in the root of your mission folder (usually in your My Documents\Arma2 Other Profiles\MPMissions folder - or just Missions folder if you are working in the singleplayer editor). There should already be a mission.sqm file in that folder if you've saved it from the editor.

Note this is not the same location for finished mission files (pbo) which is the MPMissions folder in your Arma 2 install directory

Also make sure you are running Arma with the -showscripterrors parameter that will help with troubleshooting.

Share this post


Link to post
Share on other sites

I have created a folder "RUIS.sqf" in the root directory - And in it I have placed the long "script" above.

I have edited these parts:

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

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

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

_MaxArm = 0; // Max amount of armor

_MaxAir = 1; // Max amount of air

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

_PV = 25; // Percentage chance of vehicles spawning

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

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

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

// 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];

};

Share this post


Link to post
Share on other sites
What do you mean? Just put the RUIS.sqf into your mission folder.

The hole thing? ot just some parts of it?

When you download RUIS, you get a .rar file. Inside is a folder named "RUIS1%2e2.utes". Inside that folder is an example mission file (mission.sqm) and the RUIS.sqf, which is the script we are using. Just physically drag that .sqf over into your mission folder.

That said, I need to correct a couple of things.

1. Do NOT use the code I gave you to make "RUguy" inactive. I was thinking of a different script system when I wrote that. Also, making the unit's probability of presence 0% won't work either. Just place the unit in one of the extreme corners of the map and you'll be fine.

2. There is an error in the RUIS.sqf comments, at the top, where is explains the script call. Basically, the attack waypoint(s) need to be in an array, which it does not specify. So the script call should look like this:

nul = [RUguy, [spawn1,spawn2,spawn3], [attackwp1], 300, 5] execVM "RUIS.sqf";

Sorry for the confusion, both errors were my fault for not taking the time to ensure correctness. Let us know if it works out. Also, happy to help tweak the script to get the kind of enemy groups you are looking for.

---------- Post added at 15:52 ---------- Previous post was at 15:37 ----------

I have created a folder "RUIS.sqf" in the root directory

Assuming you have saved your mission, find the actual mission folder. Typical path would be C:\Users\{your name}\My Documents\Arma 2\{profile name}\missions\.

Inside the missions folder will be more folders. These are the actual missions you have saved. At the very least, each one will have a mission.sqm inside of it. Find the right folder and place the RUIS.sqf file into it.

Here is a totally basic example mission using RUIS. Unzip it and place it in C:\Users\{your name}\My Documents\Arma 2\{profile name}\missions\ (or wherever your missions are). Radio Alpha will start the attack. enemies will spawn at either end of the runway. You won't live long!

*edit* - GAH! I forgot to mention that you need to either place a functions module or use CBA. This information is buried in the RUIS topic. Functions module added to the example mission.

Edited by Harzach

Share this post


Link to post
Share on other sites

Cool.. it works :) Thank you very much.. I keep getting more and more overwhelmed, over how good this community is. :)

Share this post


Link to post
Share on other sites

Glad to help, but all credit goes to Igneous01 for his script.

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  

×