SA-MP Forums Archive
command to delete all cars 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)
+--- Thread: command to delete all cars in the server (/showthread.php?tid=284982)



command to delete all cars in the server - boyan96 - 21.09.2011

how i can make command to delete all cars in the server


Re: command to delete all cars in the server - IstuntmanI - 21.09.2011

Code:
if( strcmp( cmdtext, "/deleteallcars", true ) == 0 )
{
    for( new veh; veh < MAX_VEHICLES; veh ++ )
    {
        DestroyVehicle( veh );
    }
    return 1;
}
* https://sampwiki.blast.hk/wiki/DestroyVehicle


Re: command to delete all cars in the server - Zh3r0 - 21.09.2011

Quote:
Originally Posted by costel_nistor96
View Post
Code:
if( strcmp( cmdtext, "/deleteallcars", true ) == 0 )
{
    for( new veh; veh < MAX_VEHICLES; veh ++ )
    {
        DestroyVehicle( veh );
    }
    return 1;
}
* https://sampwiki.blast.hk/wiki/DestroyVehicle
You forgot about INVALID_VEHICLE_ID to check if it's a valid id.


Re: command to delete all cars in the server - IstuntmanI - 21.09.2011

Quote:
Originally Posted by Zh3r0
View Post
You forgot about INVALID_VEHICLE_ID to check if it's a valid id.
I wasn't sure if I have to put INVALID_VEHICLE_ID in a MAX_VEHICLES loop :\ . It's not like
pawn Code:
if( 0 != INVALID_VEHICLE_ID )
{
    DestroyVehicle( 0 );
}
if( 1 != INVALID_VEHICLE_ID )
{
    DestroyVehicle( 1 );
}
// etc
if( 1999 != INVALID_VEHICLE_ID )
{
    DestroyVehicle( 1999 );
}
?

0 ... 1999 are valid vehicle ID's, but we are not sure if respective vehicle has been created, GetVehiclePos would be good:

Code:
if( strcmp( cmdtext, "/deleteallcars", true ) == 0 )
{
    new Float:X, Float:Y, Float:Z;
    for( new veh; veh < MAX_VEHICLES; veh ++ )
    {
        GetVehiclePos( veh, X, Y, Z );
        if( X == 0.00 && Y == 0.00 && Z == 00 )
            continue;

        DestroyVehicle( veh );
    }
    return 1;
}



Re: command to delete all cars in the server - =WoR=Varth - 22.09.2011

https://sampwiki.blast.hk/wiki/GetVehicleModel
There's no need to check it as he want just to remove all of them.


Re: command to delete all cars in the server - Charlos - 25.08.2013

Hmmmm.... Where should i put the code? In which part in Pawno- Gamemode!



Re: command to delete all cars in the server - Vanter - 25.08.2013

under OnPlayerCommandText


Re: command to delete all cars in the server - Charlos - 26.08.2013

When I compile the file I got 3 errors!

F:\SenjoritaGaming\gamemodes\SanjoritaGaming.pwn(2 675) : error 010: invalid function or declaration
F:\SenjoritaGaming\gamemodes\SanjoritaGaming.pwn(2 677) : error 010: invalid function or declaration
F:\SenjoritaGaming\gamemodes\SanjoritaGaming.pwn(2 681) : error 010: invalid function or declaration
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


3 Errors.


Re: command to delete all cars in the server - Skribblez - 26.08.2013

Code:
F:\SenjoritaGaming\gamemodes\SanjoritaGaming.pwn(2 675) : error 010: invalid function or declaration
F:\SenjoritaGaming\gamemodes\SanjoritaGaming.pwn(2 677) : error 010: invalid function or declaration
F:\SenjoritaGaming\gamemodes\SanjoritaGaming.pwn(2 681) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 Copyright © 1997-2006, ITB CompuPhase
Could you post the lines where there are errors?


Re: command to delete all cars in the server - ProjectMan - 26.08.2013

Try this:

pawn Code:
if( strcmp( cmdtext, "/deleteallcars", true ) == 0 )
{
    for( new veh; veh < MAX_VEHICLES; veh ++ )
    {
        if ( veh != INVALID_VEHICLE_ID )
        {
        DestroyVehicle( veh );
        }
    }
    return 1;
}
Make sure you put it under OnPlayerCommandText like this:

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
     if( strcmp( cmdtext, "/deleteallcars", true ) == 0 )
     {
         for( new veh; veh < MAX_VEHICLES; veh ++ )
         {
             if ( veh != INVALID_VEHICLE_ID )
             {
             DestroyVehicle( veh );
             }
         }
         return 1;
     }



    return 0;
}