Jump to content
Sign in to follow this  
hellstorm77

Spawning enemy units

Recommended Posts

hi guys i'm having a little trouble with a mission im trying to make.

what i'm trying to do: I have 3 objectives Agia Marina and Firing Range, Camp Rogain and Kamino Firing Range. Agia Marina is the first obj where i want to place a trigger ie 1000m when blufor enter it enemies will spawn if blufor leaves the area enemies will de-spawn so they is no enemies.

Share this post


Link to post
Share on other sites

One of these might help you:

Similar Threads

Spawning enemy by distance

By clydefrog in forum ARMA 2 & OA : MISSIONS - Editing & Scripting

Replies: 18

Last Post: 08-13-2012, 04:57 PM

Spawning enemy

By Frosties in forum ARMA 2 & OA : MISSIONS - Editing & Scripting

Replies: 6

Last Post: 04-12-2012, 11:13 AM

Help spawning enemy group

By Swoop in forum ARMA - MISSION EDITING & SCRIPTING

Replies: 8

Last Post: 07-28-2007, 03:24 AM

Spawning enemy AI

By LtCmdrBoon in forum ARMA - MISSION EDITING & SCRIPTING

Replies: 0

Last Post: 06-17-2007, 07:37 PM

Enemy spawning script

By Winters in forum OFP : MISSION EDITING & SCRIPTING

Replies: 7

Last Post: 12-03-2003, 02:39 PM

Share this post


Link to post
Share on other sites

I have tried this but it dosnt seem to spawn any enemies

A trigger that runs a script that spawns units.

Trigger act: blufor present

on activation

0 = ["spawnmarker"] execVM "spawnUnits.sqf";

spawnUnits.sqf:

if (!isServer) exitWith {};

_spawnPos = markerPos (_this select 0);

_group1 = createGroup EAST;

