Jump to content
redarmy

Random object placement spawning as set

Recommended Posts

Ok let me best try to explain this,

 

because the question is harder to explain than the awnser im guessing.Im searching the forums but as said i dont know what to ask to describe the effect im looking for.

 

It should be simple so if anyone can help out,appreciated.

 

I am creating a simple tent/fire/table/chair  and a group of AI with BIS function task defend.  I want all these objects and units to spawn on the map BUT with a random placement radius.So if in the editor i spawn them on Molos runway in Altis and set a placement radius of 2000M they might end up spawning in Molos town...the problem is i want them to spawn together as i set them down in the editor,such as the chair next to the fire...temt behind that etc..

 

Im guessing its like grouping them together but obviosly not that simple.

 

Anyone know how to achieve this effect?

Share this post


Link to post
Share on other sites

Having made your set of objects in the editor, you would define one of them as the "keystone" and then log the relative position and the classnames of all the other objects to the rpt file.

 

From this you can then extract the data from the rpt and create an nested array of all the objects, both their classname and relative position.

In your script you then setpos your "keystone" object to the relative position.

You then createvehicle the rest of the objects to their relative position from the "keystone".

 

Here is code I use this system on to create a copies of a scenario.

You should be able to extract the relevant info from it.

 

// AUTHOR : Terox (terox_@hotmail.com)
// MP MACHINE : SERVER
// Called from  : PV eventhandler
// Called using : _a spawn Tx_RNG_fActivate_Units
// Time Called  : Via addaction on switch 3
// Description  : Creates units in randonly selected places relative to the keystone
// Allows for creating the alpha range and then copy pasting, so that unit placement in other ranges is relative to their keystone
// COMMENTS : This is a scenario, players find a friendly wounded unit, what do they do
 
 
private ["_keystone", "_doors", "_keystoneDIR", "_u", "_uARR", "_MaxU", "_leaderPosARR", "_uPosARR",
         "_getUARR", "_ARR", "_casPOS", "_classWU",  "_uPos"," _grp", "_uDIR", "_uStance", "_u", "_side","_classCO",
         "_classSL", "_classMG", "_classAT", "_classGR", "_classRF", "_classSN", "_classARR", "_counter"];
  _keystone       = _this select 0;
  _doors          = _this select 2;
  _keystoneDIR    = getdir _keystone;
  _u              = objnull;
  _uARR         = [];
  _MaxU  = 6;
  _leaderPosARR = [];
  _uPosARR      = [];
  _getUARR = _keystone getvariable "UnitARR";
 
  if !(Isnil "_getUARR")then
  {
    {if !(Isnull _x)then{deletevehicle _x}}foreach _getUARR;
  };
 
// Array of Relative unit positions to the keystone
  _ARR =
  [
    [  [-15.9551,206.377,-0.739075], 164.35  , "DOWN" ],
    [  [-12.8203,207.795,-0.739075], 166.148 , "DOWN" ],
    [  [-5.27148,205.031,-0.739075], 163.435 , "DOWN" ],
    [  [60.6621,205.158,-0.739075] , 189.433 , "DOWN" ],
    [  [63.5313,207.637,-0.739075] , 189.739 , "DOWN" ],
    [  [68.1113,207.059,-0.739075] , 190.525 , "DOWN" ],
    [  [70.8965,205.238,-0.739075] , 189.582 , "DOWN" ],
    [  [55.2695,270.979,-0.739075] , 181.371 , "DOWN" ],
    [  [52.418,272.703,-0.739075]  , 185.177 , "DOWN" ],
    [  [47.6582,273.379,-0.739075] , 179.751 , "DOWN" ],
    [  [44.8633,271.148,-0.739075] , 184.007 , "DOWN" ],
    [  [11.8496,270.162,-0.739075] , 176.534 , "DOWN" ],
    [  [4.23047,272.811,-0.739075] , 172.511 , "DOWN" ],
    [  [1.38672,270.613,-0.739075] , 171.18  , "DOWN" ],
    [  [22.5586,304.834,-0.739075] , 175.801 , "DOWN" ],
    [  [25.5137,307.453,-0.739075] , 177.988 , "DOWN" ],
    [  [28.6016,309.412,-0.739075] , 180.249 , "DOWN" ],
    [  [34.5586,305.094,-0.739075] , 180.988 , "DOWN" ]
  ];
 
  _CasPos =[  [29.5586,15.8164,-0.739075] , 339.653 , "MIDDLE" ];
  _classWU = ["B_Soldier_TL_F"  ,"BLUFOR" , "RIFLEMAN" ];
 
 
 
