Destroying all vehicles doesn't work.
#1

The title is pretty much self explanatory, I can't get this command to work from 4 days so far. The code is below, I have no idea what was done wrong, but any help is appreciated, like..really. I have tried pretty much anything I can think of and there is no effect. My goal is to delete any car in the server that is spawned, the gamemode is loading without any cars, but players leave vehicles everywhere because of a command which allows them to spawn them. I don't want to restrict that command to anything, so yeah.
PHP код:
    if (strcmp("/destroycars"cmdtexttrue10) == 0)
       {
        if(
PlayerInfo[playerid][pAdmin] >= 3)
        {
            new 
name2[MAX_PLAYER_NAME];
            for(new 
i=1;i<=MAX_VEHICLES;i++)
            {
            
DestroyVehicle(i);
            
GetPlayerName(playeridname2sizeof(name2));
               
format(gstrsizeof(gstr), "The almighty admin %s has destroyed all vehicles"name2);
            
SendClientMessageToAll(COLOR_SPAWNgstr);
            return 
1;
            }
        }
    } 
Reply
#2

PHP код:
    if (strcmp("/destroycars"cmdtexttrue10) == 0
       { 
        if(
PlayerInfo[playerid][pAdmin] >= 3
        { 
            new 
name2[MAX_PLAYER_NAME]; 
            for(new 
1GetVehiclePoolSize();<= ji++) 
            { 
                
DestroyVehicle(i); 
            } 
            
GetPlayerName(playeridname2sizeof(name2)); 
            
format(gstrsizeof(gstr), "The almighty admin %s has destroyed all vehicles"name2); 
            
SendClientMessageToAll(COLOR_SPAWNgstr); 
        } 
    } 
You put the return 1 inside the loop thats means the loops stop after the first caris deleted. Here you go, i fix your multiple message and GetPlayerName for every car thats on server....
Reply
#3

Vehicle ID 0 is a valid vehicle id so change that initial variable to 0 (Turn out i was wrong. It actually start with id 1)
Also move that message away from the loop so it doesn't get called for every vehicle destroyed.

I think that return might be stopping the work I am not sure tho. So move it out of the loop too.

Here is a fixed version
PHP код:
if (strcmp("/destroycars"cmdtexttrue10) == 0

    if(
PlayerInfo[playerid][pAdmin] >= 3
    { 
        new 
name2[MAX_PLAYER_NAME]; 
        for(new 
i;i<MAX_VEHICLES;i++) //You don't need lesser than or equal (<=) too just lesser (<) is enough
        

            
DestroyVehicle(i); 
        } 
           
GetPlayerName(playeridname2sizeof(name2)); 
        
format(gstrsizeof(gstr), "The almighty admin %s has destroyed all vehicles"name2); 
        
SendClientMessageToAll(COLOR_SPAWNgstr); 
        return 
1
    }
 } 
EDIT: Corrected my mistake
Reply
#4

Quote:
Originally Posted by FailerZ
Посмотреть сообщение
Vehicle ID 0 is a valid vehicle id
No, it's not.
Reply
#5

May god be with you all, it got fixed. I can't believe what a silly mistake it was, thanks a lot.
Reply
#6

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
No, it's not.
Yeah. My bad i thought it was same as player ids and pickups.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)