Help with Command to supply all cars
#1

My command does not supply vehicles of the server, someone help me ?

PHP код:
CMD:fillcars(playerid,params[])
{
        if( 
PlayerInfo[playerid][pAdmin] == || PlayerInfo[playerid][pMod] == 1  || PlayerInfo[playerid][pDono] == 1)
    {
        new 
quantity;
        if(
sscanf(params"i"quantity)) return SendClientMessage(playeridred"Use: /fillcars [quantity]");
        if(
quantity|| quantity100) return SendClientMessage(playeridred"| ERROR | The maximum amount of gas is 100!");
        for ( new 
MAX_VEHICLES ++)
        {
            new 
stringgas[256];
            
carfuel[c] += quantity;
            
format(stringgassizeof(stringgas), "AdmCmd: You supplied % d liter on all cars of San Andreas"quantity);
            
SendClientMessage(playeridbluestringgas);
            return 
1;
        }
    }
    else
    {
        
SendClientMessage(playerid,red,"| ERROR | You don't have permission!");
    }
    return 
1;

Reply
#2

You return 1 in the loop and it breaks. Remove it and also declare the string before the loop and format/send the message after the loop.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You return 1 in the loop and it breaks. Remove it and also declare the string before the loop and format/send the message after the loop.
this way?

PHP код:
CMD:fillcars(playerid,params[]) 

        if( 
PlayerInfo[playerid][pAdmin] == || PlayerInfo[playerid][pMod] == 1  || PlayerInfo[playerid][pDono] == 1
              return 
SendClientMessage(playerid,red,"| ERROR | You don't have permission!"); 
        new 
quantity
        if(
sscanf(params"i"quantity)) return SendClientMessage(playeridred"Use: /fillcars [quantity]"); 
        if(
quantity|| quantity100) return SendClientMessage(playeridred"| ERROR | The maximum amount of gas is 100!"); 
        for ( new 
MAX_VEHICLES ++) 
        { 
            new 
stringgas[256]; 
            
carfuel[c] += quantity
            
format(stringgassizeof(stringgas), "AdmCmd: You supplied % d liter on all cars of San Andreas"quantity); 
            
SendClientMessage(playeridbluestringgas); 
        } 
        return 
1;

Reply
#4

Try it..you willget 2000 messages in your screen since its inside the loop.
Reply
#5

Yes, that way the loop will continue until c reaches MAX_VEHICLES-1.

Though as I told you before declaring a string with size of 256 2k times and also sending the message 2k times is not that good.
pawn Код:
new stringgas[60];
for ( new c = 0 ; c < MAX_VEHICLES ; c ++)  
{  
    carfuel[c] += quantity;
}
format(stringgas, sizeof(stringgas), "AdmCmd: You supplied %d liter on all cars of San Andreas", quantity);  
SendClientMessage(playerid, blue, stringgas);
Also vehicle IDs start from 1 so you may start the loop from 1 as well (unless you use index 0).
Reply
#6

Код:
CMD:fillcars(playerid,params[])
{
	if( PlayerInfo[playerid][pAdmin] < 2 || PlayerInfo[playerid][pMod] < 2 || PlayerInfo[playerid][pDono] < 2)
	return SendClientMessage(playerid,red,"| ERROR | You don't have permission!");
	new quantity, stringgas[130];
	if(sscanf(params, "i", quantity)) return SendClientMessage(playerid, red, "Use: /fillcars [quantity]");
	if(quantity< 0 || quantity> 100) return SendClientMessage(playerid, red, "| ERROR | The maximum amount of gas is 100!");
	format(stringgas, sizeof(stringgas), "AdmCmd: You supplied % d liter on all cars of San Andreas", quantity);
	SendClientMessage(playerid, blue, stringgas);
	for ( new c = 1 ; c < MAX_VEHICLES ; c ++)
	{
		carfuel[c] += quantity;
	}
	return 1;
}
Fixed the if(PlayerInfo.. etc, your code makes players that are not admin able to use this command as well
Reply
#7

pawn Код:
CMD:fillcars(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] < 2 && PlayerInfo[playerid][pMod] < 2 && PlayerInfo[playerid][pDono] < 2)
        return SendClientMessage(playerid,red,"| ERROR | You don't have permission!");

    new quantity;
    if(sscanf(params, "i", quantity)) return SendClientMessage(playerid, red, "Use: /fillcars [quantity]");
    if(!(0 < quantity <= 100)) return SendClientMessage(playerid, red, "| ERROR | The maximum amount of gas is 100!");
    new stringgas[68];
    format(stringgas, sizeof(stringgas), "AdmCmd: You supplied %d litres of fuel on all cars in San Andreas", quantity);
    SendClientMessage(playerid, blue, stringgas);
    for(new c = 1; c < MAX_VEHICLES; c++) carfuel[c] += quantity;
    return 1;
}
Normally I would subtract 1 when using a vehicle ID in an array, but I doubt you do this in your script. If I was to implement it here, you would have to change your entire script to fit the same way. So I'll just leave it how it is for now. This is just a small improvement on JaydenJason's code.
Reply
#8

the problem is not the admin, the problem is that not supplies the vehicles, else works okay, thank you for warning me about the string , and my level of admin, moderator , and helper is equal to 1, then > 2 would cause a bug

@EDIT
I understand the " < 2 " sorry xD...
the command is still without supply the Map vehicles!
Reply
#9

Then the problem is not from the command... it lies somewhere else in your script.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)