Command to destroy all vehicles in the server
#1

I am trying to make a command to destroy all vehicles in the server, exept vehicles with players in. The code i've got at the moment just destroys vehicles with players in!! Can anyone point me in the right direction?

pawn Код:
#include a_samp
#include zcmd

COMMAND:respawn(playerid, params[])
{
    for(new players = 0; players < MAX_PLAYERS; players++) //loop through players
    for(new i = 0; i < MAX_VEHICLES; i++) //loop through vehicles
    if(IsPlayerInVehicle(players, i) == 1)
    {
        //don't destroy this vehicle?
    }
    return 1;
}
Reply
#2

Might be more efficient doing this, i'm not sure it works but i think it should. Should be more efficient than using nested loops.
pawn Код:
new bool:bVehicleOccupied[ MAX_VEHICLES ];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( newstate == PLAYER_STATE_DRIVER )
    {
        new
            vehicleid = GetPlayerVehicleID( playerid );
        bVehicleOccupied[ vehicleid ] = true;
        SetPVarInt( playerid, "currentvehicle", vehicleid );
    }
    else if( oldstate == PLAYER_STATE_DRIVER )
    {
        bVehicleOccupied[ GetPVarInt( playerid, "currentvehicle") ] = false;
        DeletePVar( playerid, "currentvehicle");
    }
    return 1;
}
In your command
pawn Код:
for( new i; i < MAX_VEHICLES; i++ )
{
    if( !bVehicleOccupied[ i ] )
        SetVehicleToRespawn( i );
}
Reply
#3

Well this is something i had in my script..
Just do what you have to do with it to make it work with your script(Converting and whatnot)..
Reply
#4

Thanks to both of you for your help, problem solved!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)