Jump to content
Sign in to follow this  
Binary

createVehicle array syntax

Recommended Posts

Hello folks,

I'm trying to spawn a vehicle at a random position, from an array of markers.

spawn.sqf:

_spawnpoints = [spawn1, spawn2, spawn3]; //Name of the markers
_veh = createVehicle something-something-something;

Looking at the wiki for createVehicle array, I can't wrap my head around the syntax

http://community.bistudio.com/wiki/createVehicle_array

Looking at the command description, it does seem like what i need: "If the markers array contains several marker names, the position of a random one is used."

I guess I'm looking for something like this:

_veh = createVehicle ["classname", getMarkerPos "_spawnpoints", [], 0, "NONE"]

Edited by Binary

Share this post


Link to post
Share on other sites

There is an example on that wiki page, isn't it working? According to that example your code should look like this:

_veh = createVehicle ["classname", getMarkerPos spawn1, ["spawn1", "spawn2", "spawn3"], 0, "NONE"]

Where third argument is an array of your markers. I think the second argument is default position, just to create vehicle at least somewhere if something goes wrong.

Share this post


Link to post
Share on other sites

I just thought that the whole point of defining the array, was that so I didn't had to type spawn1, spawn2, spawn3, spawn4 so on.. (In the real script, I got 36 spawn points)

Share this post


Link to post
Share on other sites

So, all those markers are placed in editor? Well, thats probably a little bit strange workaround, but try this:

_i = 1;
_spawnpoints = [];
while {_i < 37} do
{
 _markerName = "spawn" + str(_i);
 _spawnpoints set[count _spawnpoints, _markerName];
 _i = _i + 1;
}

That code should add to array all markers which names look like "spawnInteger" (to be more precise, that array contains marker names, not actual makers, but it doesn't matter since markers are accessed by their names). It works for me, but don't forget to change value that represents marker count in "while" condition if you are going to add or remove markers.

But if you created all your makers in some script then you probably can add marker to array just after it was created.

Edited by Semiconductor

Share this post


Link to post
Share on other sites

_spawnpoints = ["spawn1", "spawn2","spawn3"];
_myVehicle = createVehicle ["B_MRAP_01_F", [0,0,0], _spawnpoints, 0, "NONE"]; 

Your marker names need to be in quotes in the spawnpoint array.

"B_MRAP_01_F" is the class of the vehicle you want to spawn.

[0,0,0] is just a crap position as it will be ignored (from what i have tested, just looped this code and spawned 1000 MRAP's all spawned at a random marker, none spawned at [0,0,0] )

_spawnpoints is your array of markers that you have setup in the the previous line.

0 means they will try to spawn on the exact spot if clear.

"NONE" there is no special condition for this spawn.

Share this post


Link to post
Share on other sites

Thanks Larrow !

That explanation was excatly what I needed - it actually makes sense now :)

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  

×