Jump to content
Sign in to follow this  
iceman77

Deleting a vehicles variable name

Recommended Posts

I need to create a vehicle & assign it a name. Once it's been destroyed I need to delete the vehicles variable name so I can create a new vehicle with the same name. How do I do this? So far, it only gets past the marker color check but doesn't create the vehicle no matter what I try.

_veh = createVehicle ["HMMWV_DES_EP1", GetMarkerPos "Z1_V2", [], 0, "NONE"];
WaitUntil {!isNull _veh};
_Name="CarZ1";
_Veh SetVehicleVarName _Name;
_Veh Call Compile Format ["%1=_This",_Name];

VSpawnLoop = 
{

  While {True} Do 
  {


      If (!Alive CarZ1) Then
      {   
          DeleteVehicle CarZ1;

         [color=#ff0000] //Carz1 = ObjNull;
          //Carz1 = Nil;
          //SetVariable [Carz1,Nil];
          //SetVariable ["Carz1",Nil];[/color]


             If (MarkerColor "Zone1M" == "ColorGreen") Then
             {  
                 _Veh = createVehicle ["HMMWV_DES_EP1", GetMarkerPos "Z1_V1", [], 0, "NONE"];
                 WaitUntil {!isNull _veh};
                 _Name="CarZ1";
                 _Veh SetVehicleVarName _Name;
                 _Veh Call Compile Format ["%1=_This",_Name];
             };
      };

 };
   sleep 1;

};

sleep 0.05;
[]Spawn VSpawnLoop;

Edited by Iceman77

Share this post


Link to post
Share on other sites

Do clients need to be aware of this variable?

Share this post


Link to post
Share on other sites

No, just the server. So it can keep track of 1) if vehicles alive 2) What color a marker is so it can spawn appropriate sides vehicle.

Share this post


Link to post
Share on other sites

So it should respawn whenever the marker color returns to colorgreen?

Share this post


Link to post
Share on other sites

