Jump to content
Sign in to follow this  
Rytuklis

Spawning a group on a marker

Recommended Posts

Hey guys, I need to make a convincing combat scene in the city and I need the group to appear at the designated location and start the firefight as soon as a certain event happens.

Using triggers and conditions synchronized with waypoints does not give the effect I need.. I need an element of surprise..

Share this post


Link to post
Share on other sites

Use the createUnit (array) function

Object = group createUnit [type, position, markers, placement, special]

Object: A variable. Use this to manipulate the unit you are about to create.

Group: You need to create a group firsthand or something. Use this code in the INIT field on your squad leader:

group1 = group this;
"group1" is the name of the group and
"group" is the command to create groups
"this" literally refers to [b]this[/b] game object 

Or do whatever you want.

Position: [x, y, z]

Markers, Placement, Special: The documentation is super weak for these last 3 parts. I have no idea what markers are but, literally, as I typed this sentance, I realized what placement and special are.

Placement: When you place a unit down in the editor, "Placement Radius" is the box above "OK". I guess this number (in meters) means how far away a unit may spawn from where you put the unit down in the editor.

Special: Above "Control" when you put down a unit in the editor. None, Flying, In Cargo, In Formation are the types.

Here's a little example that I'm using in a mission right now:

_x = group1 createUnit ["B_Soldier_F",(getPos player1),[],0,"None"];

B_Soldier_F is a blufor rifleman so use this page to pick out which unit you want to spawn.

(getPos player1) probably isn't very helpful to you because you'll be spawning your enemy units directly next to your player (talk about an element of surprise!)

Instead, replace that with [x, y, z] and fill in your coordinates. Conveniently, if you look at the bottom in the editor, you can see the coordinates down to the 1/10th meter.

Put your createUnit function in "On Act." field of the trigger you want to set off the ambush.

Hope this helps.

EDIT: This method requires at least one enemy unit to be present so you can make a group. Without it, you won't be able to spawn the other units. Since I don't know how to make an empty group, this is the best I could do.

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

Markers, Placement, Special: The documentation is super weak for these last 3 parts. I have no idea what markers are but, literally, as I typed this sentance, I realized what placement and special are.

Placement: When you place a unit down in the editor, "Placement Radius" is the box above "OK". I guess this number (in meters) means how far away a unit may spawn from where you put the unit down in the editor.

Special: Above "Control" when you put down a unit in the editor. None, Flying, In Cargo, In Formation are the types.

from what i understand the MARKER parameter is where the unit will spawn. So, using this function in a loop, you could create 10 units at (potentially - the description says random, and we all know what random means :p) three different locations depending on where you placed the markers on the map. I havent tested this theory, so dont take my word for it.

EDIT: I tested my theory and that is indeed what the MARKER array parameter is.

_mkr1Pos = getMarkerPos "mkr1"; for "_i" from 1 to 10 do {_unit = group player createUnit ["B_Soldier_F", _mkr1Pos, ["mkr1", "mkr2", "mkr3"], 0, "NONE"];};

to spawn in a new group (create a new group) you use createGroup

so putting the two together would look like this:

_newGrp = createGroup west; 
_mkr1Pos = getMarkerPos "mkr1"; 

