command to delete all cars in the server
#1

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

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

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.
Reply
#4

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

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

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

under OnPlayerCommandText
Reply
#8

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.
Reply
#9

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?
Reply
#10

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


Forum Jump:


Users browsing this thread: 2 Guest(s)