/////////////////////////////////////////////////
/////     CREATE THE SCENARIO CASUALTY      /////
/////////////////////////////////////////////////
  _grp = createGroup WEST;
  _Upos   = _keystone  modeltoWorld (_CasPos select 0);
  _UDir   = _keystoneDIR + (_CasPos select 1);
  _UStance= _CasPos select 2;
  _u = [_grp, _classWU, [_Upos, _UDir, _UStance], "NONE","STOP"]call Tx_RNG_fCreateUnit;
  waituntil {! Isnull _u};
  _u allowDamage false;
  _u setCaptive true;
  _u playMove "AinjPpneMstpSnonWrflDnon_rolltoback";
  _u setVariable ["FAR_isUnconscious", 1, true];
  _u setVariable ["FAR_isStabilized", 0, true];
  _u setVariable ["FAR_isDragged", 0, true];
  [_u, _u] spawn FAR_Player_Unconscious;
 
  _grp setCombatMode "GREEN";
 
// Send the unit across the network so that actions can be added
/*  Tx_RNG_PVEvent =["ADD_ACTION",[_u]];
  Publicvariable "Tx_RNG_PVEvent";
  ["",["ADD_ACTION",[_u]]] call Tx_RNG_fevent_PVReceiver;
 
  */
  _uARR = _uARR + [_u];
 
/////////////////////////////////////////////
/////     CREATE THE ENEMY LEADER      /////
/////////////////////////////////////////////
 
  _uPosARR = (_ARR call Tx_RNG_fshuffleArray) call Tx_RNG_fshuffleArray;
  _leaderPosARR = _uPosARR select 0;
 
  _side = EAST;
  _classCO = ["O_officer_F"     ,"OPFOR" , "CO" ];
  _classSL = ["O_Soldier_SL_F"  ,"OPFOR" , "SL" ];
  _classMG = ["O_Soldier_AR_F"  ,"OPFOR" , "MG" ];
  _classAT = ["O_Soldier_LAT_F" ,"OPFOR" , "AT" ];
  _classGR = ["O_Soldier_GL_F"  ,"OPFOR" , "GL" ];
  _classRF = ["O_Soldier_F"     ,"OPFOR" , "RIFLE"];
  _classSN = ["O_Soldier_F"     ,"OPFOR" , "SNIPER"];
  _classARR = _classRF;
 
/////////////////////////////////////////////////
/////     CREATE THE GROUP & THE LEADER     /////
/////////////////////////////////////////////////
  _grp = createGroup _side;
  _Upos   = _keystone  modeltoWorld (_leaderPosARR select 0);
  _UDir   = _keystoneDIR + (_leaderPosARR select 1);
  _UStance= _leaderPosARR select 2;
  _u = [_grp, _classCO, [_Upos, _UDir, _UStance], "NONE","STOP"]call Tx_RNG_fCreateUnit;
  waituntil {! Isnull _u};
  _grp lockWP TRUE;
  _grp enableAttack false;
  // Do not fire
  _grp setCombatMode "GREEN";
  _u setdir _UDir;
  _u setskill (0.1 + (random 0.2));
  _u setRank "CAPTAIN";
  dostop _u;
  _u dowatch ([_u, 35, _UDir] call BIS_fnc_relPos);
  _uARR = _uARR + [_u];
 