_loop = 1
while (_loop < 10) do 
{
    _unit = _newGrp createUnit ["B_Soldier_F", _mkr1Pos, ["mk1", "mkr2", "mkr3], 0, "NONE"];
    _loop = _loop + 1;
};

note: that if you don't specify a marker it uses the group specified leader's position.

note2: that "mkr1", "mkr2", and "mkr3" are objects i placed in the editor with the name "mkr1", "mkr2", and "mkr3" respectively. Or unrespectively, its your code ;)

Edited by Baconator
report testing results

Share this post


Link to post
Share on other sites

Neither of the mentioned methods worked.. This is what I did:

My cutscene script

; ****************************************************************
; Script file for Armed Assault
; Created by: TODO: Author Name
; ****************************************************************

showcinemaBorder false
_camera = "camera" camCreate [9292.85,20328.67,134.92];
_camera cameraEffect ["internal","back"]

;comment "19:26:23";
_camera camPrepareTarget [82711.22,-46332.73,13038.85];
_camera camPreparePos [9292.85,20328.67,134.92];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 4
titleCut ["Abderos, Altis. Present..","PLAIN DOWN"]
@camCommitted _camera

;comment "19:28:01";
_camera camPrepareTarget [82711.22,-46332.73,13038.91];
_camera camPreparePos [9285.59,20335.21,40.75];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 8
titleCut ["Abderos, Altis. Present..","PLAIN DOWN"]
@camcommitted _camera

cdrive = true
guerattack = true

_camera = "camera" camCreate [9466.24,20100.10,0.58];
_camera cameraEffect ["internal","back"]

;comment "19:30:36";
_camera camPrepareTarget [-88646.07,742.99,113.76];
_camera camPreparePos [9466.24,20100.10,0.58];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 0
@camcommitted _camera

;comment "19:32:00";
_camera camPrepareTarget civguer1
_camera camsettarget civguer1
_camera camPreparePos [9464.11,20097.19,0.90];
_camera camPrepareFOV 0.306;
_camera camCommitPrepared 13
@camcommitted _camera

civguer1 lookat grd1 
titleCut ["","BLACK OUT",3]
~3
civguer1 setdir getdir "tpciv"
civguer1 setpos getmarkerpos "tpciv"
grd2 dotarget civguer1
titleCut ["","BLACK FADED",4]
~4

_camera = "camera" camCreate [9458.96,20098.70,1.59];
_camera cameraEffect ["internal","back"]

titleCut ["","BLACK IN",3]

;comment "19:45:56";
_camera camPrepareTarget [-25328.32,-69637.05,-27039.82];
_camera camPreparePos [9458.96,20098.70,1.59];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 0
grd1 switchMove "Acts_ComingInSpeakingWalkingOut_5"
titlecut ["Show me your papers.","PLAIN DOWN"]
@camcommitted _camera

;comment "19:47:12";
_camera camPrepareTarget [-53012.51,96890.88,-14005.83];
_camera camPreparePos [9459.88,20093.61,1.76];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 8
@camcommitted _camera

_camera = "camera" camCreate [9455.03,20097.27,2.07];
_camera cameraEffect ["internal","back"]

;comment "20:16:27";
_camera camPrepareTarget civguer1
_camera camsettarget civguer1
_camera camPreparePos [9455.03,20097.27,2.07];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 4
@camcommitted _camera

_camera = "camera" camCreate [9936.85,20068.09,0.88];
_camera cameraEffect ["internal","back"]

;comment "20:18:06";
_camera camPrepareTarget [102420.42,57340.51,-7447.01];
_camera camPreparePos [9936.85,20068.09,0.88];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 6
titleCut ["Hold fire Annton! Await Eugene's code phrase.","PLAIN DOWN"]
@camcommitted _camera

_camera = "camera" camCreate [9457.67,20092.99,1.51];
_camera cameraEffect ["internal","back"]

;comment "20:24:58";
_camera camPrepareTarget [18641.34,119565.91,4672.79];
_camera camPreparePos [9457.67,20092.99,1.51];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 6
titleCut ["What the hell is wrong with you infidel? I said show me your papers! Who are you?","PLAIN DOWN"]
grd1 switchmove "AidlPercMstpSrasWrflDnon_G02_player"
@camcommitted _camera

_camera = "camera" camCreate [9455.03,20097.27,2.07];
_camera cameraEffect ["internal","back"]

;comment "20:16:27";
_camera camPrepareTarget civguer1
_camera camsettarget civguer1
_camera camPreparePos [9455.03,20097.27,2.07];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 4
titleCut ["I'm your grim reaper..","PLAIN DOWN"]
@camcommitted _camera

;comment "20:24:58";
_camera camPrepareTarget [18641.34,119565.91,4672.79];
_camera camPreparePos [9457.67,20092.99,1.51];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 2
titleCut ["What?","PLAIN DOWN"]
grd1 switchmove "AidlPercMstpSrasWrflDnon_G02_player"
@camcommitted _camera

guerattack = true

civguer1 addweapon "hgun_P07_F"
civguer1 addmagazine "30Rnd_9x21_Mag"

_camera = "camera" camCreate [9936.85,20068.09,0.88];
_camera cameraEffect ["internal","back"]

;comment "20:18:06";
_camera camPrepareTarget [102420.42,57340.51,-7447.01];
_camera camPreparePos [9936.85,20068.09,0.88];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 1
sniper doFire trg1
@camcommitted _camera

civguer1 enableAI "move"
civguer1 lookat grd2
civguer1 dotarget grd2
civguer1 dofire grd2
grd1 setDamage 1
playsound "resis1"

titleCut ["","WHITE FADED",1]
~1
titlecut ["","WHITE IN",1]

_camera = "camera" camCreate [9467.07,20097.86,1.32];
_camera cameraEffect ["internal","back"]

;comment "13:24:23";
_camera camPrepareTarget [-43832.09,-64446.59,-3265.59];
_camera camPreparePos [9467.07,20097.86,1.32];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 0
@camcommitted _camera

;comment "13:25:07";
_camera camPrepareTarget [2293.28,-79584.68,-3265.33];
_camera camPreparePos [9464.14,20100.60,1.38];
_camera camPrepareFOV 0.700;
grd2 switchmove "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright"
_camera camCommitPrepared 4
@camcommitted _camera

[] exec "spwnguer.sqs"

_camera = "camera" camCreate [9448.54,20261.63,15.47];
_camera cameraEffect ["internal","back"]

;comment "20:48:12";
_camera camPrepareTarget [-72342.73,-24957.54,-35431.02];
_camera camPreparePos [9448.54,20261.63,15.47];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 0
@camcommitted _camera

;comment "20:48:37";
_camera camPrepareTarget [-7635.66,-71568.36,-35428.70];
_camera camPreparePos [9406.43,20325.39,26.04];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 7
@camcommitted _camera

;comment "20:49:00";
_camera camPrepareTarget [97686.29,-10105.55,-35427.05];
_camera camPreparePos [9308.49,20296.47,42.05];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 17
@camcommitted _camera

titleCut ["Resistance","BLACK OUT",3]
~3
titleCut ["Resistance","BLACK FADED",5]
~3
titleCut ["Resistance","BLACK IN",3]

;comment "20:49:00";
_camera camPrepareTarget [97686.29,-10105.55,-35427.05];
_camera camPreparePos [9308.49,20296.47,42.05];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 3
@camcommitted _camera

My spwnguer script

_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos1"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos2"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos3"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos4"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos5"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos6"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos7"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos8"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos9"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos10"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos1"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos2"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos3"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos4"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos5"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos6"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos7"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos8"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos9"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos10"),[],0,"None"];

