Jump to content
Sign in to follow this  
1para{god-father}

How to Remove all Objects

Recommended Posts

I am creating a roadblock and all works great but how can i remove all objects when needed, I presume i can delete each object i.e

Deletevehicle  _bg1;

but is there a cleaner way ?

Thanks



// Define [ Gate, Blocks, Barriers, Guides, Nest, Wire, Weapon] for each faction

_list = switch (_fac) do {
// RU
case "RU": {["ZavoraAnim","Land_CncBlock","RoadBarrier_long","Land_arrows_desk_L","Land_arrows_desk_R","Land_fortified_nest_small","Fort_RazorWire","M2StaticMG"]};
// ACE_RU
   case "ACE_RU": {["ZavoraAnim","Land_CncBlock","RoadBarrier_long","Land_arrows_desk_L","Land_arrows_desk_R","Land_fortified_nest_small","Fort_RazorWire","M2StaticMG"]};
// GUE
case "GUE": {["","Sign_Checkpoint","RoadBarrier_long","RoadCone","RoadCone","Land_BagFenceLong","RoadBarrier_light","SearchLight"]};
// INS
case "INS": {["ZavoraAnim","Sign_Checkpoint","RoadBarrier_long","RoadCone","RoadCone","Land_BagFenceLong","RoadBarrier_light","M2StaticMG"]};
// BIS_TK
case "BIS_TK": {["ZavoraAnim","Land_CncBlock","RoadBarrier_long","Land_arrows_desk_L","Land_arrows_desk_R","Land_fortified_nest_small","Fort_RazorWire","M2StaticMG"]};
// BIS_TK_INS
case "BIS_TK_INS": {["","Sign_Checkpoint_TK_EP1","RoadBarrier_long","Land_Pneu","Land_Pneu","","Misc_TyreHeapEP1","DSHKM_TK_INS_EP1"]};
// Default
default {["ZavoraAnim","Land_CncBlock","RoadBarrier_long","Land_arrows_desk_L","Land_arrows_desk_R","Land_fortified_nest_small","Fort_RazorWire","M2StaticMG"]};
};


// Place Gate
if !(_list select 0 == "") then {
_bg1 = _list select 0 createVehicle (_roadpos modelToWorld [0,7,0]);
_bg1 setDir ((direction _roadpos) -360);
};

// Place Blocking Element (concrete, tyres etc)
if !(_list select 1 == "") then {
_cb1 = _list select 1 createVehicle (_roadpos modelToWorld [5,6,0]);
_cb1 setDir ((direction _roadpos) -360);
_cb2 = _list select 1  createVehicle (_roadpos modelToWorld [10,6,0]);
_cb2 setDir ((direction _roadpos) -360);
_cb3 = _list select 1  createVehicle (_roadpos modelToWorld [-5,6,0]);
_cb3 setDir ((direction _roadpos) -360);
_cb4 = _list select 1 createVehicle (_roadpos modelToWorld [-10,6,0]);
_cb4 setDir ((direction _roadpos) -360);
};

// Place Road Barriers
if !(_list select 2 == "") then {
_rb1 = _list select 2 createVehicle (_roadpos modelToWorld [5,5,0]);
_rb1 setDir ((direction _roadpos) -360);
_rb2 = _list select 2 createVehicle (_roadpos modelToWorld [10,5,0]);
_rb2 setDir ((direction _roadpos) -360);
_rb3 = _list select 2 createVehicle (_roadpos modelToWorld [-5,5,0]);
_rb3 setDir ((direction _roadpos) -360);
_rb4 = _list select 2 createVehicle (_roadpos modelToWorld [-10,5,0]);
_rb4 setDir ((direction _roadpos) -360);
};

// Place Guides