When it dies, it should "respawn" (create new rather) only if the marker in question is green. If the marker is red, then it will spawn an equivalent opfor vehicle instead (which isn't shown in the snippet)

Share this post


Link to post
Share on other sites

Just assign it something random, like this.

_vcl setVehicleVarName format["Dead_Vehicle_%1", round (random 100000)];

Share this post


Link to post
Share on other sites

i actually have a script that spawns vehicle, gives it a name and when it dies the script has no issue creating a new one with same name. even used triggers to test if alive or not. i dont use a "waituntil" condition though.

Share this post


Link to post
Share on other sites
i actually have a script that spawns vehicle, gives it a name and when it dies the script has no issue creating a new one with same name. even used triggers to test if alive or not. i dont use a "waituntil" condition though.

Cool, could you post it please?

Share this post


Link to post
Share on other sites

I just ran the code and it works as intended. I destroyed the car that was created at marker Z1_V2 and it respawned at marker Z1_V1.

The only thing I can think of is that you do not have a marker named Z1_V1 and that the marker's name in the while loop was a typo where you meant Z1_V2 instead of Z1_V1.

Describe what you are trying to do with the script and I can probably give you better help.

Edited by Jonescrusher

Share this post


Link to post
Share on other sites

i actually use this on a unit on map with a name since im changing player model, but just naming & creating a different vehicle in the script should'nt be any different i wouldnt think..

private ["_ace", "_unit", "_uniform", "_weapons", "_items", "_magazines", "_currentWpn", "_hasruck", "_ruckMags", "_ruckWeaps", "_weaponback", "_success", "_muzzles", "_type", "_posunit", "_VarName", "_newunit", "_group"];
titleText ["", "BLACK FADED"];	// Black Screen
sleep 0.5;

_civs = ["Assistant","Citizen1","Citizen2","Citizen3","Citizen4","Rocker1","Rocker2","Rocker3","Rocker4","Woodlander1","Woodlander2","Woodlander3","Woodlander4","Worker1","Worker2","Worker3","Haris_Press_EP1","CIV_EuroMan01_EP1","CIV_EuroMan02_EP1","TK_CIV_Worker01_EP1","TK_CIV_Worker02_EP1"];

// Variables
_unit = player;		
_posunit = getPos _unit;	
_setEnemy = getPos _enemyPos;
_VarName = (vehicleVarName _unit);	
_newunit = _civs select floor(random(count _civs));

_unit setPos [0,0,0];	// teleport the old unit to [0,0,0]
_enemyPos setPos [0,5,0];

// Create new unit
_eastCenter = createCenter east;
_dummyGroupEast = createGroup east;
_enemyUnit = _dummyGroupEast createUnit ["TK_Soldier_EP1",_setEnemy, [], 0, "COLONEL"]; 

_group 		= createGroup west;
_model = _group createUnit [_newunit, _posunit, [], 0, "NONE"];
[_model] joinSilent _dummyGroupEast;

removeAllWeapons _model;
removeBackpack _model;
removeAllItems _model;

//Make New Unit Playable
addSwitchableUnit _model;
setPlayable _model;
selectPlayer _model;
[_model] joinSilent grpNull;	

//Clear and delete old Unit
removeAllWeapons _unit;
{_unit removeMagazine _x;} forEach  magazines _unit;

deleteVehicle _unit;

//Clear and delete enemy Unit
removeAllWeapons _enemyUnit;
{_enemyUnit removeMagazine _x;} forEach  magazines _enemyUnit;

deleteVehicle _enemyUnit;

//Get Muzzle
_currentWpn = currentWeapon player;
_muzzles = getArray(configFile >> "cfgWeapons" >> _currentWpn >> "muzzles");
if (count _muzzles > 1) then {
	_currentWpn = currentMuzzle player;
};

// Select the primaryWeapon	
if(_currentWpn != "") then {_model selectWeapon _currentWpn;};

player disableConversation true;

// Set name of unit
_model SetVehicleVarName _VarName;
_model call Compile Format ["%1= player ; PublicVariable ""%1""",_VarName];

titleText [" ", "BLACK IN"];  // Black In








Share this post


Link to post
Share on other sites
I just ran the code and it works as intended. I destroyed the car that was created at marker Z1_V2 and it respawned at marker Z1_V1.

The only thing I can think of is that you do not have a marker named Z1_V1 and that the marker's name in the while loop was a typo where you meant Z1_V2 instead of Z1_V1.

Oops. FPDR Anyhow, I'm just going to use MPkilled EH as suggested and showed by cuel & it's the better solution I think. But, to answer your question, I'm making a capture & hold / conquest game mode. So, vehicle spawns based on marker color (in essence the side) of any given capture point. There will be either 3 or 5 capture points in any given scenario. Here's what I've so far (for 1 capture point). It's not l33t short code, but it does what I need it to so far. It's the way I code :p The long way... If anyone, wants to help me shorten these functions by passing values than feel free to send me a PM :). As I couldn't get the Zone_FNC to work properly by passing values to it.

Z1EastCap = 10;
Z1WestCap = 10;

EastScore = 0;
WestScore = 0;
EAST_ZONE1 = False;
WEST_ZONE1 = False;
NEUTRAL_ZONE1 = False;

SoundedCaptured = 
{
 SoundzCaptured = "captured";
 publicVariable "Soundz";
 PlaySound SoundzCaptured; 
};

SoundedContested = 
{
 SoundzContested = "contested";
 publicVariable "SoundzContested";
 PlaySound SoundzContested;
};

SoundedLost = 
{
 SoundzLost = "LostZone";
 publicVariable "SoundzLost";
 PlaySound SoundzLost;
};

WestScoreIntel = 
{
 WestScorez = "";
 publicVariable "WestScorez";
 WestScore = WestScore + 1;
 Player SideChat Format ["%1", WestScore];   
};


WVehicles =
{


    Switch (MarkerColor "Zone1M") Do
    {
       case "ColorGreen":
       {
           _veh = createVehicle ["M1A2_US_TUSK_MG_EP1", getMarkerPos "Z1_V1", [], 0, "NONE"];
           _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V1SpawnLoop}];

           _veh = createVehicle ["HMMWV_DES_EP1", getMarkerPos "Z1_V2", [], 0, "NONE"];
           _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V2SpawnLoop}];

           _veh = createVehicle ["AH6J_EP1", getMarkerPos "Z1_V3", [], 0, "NONE"];
           _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V3SpawnLoop}];
       };

       case "ColorRed":
       {   
           _veh = createVehicle ["T90", getMarkerPos "Z1_V1", [], 0, "NONE"];
           _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V1SpawnLoop}];

           _veh = createVehicle ["SUV_TK_EP1", getMarkerPos "Z1_V2", [], 0, "NONE"];
           _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V2SpawnLoop}];

           _veh = createVehicle ["UH1H_TK_EP1", getMarkerPos "Z1_V3", [], 0, "NONE"];
           _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V3SpawnLoop}];
       };
    };


};

