how to respawn all cars
#4

Quickly written, should do the job

pawn Код:
stock RespawnAllVehicles()
{
    for (new i=0;i<MAX_VEHICLES;i++)
    {
        if (CanVehicleBeRespawned(i)) // If this returns 1 (no factors preventing the vehicle from being respawned as stated in "CanVehicleBeRespawned"), the vehicle will respawn
        {
            SetVehicleToRespawn(i);
        }
    }
}

stock CanVehicleBeRespawned(vehicleid)
{
    new Float:X,Float:Y,Float:Z;
    GetVehiclePos(vehicleid, X,Y,Z);
    if (X == 0.0 && Y == 0.0 && Z == 0.0)
    {
        //Vehicle not created, returning 0
        return 0;
    }
   
    for (new i=0;i<MAX_PLAYERS;i++)
    {
        if (IsPlayerConnected(i))
        {
            if (GetPlayerVehicleID(i) == vehicleid) return 0; // Someone is inside the vehicle, returning 0
        }
    }
   
    return 1; // Vehicle is ready to be respawned, returning 1 :)
}
Now just use RespawnAllVehicles to respawn them to their original positions

EDIT: If you need a timer for it, here:

pawn Код:
forward RespawnVehicles();

public OnGameModeInit()
{
    SetTimer("RespawnVehicles", 300000, true);
}


public RespawnVehicles()
{
    RespawnAllVehicles();
    SendClientMessageToAll(-1, "All unoccupied vehicles successfully respawned");
}
Reply


Messages In This Thread
how to respawn all cars - by RiChArD_A - 24.02.2013, 19:47
Re: how to respawn all cars - by PabloDiCostanzo - 24.02.2013, 19:57
Respuesta: Re: how to respawn all cars - by RiChArD_A - 24.02.2013, 20:01
Re: how to respawn all cars - by Jakku - 24.02.2013, 20:08
Re: how to respawn all cars - by tyler12 - 24.02.2013, 20:10
Re: how to respawn all cars - by Jakku - 24.02.2013, 20:17
Respuesta: Re: how to respawn all cars - by RiChArD_A - 24.02.2013, 20:17
Re: how to respawn all cars - by Salim_Karaja - 24.02.2013, 20:19
Respuesta: Re: how to respawn all cars - by RiChArD_A - 24.02.2013, 20:20
Re: Respuesta: Re: how to respawn all cars - by Jakku - 24.02.2013, 20:21

Forum Jump:


Users browsing this thread: 1 Guest(s)