if !(_list select 3 == "") then {
_s1 = _list select 3 createVehicle (_roadpos2 modelToWorld [-4,0,0]);
_s1 setDir ((direction _roadpos) -90);
_s2 = _list select 3 createVehicle (_roadpos modelToWorld [-4,4,0]);
_s2 setDir ((direction _roadpos) -90);
_s3 = _list select 4 createVehicle (_roadpos modelToWorld [3,4,0]);
_s3 setDir ((direction _roadpos) -270);
_s4 = _list select 4 createVehicle (_roadpos modelToWorld [3,0,0]);
_s4 setDir ((direction _roadpos) -270);
_s5 = _list select 4 createVehicle (_roadpos modelToWorld [3,-4,0]);
_s5 setDir ((direction _roadpos) -270);
_s6 = _list select 4 createVehicle (_roadpos modelToWorld [0,-7,0]);
_s6 setDir ((direction _roadpos) -180);
};

// Place Fortification

if !(_list select 5 == "") then {
_b1 = _list select 5 createVehicle (_roadpos modelToWorld [10,-6,0]);
_b1 setDir ((direction _roadpos) -180);
_b2 = _list select 5 createVehicle (_roadpos modelToWorld [-10,-6,0]);
_b2 setDir ((direction _roadpos) -180);
};

// Place Wire

if !(_list select 6 == "") then {
_rw1 = _list select 6 createVehicle (_roadpos modelToWorld [10,8,0]);
_rw1 setDir ((direction _roadpos) -360);
_rw2 = _list select 6 createVehicle (_roadpos modelToWorld [-10,8,0]);
_rw2 setDir ((direction _roadpos) -360);
};

// Place Weapon

if !(_list select 7 == "") then {
_sg1 = _list select 7 createVehicle (_roadpos modelToWorld [10,-7,0]);
_sg1 setDir ((direction _roadpos) -360);
_sg2 = _list select 7 createVehicle (_roadpos modelToWorld [-10,-7,0]);
_sg2 setDir ((direction _roadpos) -360);
};

_triggeram1 = createTrigger["EmptyDetector",[getPos _roadpos select 0,getPos _roadpos select 1,0]];
_triggeram1 setTriggerArea [150,150,0,false];
_triggeram1 setTriggerActivation ["EAST","NOT PRESENT",false];
_triggeram1 setTriggerTimeout [5,5,5,true];
_triggeram1 setTriggerStatements ["this", "psdelete=true; publicvariable 'psdelete'",""];


waituntil{psdelete};


Share this post


Link to post
Share on other sites

Store all objects within an array, delete them when needed, f.e.:

_allObjects = [];

//Create Object and Store it for use later on
_myObj = blablabla;
_allObjects set [count _allObjects, _myObj];


//Delete All Objects when needed
{
  deleteVehicle _x;
} forEach _allObjects;

Share this post


Link to post
Share on other sites

So would my Objects be, as that does not work , or am I missing something ?

_myObj = _bg1,_cb1,_cb2,_cb3,_cb4,_rb1,_rb2,_rb3,_rb4_s1,_s2,_s3,_s4,_s5,_s6,_b1,_b2,_rw1,_rw2,_sg1,_sg2;

Share this post


Link to post
Share on other sites

One way with how your script is already written would be (neokika's suggestion is totally valid too),

At the ,moment the variables which contain the reference to the objects you are creating are only defined within the scope of the if statements they are in.

If you placed this out side of the if statements at the start of your script which will mean the variables exist at the level where you want to later delete them;

[url="http://community.bistudio.com/wiki/private"]private[/url] ["_bg1","_cb1","_cb2","_cb3","_cb4","_rb1","_rb2","_rb3","_rb4_s1","_s2","_s3","_s4","_s5","_s6","_b1","_b2","_rw1","_rw2","_sg1","_sg2"];

You could place this after your waituntil statement.

{
deletevehicle _x;
}foreach[_bg1,_cb1,_cb2,_cb3,_cb4,_rb1,_rb2,_rb3,_rb4_s1,_s2,_s3,_s4,_s5,_s6,_b1,_b2,_rw1,_rw2,_sg1,_sg2];

Nice road block by the way :)

Hope this helps Blake

Share this post


Link to post
Share on other sites

Many thanks for the Explanation of private variable and scope , I forgot that and i think that is why i have been having issues elsewhere in my scripts !

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  

×