SA-MP Forums Archive
Command for all players help - 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 for all players help (/showthread.php?tid=626434)



Command for all players help - EmrysXD - 15.01.2017

Why this command not giving players money?
sorry for bad code. im newbie. seomeone fix the code for me please.

Код:
	if(strcmp(cmd, "/giveallmoney", true) == 0)
	{
		if (PlayerInfo[playerid][pAdmin] >= 8)
		{
			tmp = strtok(cmdtext, idx);
			new amount = strval(tmp);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /giveallmoney [amount]");
				return 1;
			}
			for(new i = 0; i < MAX_PLAYERS; i ++)
			{
   				if(IsPlayerConnected(i))
   				{
			    	GivePlayerMoney(i, amount);
					format(string, sizeof(string), "~y~+$~w~%d",amount);
					GameTextForAll(string, 5000, 1);
					format(string, sizeof(string), "• %s Has given $%d to all players •",sendername,amount);
					SendClientMessageToAll(YELLOW,string);
				}
			}
		}
		return 1;
		
	}



Re: Command for all players help - Lordzy - 15.01.2017

First of all, I suggest you to use any command processor like zcmd than creating commands using strcmp. It will be slow when you have a lot of commands. Here, you're using strtok which is also you shouldn't be using now since sscanf (which is better) can be used instead. Anyway - I guess the "idx" reference should be reset before using it on strtok. You can also debug your code to know which part of the command is probably going wrong.


Re: Command for all players help - BiosMarcel - 15.01.2017

Here take this as an example, i have replaced the for loop with a foreach loop (https://github.com/karimcambridge/SAMP-foreach - standalone version download, but it is also included in YSI) the command parameter stuff using sscanf (https://github.com/maddinat0r/sscanf/releases) and the command itself using a command processor, since most comman processor have the same syntax, you can use most likely every command processor you want, just search for one, as for me i am using this one: https://sampforum.blast.hk/showthread.php?tid=608474

PHP код:
CMD:giveallmoney(playerid, params[])
{
    if (
PlayerInfo[playerid][pAdmin] >= 8)
    {
        new 
ammount;
        
        if(
sscanf(params, "d", amount)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /giveallmoney [amount]");
        foreach(new 
i : Player)
        {
            
GivePlayerMoney(i, amount);
            
format(string, sizeof(string), "~y~+$~w~%d",amount);
            
GameTextForAll(string, 5000, 1);
            
format(string, sizeof(string), "• %s Has given $%d to all players •",sendername,amount);
            
SendClientMessageToAll(YELLOW,string);
        }
    }
    return 
1;    
} 



Re: Command for all players help - SyS - 15.01.2017

Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
Here take this as an example, i have replaced the for loop with a foreach loop (https://github.com/karimcambridge/SAMP-foreach - standalone version download, but it is also included in YSI) the command parameter stuff using sscanf (https://github.com/maddinat0r/sscanf/releases) and the command itself using a command processor, since most comman processor have the same syntax, you can use most likely every command processor you want, just search for one, as for me i am using this one: https://sampforum.blast.hk/showthread.php?tid=608474

PHP код:
CMD:giveallmoney(playerid, params[])
{
    if (
PlayerInfo[playerid][pAdmin] >= 8)
    {
        new 
ammount;
        
        if(
sscanf(params, "d", amount)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /giveallmoney [amount]");
        foreach(new 
i : Player)
        {
            
GivePlayerMoney(i, amount);
            
format(string, sizeof(string), "~y~+$~w~%d",amount);
            
GameTextForAll(string, 5000, 1);
            
format(string, sizeof(string), "• %s Has given $%d to all players •",sendername,amount);
            
SendClientMessageToAll(YELLOW,string);
        }
    }
    return 
1;    
} 
That formatting and sending message should be outside the loop


Re: Command for all players help - RyderX - 15.01.2017

Ermys, use ZCMD Command processor as Marcel said, and here is the command:

PHP код:
CMD:giveallmoney(playerid, params[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 8)
    {
        new 
amount;
        if(
sscanf(params, "d", amount)) return SendClientMessage(playerid, 0xF8F8F8FFF, "Usage:/giveallmoney [amount]");
        {
            for(new 
i = 0; i < MAX_PLAYERS; i++)
            {
                if(
IsPlayerConnected(i))
                {
                    new 
str[128];
                    new 
AdminName[MAX_PLAYER_NAME];

                    
GetPlayerName(playerid, AdminName, sizeof(AdminName));

                      
format(str, sizeof(str), "[{B4B5B7}Admin{FF6347}]{B4B5B7}'%s has give $%d to all player .", AdminName, amount);
                    
SendClientMessageToAll(0xf0f0f0f0, str);

                    
GivePlayerMoney(i,amount);
                }
            }
        }
    }
    else return 
SendClientMessage(playerid, 0xf8f8f8fff, "[{B4B5B7}System{FF6347}]: {B4B5B7}You aren't authorized to use this command.");
    return 
1;
} 



Re: Command for all players help - BiosMarcel - 15.01.2017

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
That formatting and sending message should be outside the loop
Indeed, i didn't think so far, ty

PHP код:
CMD:giveallmoney(playerid, params[])
{
    if (
PlayerInfo[playerid][pAdmin] >= 8)
    {
        new 
ammount;
        if(
sscanf(params, "d", amount)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /giveallmoney [amount]");
            
        foreach(new 
i : Player)
        {
            
GivePlayerMoney(i, amount);
        }
        
        new 
string[37];
        
format(string, sizeof(string), "~y~+$~w~%d", amount);
        
GameTextForAll(string, 5000, 1);
        
format(string, sizeof(string), "• %s Has given $%d to all players •", sendername, amount);
        
SendClientMessageToAll(YELLOW, string);
    }
    return 
1;    
}