Jump to content
Sign in to follow this  
THORFINN

Creating/spawning an object at a random marker position?

Recommended Posts

Hi, I'm trying to make a simple script that will spawn an ammo crate at a few different empty markers.

_cacheSpawn = true;
while {_cacheSpawn} do {
_num=(ceil(Random 2));
if (_num==0) then {_cache = "GuerillaCacheBox_EP1" createVehicle getMarkerPos "mark1"}
if (_num==1) then {_cache = "GuerillaCacheBox_EP1" createVehicle getMarkerPos "mark2"};
if (_num==2) then {_cache = "GuerillaCacheBox_EP1" createVehicle getMarkerPos "mark3"};
};

I'm trying to exec it via init.sqf and it doesn't seem to be working. I'm not exactly sure what I'm doing in the first place though :X I've even searched a lot on the forums for this, but I can't seem to find exactly what I'm looking for.

Share this post


Link to post
Share on other sites

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

x=round(random 5) will return 0,1,2,3,4 or 5.

x=floor(random 5) will return 0,1,2,3 or 4.

x=ceil(random 5) will return 0, 1,2,3,4 or 5. (0 is very unlikely, but possible, as ceil 0 is 0)

I do that like this, you need a functions module on the map:

nul = ["GuerillaCacheBox_EP1",["mkr1", "mkr2", "mkr3"]] execVM "rndmkr.sqf";

waituntil {!isnil "bis_fnc_init"};
_type = _this select 0;
_mkrs = _this select 1;
_marker = _mkrs call BIS_fnc_selectRandom;
_cache = _type createVehicle getMarkerPos _marker;

You can add any class type and any number of markers in the execVM line.

Edited by PELHAM

Share this post


Link to post
Share on other sites

This is a similar thing that I am having trouble with. I have a very large senario with many objectives etc. I am trying to make a spawned radar with name, this is not a problem as I have all this working fine when there is only one marker. I am trying to make the radar have a choice of 6 different locations where it might spawn.

I have a trigger which calls the script but I am not sure how to implement what you have said into this.

This is the script

_spawn = [getmarkerpos "rusartill2", "RU_WarfareBArtilleryRadar", "artil2",55] execVM "mission1a.sqf";

The multipule markers will be called: rusartill2a, rusartill2b, rusartill2c etc

the object is named artil2 I need this because the objective is to destroy it, which once that is complete the next objective is called.

I cant have it in place from mission start as it is only called mid mission

Share this post


Link to post
Share on other sites

Try something like this mate...

_mkr_array = ["rusartill2a","rusartill2b","rusartill2c"];
_mkr_position = getmarkerpos (_mkr_array select floor (random (count _mkr_array)));
_spawn = [_mkr_position, "RU_WarfareBArtilleryRadar", "artil2",55] execVM "mission1a.sqf";

Share this post


Link to post
Share on other sites

If you want to make an object spawn at one of various locations, you can just group that object with markers in the editor. No scripting required. :)

(Of course this only works if you want the object to spawn right at the start of the mission.)

Share this post


Link to post
Share on other sites

You don't even need to use that much coding. Createvehicle has randomness built into it.

from the wiki (http://community.bistudio.com/wiki/createVehicle_array):

_veh = createVehicle ["2S6M_Tunguska",getMarkerPos "marker1",["marker2","marker3"], 0, "NONE"] 

This will spawn a Tunguska at either marker1, marker2, or marker3. You could substitue an ammo box in for the Tunguska. Or you could spawn an artillery round and have randomly-placed explosions (IED?).

[type, position, markers, placement, special]: Array

type: String

position: Position

markers: Array

placement: Number

special: String

Share this post


Link to post
Share on other sites

And furthermore in the "Code optimisation" page in the wiki it says:

It is highly recommended to use a standard of createVehicle array rather than the older (deprecated version) createVehicle. It is up to 500x faster than its older brother.

Cheers

Share this post


Link to post
Share on other sites

Thanks for your replies, I have it working perfect now I used the sugestion from twirly because it was easy to copy and paste. it worked straight away, I will however look into the other sugestions if that helps with performance Cheers all...

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  

×