Jump to content
DanJohn

Deleting a Vehicle Once another one is spawned

Recommended Posts

I have created a Virtual Vehicle Spawner But I want the old vehicle to delete once the new vehicle has been spawned. Right now i can spawn however much vehicles i want. I have tried to add in my own check but it doesnt work. If i change (count Old_Vehicles_Spawned > 1) to (count Old_Vehicles_Spawned > 0) i am able to spawn in a vehicle that deletes straight away so im not sure why (count Old_Vehicles_Spawned > 1). Any help would be appreciated.

Code:

Spoiler

Old_Vehicles_Spawned = [];
    _VehicleSelected = lbCurSel 1;
    _classVeh = lbData[1, _VehicleSelected];
    _emptyPos = position player findEmptyPosition [5,50, _classVeh]; //Spawn A Vehicle 5-50M around player
    if (count _emptyPosDir == 0) exitWith {hint "Vehicle Cant be Spawned Here"; };

    _veh = createVehicle [_classVeh, _emptyPos, [], 0, ""];
    _veh setDir (getDir player);
    _veh setVehicleAmmo 0;
    _veh setVehicleAmmoDef 0;
    clearWeaponCargoGlobal _veh;
    clearMagazineCargoGlobal _veh;
    clearItemCargoGlobal _veh;
    clearBackpackCargoGlobal _veh;
    player moveInAny _veh;
    //if (_Old_Vehicle_Spawned isEqualTo "") exitWith {closeDialog 18002;}

    Old_Vehicles_Spawned pushBack _veh;

    if (count Old_Vehicles_Spawned > 1) then
    {
        deleteVehicle (Old_Vehicles_Spawned select 0);
        [Old_Vehicles_Spawned] call BIS_fnc_arrayShift;
    };

    closeDialog 18002;

 

 

 

Share this post


Link to post
Share on other sites

I only just realized this after trying to figure out the problem for the last week that every time the function was called I was resetting the array by adding this to the top

Old_Vehicles_Spawned = [];

Share this post


Link to post
Share on other sites
if (isNil "Old_Vehicles_Spawned") then
{
	Old_Vehicles_Spawned = [];
};

This will only define it if it doesn't exist in first place.

  • Like 1

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

×