Command not working as intended
#1

I'm having problems using sscanf again, this command doesn't work. If you type the command properly (i.e. /makedonator 23 bronze) it doesn't send the messages nor does it set the pDonator, it just sets it as 0.

pawn Код:
CMD:makedonator(playerid, params[])
{
    if (PlayerData[playerid][pAdmin] < 5)
        return SendErrorMessage(playerid, "You don't have permission to use this command!");

    static
        userid,
        type[16],
        message[128];
       
    if (sscanf(params, "u", userid))
        return SendSyntaxMessage(playerid, "/makedonator [playerid/name] [bronze/silver/gold/none]");

    if (userid == INVALID_PLAYER_ID)
        return SendErrorMessage(playerid, "You have specified an invalid player.");

    if (strcmp(type, "bronze", true))
    {
        format(message, sizeof(message), "You have sed &s's donator rank to Bronze.", ReturnName(userid, 0));
        SendClientMessage(playerid, COLOR_RED, message);
        format(message, sizeof(message), "Your donator rank has been set to Bronze by %s.", ReturnName(playerid, 0));
        SendClientMessage(userid, COLOR_RED, message);
        PlayerData[userid][pDonator] = 1;
    }
    else if (strcmp(type, "silver", true))
    {
        format(message, sizeof(message), "You have sed &s's donator rank to Silver.", ReturnName(userid, 0));
        SendClientMessage(playerid, COLOR_RED, message);
        format(message, sizeof(message), "Your donator rank has been set to Silver by %s.", ReturnName(playerid, 0));
        SendClientMessage(userid, COLOR_RED, message);
        PlayerData[userid][pDonator] = 2;
    }
    else if (strcmp(type, "gold", true))
    {
        format(message, sizeof(message), "You have sed &s's donator rank to Gold.", ReturnName(userid, 0));
        SendClientMessage(playerid, COLOR_RED, message);
        format(message, sizeof(message), "Your donator rank has been set to Gold by %s.", ReturnName(playerid, 0));
        SendClientMessage(userid, COLOR_RED, message);
        PlayerData[userid][pDonator] = 3;
    }
    return 1;
}
Reply
#2

Hello,

