SA-MP Forums Archive
Timer that deletes a vehicle (no driver) problem... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Timer that deletes a vehicle (no driver) problem... (/showthread.php?tid=325638)



Timer that deletes a vehicle (no driver) problem... - Reklez - 14.03.2012

i have made Vehicle Updating delete system to avoid respawning vehicles back from their spawned position
suddenly i notice that my server vehicles are also delete too. how to avoid to do that? i use
create vehicle native function for /v and for /acar. here is the code.

pawn Код:
new DeleteUpdate;
DeleteUpdate = SetTimer("DeleteVehicles", 21000, true);

forward DeleteVehicles();
public DeleteVehicles()
{
    for(new veh = 0; veh < MAX_VEHICLES; veh++)
    {
        if(!VehicleOccupied(veh))
        {
            DestroyVehicle(veh);
        }
    }
    return 1;
}

stock VehicleOccupied(vehicleid)
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerInVehicle(i,vehicleid)) return 1;
    }
    return 0;
}



Re: Timer that deletes a vehicle (no driver) problem... - Daddy Yankee - 14.03.2012

Use SetVehicleToRespawn(veh); instead of DestroyVehicle(veh);


Re: Timer that deletes a vehicle (no driver) problem... - HighPitchedVoice - 14.03.2012

pawn Код:
DestroyVehicle(veh);
to
pawn Код:
SetVehicleToRespawn(veh);



Re: Timer that deletes a vehicle (no driver) problem... - TTJJ - 14.03.2012

Hi Reklez,

That function will indeed delete every vehicle in the server if it's un-occupied. If you want to avoid it deleting certain vehicles you will need to make a function that will tell the script that vehicle x should not be deleted. For instance:

pawn Код:
//Top Of Script
new do_not_delete[MAX_VEHICLES];

public OnGameModeInit()
{
    do_not_delete[0] = CreateVehicle...
}

public DeleteVehicles()
{
    for(new veh = 0; veh < MAX_VEHICLES; veh++)
    {
        if(!VehicleOccupied(veh) && CanDeleteVehicle(veh))
        {
            DestroyVehicle(veh);
        }
    }
    return 1;
}

public CanDeleteVehicle(vehicleid)
{

    for(new i = 0; i < sizeof(do_not_delete); i ++)
    {

         if(vehicleid == do_not_delete[i]) return false;

    }
    return true;
}
I hope that made sense..

Cheers,

TJ