Help?

Edited by Rytuklis

Share this post


Link to post
Share on other sites

_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos1"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos2"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos3"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos4"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos5"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos6"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos7"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos8"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos9"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos10"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos1"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos2"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos3"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos4"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos5"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos6"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos7"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos8"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos9"),[],0,"None"];
_x = group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos10"),[],0,"None"];

Give every unit a different name : unit1, unit2,.... as you want.

_x is a magic variable used to access the current element in "forEach" and "count" command.

Share this post


Link to post
Share on other sites
Give every unit a different name : unit1, unit2,.... as you want.

_x is a magic variable used to access the current element in "forEach" and "count" command.

At which point of the code im supposed to add the title? Can you please edit one line of that code to be correct?

Share this post


Link to post
Share on other sites

_group1 = creategroup west;

_unit1 = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos1"),[],0,"None"];
_unit2 = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos2"),[],0,"None"];
_unit3 = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos3"),[],0,"None"];
_unitunit = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos4"),[],0,"None"];
_you = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos5"),[],0,"None"];
_can = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos6"),[],0,"None"];
_namethen = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos7"),[],0,"None"];
_like = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos8"),[],0,"None"];
_you = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos9"),[],0,"None"];
_want = _group1 createUnit ["B_Soldier_F",(getMarkerPos "spwnpos10"),[],0,"None"];