PHP код:
CMD:makedonator(playeridparams[])
{
    if (
PlayerData[playerid][pAdmin] < 5)
        return 
SendErrorMessage(playerid"You don't have permission to use this command!");
    static
        
userid,
        
type[16],
        
message[128];
    if (
sscanf(params"us[16]"userid,type))
        return 
SendSyntaxMessage(playerid"/makedonator [playerid/name] [bronze/silver/gold/none]");
    if (
userid == INVALID_PLAYER_ID)
        return 
SendErrorMessage(playerid"You have specified an invalid player.");
    if (!
strcmp(param"bronze"true6))
    {
        
format(messagesizeof(message), "You have sed &s's donator rank to Bronze."ReturnName(userid0));
        
SendClientMessage(playeridCOLOR_REDmessage);
        
format(messagesizeof(message), "Your donator rank has been set to Bronze by %s."ReturnName(playerid0));
        
SendClientMessage(useridCOLOR_REDmessage);
        
PlayerData[userid][pDonator] = 1;
    }
    if (!
strcmp(param"silver"true6))
    {
        
format(messagesizeof(message), "You have sed &s's donator rank to Silver."ReturnName(userid0));
        
SendClientMessage(playeridCOLOR_REDmessage);
        
format(messagesizeof(message), "Your donator rank has been set to Silver by %s."ReturnName(playerid0));
        
SendClientMessage(useridCOLOR_REDmessage);
        
PlayerData[userid][pDonator] = 2;
    }
    if (!
strcmp(param"gold"true4))
    {
        
format(messagesizeof(message), "You have sed &s's donator rank to Gold."ReturnName(userid0));
        
SendClientMessage(playeridCOLOR_REDmessage);
        
format(messagesizeof(message), "Your donator rank has been set to Gold by %s."ReturnName(playerid0));
        
SendClientMessage(useridCOLOR_REDmessage);
        
PlayerData[userid][pDonator] = 3;
    }
    return 
1;

Reply
#3

Quote:
Originally Posted by Golf
Посмотреть сообщение
Hello,

PHP код:
CMD:makedonator(playeridparams[])
{
    if (
PlayerData[playerid][pAdmin] < 5)
        return 
SendErrorMessage(playerid"You don't have permission to use this command!");
    static
        
userid,
        
type[16],
        
message[128];
    if (
sscanf(params"us[16]"userid,type))
        return 
SendSyntaxMessage(playerid"/makedonator [playerid/name] [bronze/silver/gold/none]");
    if (
userid == INVALID_PLAYER_ID)
        return 
SendErrorMessage(playerid"You have specified an invalid player.");
    if (!
strcmp(param"bronze"true6))
    {
        
format(messagesizeof(message), "You have sed &s's donator rank to Bronze."ReturnName(userid0));
        
SendClientMessage(playeridCOLOR_REDmessage);
        
format(messagesizeof(message), "Your donator rank has been set to Bronze by %s."ReturnName(playerid0));
        
SendClientMessage(useridCOLOR_REDmessage);
        
PlayerData[userid][pDonator] = 1;
    }
    if (!
strcmp(param"silver"true6))
    {
        
format(messagesizeof(message), "You have sed &s's donator rank to Silver."ReturnName(userid0));
        
SendClientMessage(playeridCOLOR_REDmessage);
        
format(messagesizeof(message), "Your donator rank has been set to Silver by %s."ReturnName(playerid0));
        
SendClientMessage(useridCOLOR_REDmessage);
        
PlayerData[userid][pDonator] = 2;
    }
    if (!
strcmp(param"gold"true4))
    {
        
format(messagesizeof(message), "You have sed &s's donator rank to Gold."ReturnName(userid0));
        
SendClientMessage(playeridCOLOR_REDmessage);
        
format(messagesizeof(message), "Your donator rank has been set to Gold by %s."ReturnName(playerid0));
        
SendClientMessage(useridCOLOR_REDmessage);
        
PlayerData[userid][pDonator] = 3;
    }
    return 
1;

What did I do wrong?
Reply
#4

Glad you asked. The person above your post left you over to the guess-what-you-did-wrong part.

CMD:makedonator requires two parameters. In your case: the targetid and the type of donator. You defined everything correctly till the sscanf function.
pawn Код:
(sscanf(params, "u", userid))
You 'told' sscanf that there is 1 parameter to look out for: targetid.
Since no 'type' parameter was defined in your sscanf function, it will ignore all the strcmp functions underneath returning 1 for the command after inserting the target's id.

We define the second parameter (the 'type' parameter) in the following code:
pawn Код:
(sscanf(params, "us[16]", userid, type))
And we define a size to the 's' specifier since 'type' is a string.
Reply
#5

Quote:
Originally Posted by Golf
Посмотреть сообщение
Hello,

PHP код:
CMD:makedonator(playeridparams[])
{
    if (
PlayerData[playerid][pAdmin] < 5)
        return 
SendErrorMessage(playerid"You don't have permission to use this command!");
    static
        
userid,
        
type[16],
        
message[128];
    if (
sscanf(params"us[16]"userid,type))
        return 
SendSyntaxMessage(playerid"/makedonator [playerid/name] [bronze/silver/gold/none]");
    if (
userid == INVALID_PLAYER_ID)
        return 
SendErrorMessage(playerid"You have specified an invalid player.");
    if (!
strcmp(param"bronze"true6))
    {
        
format(messagesizeof(message), "You have sed &s's donator rank to Bronze."ReturnName(userid0));
        
SendClientMessage(playeridCOLOR_REDmessage);
        
format(messagesizeof(message), "Your donator rank has been set to Bronze by %s."ReturnName(playerid0));
        
SendClientMessage(useridCOLOR_REDmessage);
        
PlayerData[userid][pDonator] = 1;
    }
    if (!
strcmp(param"silver"true6))
    {
        
format(messagesizeof(message), "You have sed &s's donator rank to Silver."ReturnName(userid0));
        
SendClientMessage(playeridCOLOR_REDmessage);
        
format(messagesizeof(message), "Your donator rank has been set to Silver by %s."ReturnName(playerid0));
        
SendClientMessage(useridCOLOR_REDmessage);
        
PlayerData[userid][pDonator] = 2;
    }
    if (!
strcmp(param"gold"true4))
    {
        
format(messagesizeof(message), "You have sed &s's donator rank to Gold."ReturnName(userid0));
        
SendClientMessage(playeridCOLOR_REDmessage);
        
format(messagesizeof(message), "Your donator rank has been set to Gold by %s."ReturnName(playerid0));
        
SendClientMessage(useridCOLOR_REDmessage);
        
PlayerData[userid][pDonator] = 3;
    }
    return 
1;

Quote:
Originally Posted by Bible
Посмотреть сообщение
Glad you asked. The person above your post left you over to the guess-what-you-did-wrong part.

CMD:makedonator requires two parameters. In your case: the targetid and the type of donator. You defined everything correctly till the sscanf function.
pawn Код:
(sscanf(params, "u", userid))
You 'told' sscanf that there is 1 parameter to look out for: targetid.
Since no 'type' parameter was defined in your sscanf function, it will ignore all the strcmp functions underneath returning 1 for the command after inserting the target's id.

We define the second parameter (the 'type' parameter) in the following code:
pawn Код:
(sscanf(params, "us[16]", userid, type))
And we define a size to the 's' specifier since 'type' is a string.
Thank you.

I have just tested the command but it still isn't working for some reason, you don't get the message nor does the playerdata update.
Reply
#6

Of course not. You are comparing (strcmp) the params (userid AND type) with a name. That's not what you are aiming for. You want to compare only the 'type' parameter.

Example code:
pawn Код:
if(!strcmp(type, "Bronze", true, 7))
What this means is: "If the parameter 'type' is equal to 'Bronze', execute following code:"
Reply
#7

Quote:
Originally Posted by Bible
Посмотреть сообщение
Of course not. You are comparing (strcmp) the params (userid AND type) with a name. That's not what you are aiming for. You want to compare only the 'type' parameter.

Example code:
pawn Код:
if(!strcmp(type, "Bronze", true, 7))
What this means is: "If the parameter 'type' is equal to 'Bronze', execute following code:"
That's what Golf has done in his above post, is it not? I have tested his code and it still doesn't work.
Reply
#8

Quote:
Originally Posted by Luke_James
Посмотреть сообщение
That's what Golf has done in his above post, is it not? I have tested his code and it still doesn't work.
He didn't. Have you even tried changing any of his code with the example code that I provided in my previous reply?

His code:
pawn Код:
if(!strcmp(params, "Bronze", true, 7))
Example code:
pawn Код:
if(!strcmp(type, "Bronze", true, 7))
As you can see, after the opening bracket of the strcmp function, he compared the params (userid AND type) with a string. What you want is compare the 'type' parameter to a string and see if it is equal to each other and that is what I did in the example code.
Reply
#9

Quote:
Originally Posted by Bible
Посмотреть сообщение
He didn't. Have you even tried changing any of his code with the example code that I provided in my previous reply?

His code:
pawn Код:
if(!strcmp(params, "Bronze", true, 7))
Example code:
pawn Код:
if(!strcmp(type, "Bronze", true, 7))
As you can see, after the opening bracket of the strcmp function, he compared the params (userid AND type) with a string. What you want is compare the 'type' parameter to a string and see if it is equal to each other and that is what I did in the example code.
Oh sorry, I understand now, thank you. What does the number 7 do?
Reply
#10

Quote:
Originally Posted by Luke_James
Посмотреть сообщение
Oh sorry, I understand now, thank you. What does the number 7 do?
It's an optional parameter of the strcmp function. It tells the strcmp function to how many characters it has to check.

https://sampwiki.blast.hk/wiki/Strcmp
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)