/////////////////////////////////////////////////
/////      CREATE THE STATIC UNITS          /////
/////////////////////////////////////////////////
 
_counter = 1;
While{_counter <= _MaxU}do
{
    systemchat format ["UNIT No. %1 being created",_counter];
    _Upos   = _keystone  modeltoWorld ((_uPosARR select _counter) select 0);
    _UDir   = _keystoneDIR + ((_uPosARR select _counter)  select 1);
    _UStance= ((_uPosARR select _counter)  select 2);
    switch (_counter)do
    {
      case 1: {_classARR = _classMG};
      case 2: {_classARR = _classSN};
      default {_classARR = _classRF};
    };
    _u = objnull;
    _u = [_grp, _classARR, [_Upos, _UDir, _UStance], "NONE","STOP"]call Tx_RNG_fCreateUnit;
    waituntil {! Isnull _u};
    _u setskill (0.1 + (random 0.2));
    _u dowatch ([_u, 300, _UDir] call BIS_fnc_relPos);
    _uARR = _uARR + [_u];
    _counter = _counter + 1;
 
    sleep 0.1;
};
 
  {_x addMPEventHandler  ["Killed",{_this call Tx_RNG_fEH_AIkilled}]}foreach _uARR;
  _keystone setvariable ["UnitARR",_uARR];
 
  sleep 3;
  {if !(Isnull _x)then{deletevehicle _x}}foreach _doors;

Share this post


Link to post
Share on other sites

 

Having made your set of objects in the editor, you would define one of them as the "keystone" and then log the relative position and the classnames of all the other objects to the rpt file.

 

From this you can then extract the data from the rpt and create an nested array of all the objects, both their classname and relative position.

In your script you then setpos your "keystone" object to the relative position.

You then createvehicle the rest of the objects to their relative position from the "keystone".

 

Here is code I use this system on to create a copies of a scenario.

You should be able to extract the relevant info from it.

// AUTHOR : Terox (terox_@hotmail.com)
// MP MACHINE : SERVER
// Called from  : PV eventhandler
// Called using : _a spawn Tx_RNG_fActivate_Units
// Time Called  : Via addaction on switch 3
// Description  : Creates units in randonly selected places relative to the keystone
// Allows for creating the alpha range and then copy pasting, so that unit placement in other ranges is relative to their keystone
// COMMENTS : This is a scenario, players find a friendly wounded unit, what do they do
 
 
private ["_keystone", "_doors", "_keystoneDIR", "_u", "_uARR", "_MaxU", "_leaderPosARR", "_uPosARR",
         "_getUARR", "_ARR", "_casPOS", "_classWU",  "_uPos"," _grp", "_uDIR", "_uStance", "_u", "_side","_classCO",
         "_classSL", "_classMG", "_classAT", "_classGR", "_classRF", "_classSN", "_classARR", "_counter"];
  _keystone       = _this select 0;
  _doors          = _this select 2;
  _keystoneDIR    = getdir _keystone;
  _u              = objnull;
  _uARR         = [];
  _MaxU  = 6;
  _leaderPosARR = [];
  _uPosARR      = [];
  _getUARR = _keystone getvariable "UnitARR";
 
  if !(Isnil "_getUARR")then
  {
    {if !(Isnull _x)then{deletevehicle _x}}foreach _getUARR;
  };
 