you can use the names you like, not these: https://community.bistudio.com/wiki/Magic_Variables

Share this post


Link to post
Share on other sites
At which point of the code im supposed to add the title? Can you please edit one line of that code to be correct?

How are you trying to spawn these units? It looks like you want to spawn 2 units at 10 positions.

_newGrp = createGroup west; 
_mkr1Pos = getMarkerPos "mkr1"; 

_loop = 1
while (_loop < 10) do 
{
    _unit = _newGrp createUnit ["B_Soldier_F", _mkr1Pos, ["mk1", "mkr2", "mkr3], 0, "NONE"];
    _loop = _loop + 1;                                                  //   ^ He forgot a quote here so that's why this didn't work.
};

Use Baconator's code and modify it to do what you want.

This is what I came up with.

_newGrp = createGroup west;  //create a new group of BLUFOR soldiers
_markerArray = [getMarkerpos "spwnpos1", getMarkerpos "spwnpos2", getMarkerpos "spwnpos3", getMarkerpos "spwnpos4", getMarkerpos "spwnpos5", getMarkerpos "spwnpos6", getMarkerpos "spwnpos7", getMarkerpos "spwnpos8", getMarkerpos "spwnpos9", getMarkerpos "spwnpos10"]; //setting up an [url="https://community.bistudio.com/wiki/Array"]Array[/url] with the positions of all your spawners.

{
    {
         _unit = _newGrp createUnit ["B_Soldier_F", _markerArray select _x, [], 0, "NONE"];  //nested loop makes a blufor soldier named _unit, part of _newGrp, and cycles through all 10 spawn locations
    } forEach [1, 2];  //made a trash array with no name, just to spawn 2 units
} forEach  _markerArray;

//lastly, _x is a local variable that forEach uses for it's index, that's why we don't have to define it but can use it. The spawn code I posted earlier using _x was just bad practice, don't do that.

This code will cycle through each spawn location, one by one, spawning 2 units. If you switch around "_markerArray" and "[1, 2]" it will create 1 unit at all the locations, but go through it twice. That could be useful if you're trying to get the units spread out quickly.

Good Luck

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

Whats interesting about the marker array in the createUnit array function parameters is that it selects a marker at random. So if you had an array of 10 markers and your loop ran twice, you could create 1 unit at one marker and another unit at another marker (or potentially two at the same one), and each time this code block was run (maybe put it in its own script and call that script from a trigger activation) you would get 2 units at a random marker position. It wouldn't be the same location every time you played the mission. Very useful for creating dynamic missions and re-playability. Im not sure how heavy the function is for randomly selecting a marker, so if you create a lot of units and place them with the random marker array, it could potentially cause lag and frame drop, but you would run into the problem of having a lot of AI units on the map anyway.

Share this post


Link to post
Share on other sites

Thank you gentlemen, these have worked, however, the problem is I need to spawn the Guerillas (FIA), not the US soldiers and i cant find the unit name for them. Any ideas?

Share this post


Link to post
Share on other sites

In addition to that unit classnames are displayed at the top right of the unit creation panel.

Share this post


Link to post
Share on other sites

Here you go buddy,

https://community.bistudio.com/wiki/Arma_3_CfgVehicles_GUER

And you also have blufor, and opfor.

And overall page with all Arma 3 assets. (weapons, vehicles, magazines)

https://community.bistudio.com/wiki/Arma_3_Assets

EDIT: Oops, Baconator got to it first. When I refreshed the page, I didn't see that there was a second page.

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  

×