Timer that deletes a vehicle (no driver) problem...
#1

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;
}
Reply
#2

Use SetVehicleToRespawn(veh); instead of DestroyVehicle(veh);
Reply
#3

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)