// Array of Relative unit positions to the keystone
  _ARR =
  [
    [  [-15.9551,206.377,-0.739075], 164.35  , "DOWN" ],
    [  [-12.8203,207.795,-0.739075], 166.148 , "DOWN" ],
    [  [-5.27148,205.031,-0.739075], 163.435 , "DOWN" ],
    [  [60.6621,205.158,-0.739075] , 189.433 , "DOWN" ],
    [  [63.5313,207.637,-0.739075] , 189.739 , "DOWN" ],
    [  [68.1113,207.059,-0.739075] , 190.525 , "DOWN" ],
    [  [70.8965,205.238,-0.739075] , 189.582 , "DOWN" ],
    [  [55.2695,270.979,-0.739075] , 181.371 , "DOWN" ],
    [  [52.418,272.703,-0.739075]  , 185.177 , "DOWN" ],
    [  [47.6582,273.379,-0.739075] , 179.751 , "DOWN" ],
    [  [44.8633,271.148,-0.739075] , 184.007 , "DOWN" ],
    [  [11.8496,270.162,-0.739075] , 176.534 , "DOWN" ],
    [  [4.23047,272.811,-0.739075] , 172.511 , "DOWN" ],
    [  [1.38672,270.613,-0.739075] , 171.18  , "DOWN" ],
    [  [22.5586,304.834,-0.739075] , 175.801 , "DOWN" ],
    [  [25.5137,307.453,-0.739075] , 177.988 , "DOWN" ],
    [  [28.6016,309.412,-0.739075] , 180.249 , "DOWN" ],
    [  [34.5586,305.094,-0.739075] , 180.988 , "DOWN" ]
  ];
 
  _CasPos =[  [29.5586,15.8164,-0.739075] , 339.653 , "MIDDLE" ];
  _classWU = ["B_Soldier_TL_F"  ,"BLUFOR" , "RIFLEMAN" ];
 
 
 
/////////////////////////////////////////////////
/////     CREATE THE SCENARIO CASUALTY      /////
/////////////////////////////////////////////////
  _grp = createGroup WEST;
  _Upos   = _keystone  modeltoWorld (_CasPos select 0);
  _UDir   = _keystoneDIR + (_CasPos select 1);
  _UStance= _CasPos select 2;
  _u = [_grp, _classWU, [_Upos, _UDir, _UStance], "NONE","STOP"]call Tx_RNG_fCreateUnit;
  waituntil {! Isnull _u};
  _u allowDamage false;
  _u setCaptive true;
  _u playMove "AinjPpneMstpSnonWrflDnon_rolltoback";
  _u setVariable ["FAR_isUnconscious", 1, true];
  _u setVariable ["FAR_isStabilized", 0, true];
  _u setVariable ["FAR_isDragged", 0, true];
  [_u, _u] spawn FAR_Player_Unconscious;
 
  _grp setCombatMode "GREEN";
 
// Send the unit across the network so that actions can be added
/*  Tx_RNG_PVEvent =["ADD_ACTION",[_u]];
  Publicvariable "Tx_RNG_PVEvent";
  ["",["ADD_ACTION",[_u]]] call Tx_RNG_fevent_PVReceiver;
 
  */
  _uARR = _uARR + [_u];
 
/////////////////////////////////////////////
/////     CREATE THE ENEMY LEADER      /////
/////////////////////////////////////////////
 
  _uPosARR = (_ARR call Tx_RNG_fshuffleArray) call Tx_RNG_fshuffleArray;
  _leaderPosARR = _uPosARR select 0;
 
  _side = EAST;
  _classCO = ["O_officer_F"     ,"OPFOR" , "CO" ];
  _classSL = ["O_Soldier_SL_F"  ,"OPFOR" , "SL" ];
  _classMG = ["O_Soldier_AR_F"  ,"OPFOR" , "MG" ];
  _classAT = ["O_Soldier_LAT_F" ,"OPFOR" , "AT" ];
  _classGR = ["O_Soldier_GL_F"  ,"OPFOR" , "GL" ];
  _classRF = ["O_Soldier_F"     ,"OPFOR" , "RIFLE"];
  _classSN = ["O_Soldier_F"     ,"OPFOR" , "SNIPER"];
  _classARR = _classRF;
 
