Results 1 to 9 of 9

Thread: Creating/spawning an object at a random marker position?

  1. #1

    Creating/spawning an object at a random marker position?

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

    Code:
    _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.

  2. #2
    I shall not insult moderators
    Join Date
    Nov 25 2010
    Posts
    1,576
    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";
    Code:
    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.
    Last edited by PELHAM; Apr 16 2012 at 09:54.

  3. #3
    Private First Class
    Join Date
    Dec 19 2011
    Posts
    28
    Author of the Thread
    Thanks! That worked. :D

  4. #4
    Gunnery Sergeant
    Join Date
    Apr 3 2002
    Location
    Brighouse, West Yorkshire. (UK)
    Posts
    576
    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

  5. #5
    Master Gunnery Sergeant twirly's Avatar
    Join Date
    Sep 13 2010
    Location
    Gods Own (NZ)
    Posts
    1,302
    Try something like this mate...

    Code:
    _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";

    "Learn by doing!" - Quoted from a post by Imutep

    OUTERRA - OUTERRA - OUTERRA - OUTERRA - BLOWMIND!

  6. #6
    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.)
    Get Arma2 OA Beta Notifications via e-mail | RSS | Twitter

    Gigabyte P67X-UD3-B3 Motherboard | Intel Core i7 2600k @ 4.0GHz | NVidia GeForce GTX560 TI
    16GB Corsair XMS3 1600Mhz RAM | Kingston HyperX SSD | ASUS Xonar D2X
    sound | be Quiet! 700W PSU | Windows 7 x64


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

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

    Code:
    _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

  8. #8
    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

  9. #9
    Gunnery Sergeant
    Join Date
    Apr 3 2002
    Location
    Brighouse, West Yorkshire. (UK)
    Posts
    576
    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...

Similar Threads

  1. Semi random hvt spawning position?
    By ZZEZ in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 1
    Last Post: Feb 20 2011, 16:10
  2. Creating green smoke at a marker position?
    By Acelondoner in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 4
    Last Post: Jan 23 2011, 02:11
  3. Making a marker move to a random spawning object.
    By MechaStalin in forum ARMA - MISSION EDITING & SCRIPTING
    Replies: 1
    Last Post: Jan 5 2009, 12:54
  4. need help spawning a random object
    By madmedic in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 9
    Last Post: Oct 11 2005, 02:44
  5. A marker at a random position?
    By Spy17 in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 2
    Last Post: Oct 13 2002, 09:57

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •