Jump to content
Sign in to follow this  
ArmAriffic

can a group name be a local var?

Recommended Posts

1. I have a code here

//_nul = ["nubakeast", nubakcenter, 0, east] execVM "RespawnTest2\respawnThis.sqf";
//_nul = ["nubakwest", nubakcenter, 0, west] execVM "RespawnTest2\respawnThis.sqf";

//Prepare the local variables
private ["_grp1","_Side","_wp","_grp2","_RSMkr","_WPPos","_RS","_EastUnits","_WestUnits","_UnitSpawnE","_UnitSpawnW","_wp2"];

_RSMkr = _this select 0;
_WPPos = _this select 1;
_RS = _this select 2;
_Side = _this select 3;

//The units that can spawn, selected at random
_EastUnits = ["MOL_Soldier_Medic", "MOL_Soldier_Engineer", "MOL_Soldier_Rifleman", "MOL_Soldier_GL", "MOL_Soldier_Marksman", "MOL_Soldier_AR", "MOL_Soldier_MG", "MOL_Soldier_AT", "MOL_Soldier_LAT"];
_WestUnits = ["AFR_Soldier_GL", "AFR_Soldier_Rifleman", "AFR_Soldier_Engineer", "AFR_Soldier_Medic", "AFR_Soldier_MG", "AFR_Soldier_AT", "AFR_Rifleman", "AFR_Medic"];

//If EAST is called, then an east guy will spawn, same with west
//East
if (_Side == EAST) then {
  _UnitSpawnE = _EastUnits select floor(random count _EastUnits);
  _grp1 = createGroup east;

  if (_RS == 1) then { _UnitSpawnE createUnit [getMarkerPos _RSMkr, _grp1, "_nul = [this, 5, _RSMkr, _WPPos, EAST] execVM ""RespawnTest2\deleteUnit.sqf""; this allowFleeing 0;"]; } else { _UnitSpawnE createUnit [getMarkerPos _RSMkr, _grp1, "this allowFleeing 0;_nul = [this, 5] execVM ""RespawnTest2\deleteUnitNR.sqf"";"]; };

  _wp = _grp1 addWaypoint [position _WPPOS, 1];
  [_grp1, 1] setWaypointCombatMode "RED";
  [_grp1, 1] setWaypointBehaviour "AWARE";
  [_grp1, 1] setWaypointPosition [position _WPPOS, 1];
  [_grp1, 1] setWaypointType "SAD";
  _grp1 setCurrentWaypoint [_grp1, 1];
};

//West
if (_Side == WEST) then {
  _UnitSpawnW = _WestUnits select floor(random count _WestUnits);
  _grp2 = createGroup west;

  if (_RS == 1) then { _UnitSpawnW createUnit [getMarkerPos _RSMkr, _grp2, "_nul = [this, 5, _RSMkr, _WPPos, WEST] execVM ""RespawnTest2\deleteUnit.sqf""; this allowFleeing 0;"]; } else { _UnitSpawnW createUnit [getMarkerPos _RSMkr, _grp2, "this allowFleeing 0;_nul = [this, 5] execVM ""RespawnTest2\deleteUnitNR.sqf"";"]; };

  _wp2 = _grp2 addWaypoint [position _WPPOS, 1];
  [_grp2, 1] setWaypointCombatMode "RED";
  [_grp2, 1] setWaypointBehaviour "AWARE";
  [_grp2, 1] setWaypointPosition [position _WPPOS, 1];
  [_grp2, 1] setWaypointType "SAD";
  _grp2 setCurrentWaypoint [_grp2, 1];
};

It works great but I want to know if creating a group called _grp1 or _grp2 will make the group name a local variable.

2. Will the group be automatically deleted when the unit is killed or deleted with

(delete the unit)

private ["_DA","_DD","_Side","_nearguys"];
_DA = _this select 0;
_DD = _this select 1;
_Side = _this select 2;

_nearguys = nearestObjects [_DA,["Man"],_DD]; 
{if (side _x == _Side) then { deleteVehicle _x; }} forEach _nearguys;

(respawn the unit when it is killed)

 
private ["_Delay","_nul","_ThisUnit","_RSMKR","_WPPOS","_Side"];

_ThisUnit = _this select 0;
_Delay = _this select 1;
_RSMkr = _this select 2;
_WPPOS = _this select 3;
_Side = _this select 4;

//Wait untill the unit dies
waitUntil {not alive _ThisUnit};

sleep _Delay;

//Delete him
deleteVehicle _ThisUnit;

sleep 1;

//Respawn him
_nul = [_RSMkr, _WPPOS, 1, _Side] execVM "RespawnTest2\respawnThis.sqf"; 

Edited by ArmAriffic
t-t-t-typo

Share this post


Link to post
Share on other sites

Well a group could be referred to only as a local variable, but it wouldn't be a "name" exactly just a "group".

You could just add in a waitUntil checking for groups to be empty in the same script. My silly traffic script does that. Spawns things as local variables and cleans them up all from the same script. If you're going to refer to the group externally, from another script or something, you'll want to look into giving it a global name.

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  

×