Z1_V1SpawnLoop = 
{
   if (!isServer) exitWith {};
   if (count _this > 0) then 
       {
          sleep 5;
      (_this select 0) call {deleteVehicle _this};
          Sleep 1;
   };

           WaitUntil {MarkerColor "Zone1M" == "ColorGreen" || MarkerColor "Zone1M" == "ColorRed"};

         If (markerColor "Zone1M" == "ColorGreen") Then
         {
       _veh = createVehicle ["M1A2_US_TUSK_MG_EP1", getMarkerPos "Z1_V1", [], 0, "NONE"];
       _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V1SpawnLoop}];
             };

             If (markerColor "Zone1M" == "ColorRed") Then
         {
       _veh = createVehicle ["T90", getMarkerPos "Z1_V1", [], 0, "NONE"];
       _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V1SpawnLoop}];
             };



};

Z1_V2SpawnLoop = 
{
   if (!isServer) exitWith {};
   if (count _this > 0) then 
       {
      sleep 5;
      (_this select 0) call {deleteVehicle _this};
          Sleep 1;
   };

           WaitUntil {MarkerColor "Zone1M" == "ColorGreen" || MarkerColor "Zone1M" == "ColorRed"};

         If (markerColor "Zone1M" == "ColorGreen") Then
         {
       _veh = createVehicle ["HMMWV_DES_EP1", getMarkerPos "Z1_V2", [], 0, "NONE"];
       _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V2SpawnLoop}];
             };

             If (markerColor "Zone1M" == "ColorRed") Then
         {
       _veh = createVehicle ["SUV_TK_EP1", getMarkerPos "Z1_V2", [], 0, "NONE"];
       _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V2SpawnLoop}];
             };



};

Z1_V3SpawnLoop = 
{
   if (!isServer) exitWith {};
   if (count _this > 0) then 
       {
      sleep 5;
      (_this select 0) call {deleteVehicle _this};
          Sleep 1;
   };

           WaitUntil {MarkerColor "Zone1M" == "ColorGreen" || MarkerColor "Zone1M" == "ColorRed"};

         If (markerColor "Zone1M" == "ColorGreen") Then
         {
       _veh = createVehicle ["AH6J_EP1", getMarkerPos "Z1_V3", [], 0, "NONE"];
       _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V3SpawnLoop}];
             };

             If (markerColor "Zone1M" == "ColorRed") Then
         {
       _veh = createVehicle ["UH1H_TK_EP1", getMarkerPos "Z1_V3", [], 0, "NONE"];
       _veh addMPEventHandler ["MPKilled",{_this spawn Z1_V3SpawnLoop}];
             };



};

"Soundz" addPublicVariableEventHandler {PlaySound Soundz;};
"SoundzContested" addPublicVariableEventHandler {PlaySound SoundzContested;}; 
"SoundzLost" addPublicVariableEventHandler {PlaySound Soundzlost;};
"WestScorez" addPublicVariableEventHandler {WestScore = WestScore + 1;};



