Admin command doesn't work
#1

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;

Reply
#2

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
Reply
#3

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

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; 
}
Reply
#5

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

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.
Reply
#7

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


Forum Jump:


Users browsing this thread: 1 Guest(s)