_unit1 = _group1 createUnit ["O_Soldier_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;

[_group1,_spawnPos,200] call bis_fnc_taskPatrol;

Share this post


Link to post
Share on other sites

Trigger act: blufor present

on activation

(getMarkerPos "spawnmarker") execVM "spawnUnits.sqf"

if (!isServer) exitWith {};
_spawnPos = _this;
_side = createCenter east;
_group1= createGroup east;
_group1= [_spawnPos , east, (configFile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad")] call BIS_fnc_spawnGroup;
[_group1,_spawnPos,200] call bis_fnc_taskPatrol;

Share this post


Link to post
Share on other sites

i got it working i placed a marker called spawnmarker is there a way when blufor leaves the trigger opfor de-spawns

Share this post


Link to post
Share on other sites
{deletevehicle _x} forEach (units _group1);
deleteGroup _group1;

where would i add this to?

Share this post


Link to post
Share on other sites

Basically, you're going to have to watch for the exit. So from the position of the marker, find all BLUFOR within a radius and if there is none found, then then delete group 1. You would need a piece of code like:

_BLUFOR_Count = 1;
while { _BLUFOR_Count > 0 } do
{
_BLUFOR_Count = {_x isKindof "Man" and (side _x) == west} count (nearestObjects [(getMarkerPos "spawnmarker"), [], 200]);
sleep 5;
};

{deletevehicle _x} forEach (units _group1);
deleteGroup _group1;

This could be placed immediately after spawning the enemy group code you already have.

Share this post


Link to post
Share on other sites

that works great the only problem with it is if i re-enter the trigger after they de-spawns they dont re-spawn

---------- Post added at 20:46 ---------- Previous post was at 20:21 ----------

they seem to also de-spawn when i'm still in side the trigger also

Share this post


Link to post
Share on other sites

The radius is set at 200, you might need to adjust it.

Share this post


Link to post
Share on other sites

i set it to 50 to test it after a few seconds the units de-spawn even if im still inside the trigger

---------- Post added at 22:13 ---------- Previous post was at 22:09 ----------

this is the code i have so far

if (!isServer) exitWith {};

_spawnPos = markerPos (_this select 0);

_group1 = createGroup EAST;

_unit1 = _group1 createUnit ["O_Soldier_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit2 = _group1 createUnit ["O_medic_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit3 = _group1 createUnit ["O_Soldier_GL_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit4 = _group1 createUnit ["O_Soldier_LAT_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
[_group1,_spawnPos,50] call bis_fnc_taskPatrol;


_BLUFOR_Count = 1;
while { _BLUFOR_Count > 0 } do
{
_BLUFOR_Count = {_x isKindof "Man" and (side _x) == west} count (nearestObjects [(getMarkerPos "spawnmarker"), [],50]);
sleep 5;
};

{deletevehicle _x} forEach (units _group1);
deleteGroup _group1;

Share this post


Link to post
Share on other sites

_null = [markerPos "spawntest"] execVM "spawnscript.sqf"

if (!isServer) exitWith {};

_spawnPos = _this select 0;
_enemyArray = [];

_group1 = createGroup EAST;
_unit1 = _group1 createUnit ["O_Soldier_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit2 = _group1 createUnit ["O_medic_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit3 = _group1 createUnit ["O_Soldier_GL_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit4 = _group1 createUnit ["O_Soldier_LAT_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_enemyArray = [_unit1,_unit2,_unit3,_unit4];

[_group1,_spawnPos,100] call bis_fnc_taskPatrol;

waitUntil { {player distance _x > 400} forEach _enemyArray };

{deletevehicle _x} forEach (units _group1);
deleteGroup _group1;

Share this post


Link to post
Share on other sites

got the same problem when i get out of range and the units de-spawn when i try to re-enter the units dont spawn again

Edited by hellstorm77

Share this post


Link to post
Share on other sites

Put the script above into an .sqf called spawntest.sqf for example.

Create a trigger set to repeat and name it trigg1. Then you can group the trigger to your player.

On Act: _null = [position trigg1] execVM "spawntest.sqf"

Now when the player enters the trigger the enemy group will spawn. When the player gets 400 meters away from the enemy they will delete. When you re-enter the trigger they will respawn.

Share this post


Link to post
Share on other sites

that worked great thank you

how would i deactivate the trigger when all enemies are dead?

Share this post


Link to post
Share on other sites

if (!isServer) exitWith {};

_spawnPos = _this select 0;

_group1 = createGroup EAST;
_unit1 = _group1 createUnit ["O_Soldier_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit2 = _group1 createUnit ["O_medic_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit3 = _group1 createUnit ["O_Soldier_GL_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit4 = _group1 createUnit ["O_Soldier_LAT_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;

[_group1,_spawnPos,100] call bis_fnc_taskPatrol;

waitUntil { player distance ((units _group1) select 0) > 200 or {alive _x} count (units _group1) == 0 };

{deletevehicle _x} forEach (units _group1);
deleteGroup _group1;

---------- Post added at 23:54 ---------- Previous post was at 23:43 ----------

This script will spawn in a random infantry squad.

if (isServer) then {
_spawnPos = _this select 0;

_group1 = createGroup EAST;
_spawn = ["OIA_InfSquad","OIA_InfSquad_Weapons","OIA_InfTeam","OIA_InfTeam_AT"] call BIS_fnc_selectRandom;
_group1 = [_spawnPos, east, (configFile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> _spawn)] call BIS_fnc_spawnGroup;

[_group1,_spawnPos,100] call bis_fnc_taskPatrol;

waitUntil { player distance ((units _group1) select 0) > 200 or {alive _x} count (units _group1) == 0 };

{deletevehicle _x} forEach (units _group1);
deleteGroup _group1;
};

Edited by cobra4v320

Share this post


Link to post
Share on other sites

if (isServer) then {
_spawnPos = _this select 0;

_group1 = createGroup EAST;
_spawn = ["OIA_InfSquad","OIA_InfSquad_Weapons","OIA_InfTeam","OIA_InfTeam_AT"] call BIS_fnc_selectRandom;
_group1 = [_spawnPos, east, (configFile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> _spawn)] call BIS_fnc_spawnGroup;

[_group1,_spawnPos,100] call bis_fnc_taskPatrol;

waitUntil { player distance ((units _group1) select 0) > 200 or {alive _x} count (units _group1) == 0 };

{deletevehicle _x} forEach (units _group1);
deleteGroup _group1;
};

is there a way to set how many spawn and is there away to deactivate the trigger when all enemies are dead?

Share this post


Link to post
Share on other sites

_null = [markerPos "spawn", 5] execVM "spawntest.sqf"

if (!isServer) exitWith {};

_spawnPos = _this select 0;
_num = _this select 1;

_group1 = createGroup EAST;

for "_i" from 1 to _num do {

   _unit = _group1 createUnit ["O_Soldier_F", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
};

[_group1,_spawnPos,100] call bis_fnc_taskPatrol;

waitUntil { player distance ((units _group1) select 0) > 200 or {alive _x} count (units _group1) == 0 };

{deletevehicle _x} forEach (units _group1);
deleteGroup _group1;

Share this post


Link to post
Share on other sites

if i place a marker called spawnmarker how would i call up spawntest.sqf so how would i get them to stay in a 100 sq zone

Share this post


Link to post
Share on other sites

Made some changes.

You can put it into the onact of a trigger, condition set to blufor or opfor present, set to repeat if you want it to execute every time you enter that trigger.

_null = [markerPos "spawn","east",100,"AWARE","YELLOW",400] execVM "spawnGroup.sqf"


if (isServer) then {
_spawnPos = _this select 0;
_side = _this select 1;
_patrolDist = if (count _this > 2) then {_this select 2} else {150};
_behavior = if (count _this > 3) then {_this select 3} else {"AWARE"};
_comMode = if (count _this > 4) then {_this select 4} else {"YELLOW"};
_deleteDist = if (count _this > 5) then {_this select 5} else {400};
_spawn = [];

private "_group";

switch (_side) do {
	case "east": {
		_spawn = ["OIA_InfSquad","OIA_InfSquad_Weapons","OIA_InfTeam","OIA_InfTeam_AT"] call BIS_fnc_selectRandom;
		_group = createGroup EAST;
		_group = [_spawnPos, east, (configFile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> _spawn)] call BIS_fnc_spawnGroup;
	};
	case "west": {
		_spawn = ["BUS_InfSquad","BUS_InfSquad_Weapons","BUS_InfTeam","BUS_InfTeam_AT"] call BIS_fnc_selectRandom;
		_group = createGroup WEST;
		_group = [_spawnPos, WEST, (configFile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> _spawn)] call BIS_fnc_spawnGroup;
	};
};

[_group,_spawnPos,_patrolDist] call bis_fnc_taskPatrol;
{_x setBehaviour _behavior; _x setCombatMode _comMode} forEach (units _group);

waitUntil { player distance ((units _group) select 0) > _deleteDist || {alive _x} count (units _group) == 0 };

{deletevehicle _x} forEach (units _group);
deleteGroup _group;
};

Share this post


Link to post
Share on other sites

say if my trigger is 1000m they will stay within 100m from the center or can the trigger be placed any where and they will spawn at a marker i place?

Share this post


Link to post
Share on other sites

The bis_fnc_taskpatrol will start a series of waypoints around a designated point. You can set the distance between the waypoints as I have showed you above. If you only want them to travel a small distance than make the waypoint distance smaller.

You can make your trigger as large as you want to, the units will patrol around the marker or trigger that you designated at the distance you selected in the function. The units will spawn at the center of your trigger or marker. Once your player gets a certain distance away or all of the enemy are killed they will be deleted.

Another option is to check if the script is running and prevent multiple units from being spawned in if you go in and out of the trigger.

Share this post


Link to post
Share on other sites

is it possible to spawn AI in on the client side instead of the server side?

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  

×