SA-MP Forums Archive
Help with Command to supply all cars - 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: Help with Command to supply all cars (/showthread.php?tid=577148)



Help with Command to supply all cars - LucasDias - 09.06.2015

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;




Re: Help with Command to supply all cars - Konstantinos - 09.06.2015

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.


Re: Help with Command to supply all cars - LucasDias - 09.06.2015

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;




Re: Help with Command to supply all cars - Richie© - 09.06.2015

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


Re: Help with Command to supply all cars - Konstantinos - 09.06.2015

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).


Re: Help with Command to supply all cars - JaydenJason - 09.06.2015

Код:
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


Re: Help with Command to supply all cars - Threshold - 09.06.2015

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.


Re: Help with Command to supply all cars - LucasDias - 09.06.2015

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!


Re: Help with Command to supply all cars - Threshold - 09.06.2015

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