/////////////////////////////////////////////////
/////     CREATE THE GROUP & THE LEADER     /////
/////////////////////////////////////////////////
  _grp = createGroup _side;
  _Upos   = _keystone  modeltoWorld (_leaderPosARR select 0);
  _UDir   = _keystoneDIR + (_leaderPosARR select 1);
  _UStance= _leaderPosARR select 2;
  _u = [_grp, _classCO, [_Upos, _UDir, _UStance], "NONE","STOP"]call Tx_RNG_fCreateUnit;
  waituntil {! Isnull _u};
  _grp lockWP TRUE;
  _grp enableAttack false;
  // Do not fire
  _grp setCombatMode "GREEN";
  _u setdir _UDir;
  _u setskill (0.1 + (random 0.2));
  _u setRank "CAPTAIN";
  dostop _u;
  _u dowatch ([_u, 35, _UDir] call BIS_fnc_relPos);
  _uARR = _uARR + [_u];
 
/////////////////////////////////////////////////
/////      CREATE THE STATIC UNITS          /////
/////////////////////////////////////////////////
 
_counter = 1;
While{_counter <= _MaxU}do
{
    systemchat format ["UNIT No. %1 being created",_counter];
    _Upos   = _keystone  modeltoWorld ((_uPosARR select _counter) select 0);
    _UDir   = _keystoneDIR + ((_uPosARR select _counter)  select 1);
    _UStance= ((_uPosARR select _counter)  select 2);
    switch (_counter)do
    {
      case 1: {_classARR = _classMG};
      case 2: {_classARR = _classSN};
      default {_classARR = _classRF};
    };
    _u = objnull;
    _u = [_grp, _classARR, [_Upos, _UDir, _UStance], "NONE","STOP"]call Tx_RNG_fCreateUnit;
    waituntil {! Isnull _u};
    _u setskill (0.1 + (random 0.2));
    _u dowatch ([_u, 300, _UDir] call BIS_fnc_relPos);
    _uARR = _uARR + [_u];
    _counter = _counter + 1;
 
    sleep 0.1;
};
 
  {_x addMPEventHandler  ["Killed",{_this call Tx_RNG_fEH_AIkilled}]}foreach _uARR;
  _keystone setvariable ["UnitARR",_uARR];
 
  sleep 3;
  {if !(Isnull _x)then{deletevehicle _x}}foreach _doors;

Thnaks so much for sharing and im not tryna sound ungrateful but im sure there is an easier method for keepingobjects spawned together with even using the init.sqf or scripts.

Share this post


Link to post
Share on other sites

Place a table on the map and name it    table1

 

Use various methods so that the table always starts at a random location.

 

Place a chair on the map and name it   chair1

 

You want the chair to ALWAYS be 5 meters to the north of the table

 

chair1 setPos [(getPos table1 select 0) +0, (getPos table1 select 1) +5]; 

 

 

You want the chair to ALWAYS be 5 meters to the south of the table

 

chair1 setPos [(getPos table1 select 0) +0, (getPos table1 select 1) -5]; 

 

 

You want the chair to ALWAYS be 5 meters to the east of the table

 

chair1 setPos [(getPos table1 select 0) +5, (getPos table1 select 1) +0]; 

 

 

You want the chair to ALWAYS be 5 meters to the west of the table

 

chair1 setPos [(getPos table1 select 0) -5, (getPos table1 select 1) +0]; 

 

.

.

Share this post


Link to post
Share on other sites

Thanks for input mate,all ya...i found this great script from jshock( i realise i said i didnt want scripts) but this one is very easy to understand and impliment.And you can set up compositions of F.O.B's or anything you like with simply a few game logics

 

heres the thread,near the end read the script and instructions.Its from Arma2 made by Jshock i beleive but it works here.

 

https://forums.bistudio.com/topic/101205-moving-multiple-objectsunits-to-random-locations/

Share this post


Link to post
Share on other sites

Defintely not mine :P. I had used the same function tag as Shuko in my earlier days, but soon realized it and I've tried to steer away from it (via JSHK instead of SHK).

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

×