ZONE1_FNC = 
{
   If (!IsServer) ExitWith {};
   While {True} Do 
   {
       If (({Alive _x && (Side _x) == West} Count List Zone1) > ({Alive _x && (Side _x) == East} Count List Zone1) && (Z1WestCap > 0)) Then 
       {
         Z1WestCap = Z1WestCap - 1;
         If (Z1EastCap < 10) Then {Z1EastCap = Z1EastCap + 1;};
       };

       If (({Alive _x && (Side _x) == East} Count List Zone1) > ({Alive _x && (Side _x) == West} Count List Zone1) && (Z1EastCap > 0)) Then 
       {
         Z1EastCap = Z1EastCap - 1;
         If (Z1WestCap < 10) Then {Z1WestCap = Z1WestCap + 1;};
       };

       If (({Alive _x && (Side _x) == West} Count List Zone1) == 0 && ({Alive _x && (Side _x) == East} Count List Zone1) == 0 && (Z1EastCap != 0) && (Z1WestCap != 0)) Then
       {
           If (Z1WestCap == 10) ExitWith {}; 
           Z1WestCap = 10;
           Z1EastCap = 10;
       };

       If (({Alive _x && (Side _x) == West} Count List Zone1 > 0) && ({Alive _x && (Side _x) == East} Count List Zone1 > 0))  Then 
       {
         If (MarkerColor "Zone1M" != "ColorYellow") Then {"Zone1M" SetMarkerColor "ColorYellow";PublicVariable "Zone1M";};
         If (!NEUTRAL_ZONE1) Then {NEUTRAL_ZONE1 = True;PublicVariable "NEUTRAL_ZONE1";{nul = [] call SoundedContested;} ForEach PlayableUnits;};
         If (EAST_ZONE1) Then {EAST_ZONE1 = False;PublicVariable "EAST_ZONE1";};
         If (WEST_ZONE1) Then {WEST_ZONE1 = False;PublicVariable "WEST_ZONE1";};
       };

       If ((Z1WestCap < 1) && ({Alive _x && (Side _x) == East} Count List Zone1 == 0))  Then   
       {

         If (MarkerColor "Zone1M" != "ColorGreen") Then {"Zone1M" SetMarkerColor "ColorGreen";PublicVariable "Zone1M";};     
         If (NEUTRAL_ZONE1) Then {NEUTRAL_ZONE1 = False;PublicVariable "NEUTRAL_ZONE1";};
         If (EAST_ZONE1) Then {EAST_ZONE1 = False;PublicVariable "EAST_ZONE1";};
         If (!WEST_ZONE1) Then 
            {
               WEST_ZONE1 = True;
               PublicVariable "WEST_ZONE1";
               {If (Side _x == West) Then {_nul = [] call SoundedCaptured;}} ForEach PlayableUnits;
               {If (Side _x == East) Then {_nul = [] call SoundedLost;}} ForEach PlayableUnits;
               If (IsNil "vSpawned") Then {vSpawned=0;[]Spawn Wvehicles;};
            };

            []Call WestScoreIntel;

       };

       If ((Z1EastCap < 1) && ({Alive _x && (Side _x) == West} Count List Zone1 == 0)) Then 
       {
         If (MarkerColor "Zone1M" != "ColorRed") Then {"Zone1M" SetMarkerColor "ColorRed";PublicVariable "Zone1M";};  
         If (NEUTRAL_ZONE1) Then {NEUTRAL_ZONE1 = False;PublicVariable "NEUTRAL_ZONE1";};
         If (!EAST_ZONE1) Then 
            {
              EAST_ZONE1 = True;
              PublicVariable "EAST_ZONE1";
              {If (Side _x == East) Then {_nul = [] call SoundedCaptured;}} ForEach PlayableUnits;
              {If (Side _x == West) Then {_nul = [] call SoundedLost;}} ForEach PlayableUnits;
              If (IsNil "vSpawned") Then {vSpawned=0;[]Spawn Wvehicles;};
            };

         If (WEST_ZONE1) Then {WEST_ZONE1 = False;PublicVariable "WEST_ZONE1";};
         EastScore = EastScore + 1;
       };

         Player GlobalChat Format ["%1", Z1WestCap];
         Sleep 1;
   };



};

Ofcourse the vehicles wont spawn/respawn instantly, but just for testing.

Edited by Iceman77

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  

×