SA-MP Forums Archive
Admin command doesn't work - 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: Admin command doesn't work (/showthread.php?tid=606316)



Admin command doesn't work - TayFunCZE - 02.05.2016

Hello, I want to set PVarInt to player in game, but command doesn't work, help me please
PHP код:
CMD:setpvar(playeridparams[])
{
    if(
IsPlayerAnAdmin(playerid,3))
    {
        new 
toplayeridamountstring[64];
        if (!
sscanf(params"uci"toplayeridstringamount))
        {
              if (
toplayerid != INVALID_PLAYER_ID)
              {
                   new 
message[200];
                   
SetPVarInt(toplayerid,string,amount);
              }
              else 
SCM(playerid,RED,"Bad ID");
        }
        else 
SCM(playerid,RED,"INFO: /setpvar <playerid> <PVarInt> <number>");
    }
    else 
SCM(playerid,RED,"You are not admin!");
    return 
1;




Re: Admin command doesn't work - Godey - 02.05.2016

OK, the core problem here is:
Код:
if (!sscanf(params, "uci", toplayerid, string, amount))
you don't use a '!'(NOT) in a ssanf, which is not allowing the command to continue further

So try:
Код:
if (sscanf(params, "uci", toplayerid, string, amount))
PS: correct me if I'm wrong


Re: Admin command doesn't work - TayFunCZE - 02.05.2016

OK, but still doesn't work, now it doesn't says this:
PHP код:
INFO: /setpvar <playerid> <PVarInt> <number



Re: Admin command doesn't work - Darkwood17 - 02.05.2016

You didn't set the size of the string in sscanf. It should be:
Код:
if (sscanf(params, "usi", toplayerid, string[64], amount))
Here is an optimized version of your code:
Код:
CMD:setpvar(playerid, params[]) 
{ 
    if(IsPlayerAnAdmin(playerid,3)) 
    { 
        new toplayerid, amount, string[64]; 
        if (sscanf(params, "usi", toplayerid, string[64], amount)) SCM(playerid,RED,"INFO: /setpvar <playerid> <PVarInt> <number>"); 
        if (toplayerid == INVALID_PLAYER_ID) return SCM(playerid,RED,"Bad ID"); 
        new message[200]; 
        SetPVarInt(toplayerid,string,amount);
    } 
    else SCM(playerid,RED,"You are not admin!"); 
    return 1; 
}



Re: Admin command doesn't work - Godey - 02.05.2016

Can you explain what do you mean by, 'doesn't work'?


Re: Admin command doesn't work - Konstantinos - 02.05.2016

Quote:
Originally Posted by Godey
Посмотреть сообщение
OK, the core problem here is:
Код:
if (!sscanf(params, "uci", toplayerid, string, amount))
you don't use a '!'(NOT) in a ssanf, which is not allowing the command to continue further

So try:
Код:
if (sscanf(params, "uci", toplayerid, string, amount))
PS: correct me if I'm wrong
sscanf returns 0 on success so it is correct.

The problem is that "c" is used for characters and the argument shouldn't be a string. If you want a string use "s" specifier and add the size as Darkwood17 mentioned. Having the string as not last parameter allows you to use a word only though. In order to use space you'll have to move it last.


Re: Admin command doesn't work - TayFunCZE - 02.05.2016

OK, thank you guys, now it's working fine, thank you so much