Command to destroy all vehicles in the server - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Command to destroy all vehicles in the server (
/showthread.php?tid=245844)
(Solved)Command to destroy all vehicles in the server -
linuxthefish - 02.04.2011
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;
}
Re: Command to destroy all vehicles in the server -
iggy1 - 02.04.2011
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 );
}
Re: Command to destroy all vehicles in the server -
s0nic - 02.04.2011
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)..
Re: Command to destroy all vehicles in the server -
linuxthefish - 02.04.2011
Thanks to both of you for your help, problem solved!