Jump to content
Sign in to follow this  
thetrooper

Spawn a unit on trigger

Recommended Posts

Hi, I never thought it would be so hard to find a script for a simple spawn. Can anyone tell me how to spawn either a single unit, or group in a particular place after a trigger is tripped?

Share this post


Link to post
Share on other sites

Create a scriptfile in yourn mission folder, maybe spawn.sqf. Open it with a texteditor (I prefer notepad++) and write something like this inside:

_grp = createGroup [i]west[/i];
_pos = getpos player;
_unit = _grp createUnit ["[i]USMC_Soldier[/i]", _pos, [], 100, "FORM"] ;   

And run this script from the "On Activation"-Line in your trigger:

dumvar = [] execVM "spawn.sqf"

This will spawn a USMC Soldier on the players position if the trigger is activated.

A list of available units could be found here: http://forums.bistudio.com/showthread.php?t=73241

You can also alter _pos and the side of the group (resistance, east, civilian). You can also use an existing group. For example your own group to create a new squadmember:

_grp = group player;

To spawn a whole group, you could copy the createunit line. This could also be more dynamic, if you use for- and while-loops and other sqf-structures, but this is a little bit more advanced topic.

A simple groupspawn could be like this:

_grp = createGroup west;

_pos = getpos player;

_unit1 = _grp createUnit ["USMC_Soldier_SL", _pos, [], 100, "FORM"];

_unit2 = _grp createUnit ["USMC_Soldier", _pos, [], 100, "FORM"];

_unit3 = _grp createUnit ["USMC_Soldier_MG", _pos, [], 100, "FORM"];

_unit4 = _grp createUnit ["USMC_Soldier_Medic", _pos, [], 100, "FORM"];

And I also forget to mention: the side of you group must be already present. So if your group is for example the first westgroup, you must either call "createcenter west:" in your script or place a westunit somewhere on the map.

Edited by NeoArmageddon

Share this post


Link to post
Share on other sites

and BIS_fnc_spawnGroup is the best way to spawn groups.

And as NeoArmageddon said, always have a unit of that side present before spawning or create a center.

Easiest and should be default beheaviour for a mission maker with spawns is to have 1 unit of any side present in your mission in a corner of map with probability slider of 0.

That way they are never there and will not mess up your mission, but a center will be created for that side so all spawns during the mission will work fine.

Share this post


Link to post
Share on other sites

Hi there, im trying scripting since yesterday. i so far only spawned units from a trigger init in the editor, now i try with the sqf files.... I tried in different ways but i still am not able to spawn units through a script.

i have a .sqf file named "spawnwest.sqf". I just want to make it spwan a group of friendly units around the location of the trigger, when the player enters the area.

Trigger set to detect bluefor and fire repeatedly... Trigger fires, thats not the problem^^

The triggers onAct says:

"nul = [] execVM "spawnwest.sqf"; hint " spawn triggered countereast";" and i do get the hint

in the spawnwest.sqf i have these lines:

"

_grp = createGroup west;

_grp = [getPos _this, WEST, (configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> "BUS_ReconSquad")] call BIS_fnc_spawnGroup;

sleep 1;

"

where is my mistake?

i do this in arma 3 btw, not sure if im right here, but i thought its somewhat the same?

Share this post


Link to post
Share on other sites

_this refers to whatever was passed into the script from the execVM array. It likely fails because execVM passes an empty array [], so nothing is passed into the script for "getPos _this" to use.

https://community.bistudio.com/wiki/Arma2:_Startup_Parameters

Use launch options -showScriptErrors and do not use -noLogs.

You will see errors on screen when they occur, and have the error generated in the .rpt file for review.

Quite often the -showScriptErrors box will display a "[#]" in front of the command or variable that generated the error.

Also, the line:

_grp = createGroup west;

is not needed, the BIS_fnc_spawnGroup does that inside the function using the side designated in the call array.

Edited by OpusFmSPol

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  

×