Sscanf2 question.
#1

This is a multiple parameter command, and i have some trouble with her:

pawn Код:
cmd(pm, playerid, params[]) // PM Command.
{
    if(IsPlayerConnected(playerid))
    {
        new pl, opt[16], msg[64], str[128];
        if(sscanf(params, "s[16]", opt))
        {
            SendClientMessage(playerid,COLOR_HELP,"USAGE: /pm [location/message/stop]");
            return 1;
        }
        if(!strcmp(opt, "location", true)) // Sends a player your location.
        {
            if(sscanf(params, "s[16]u", opt, pl))
            {
                SendClientMessage(playerid,COLOR_HELP,"USAGE: /pm [location/message/stop] [ID/PartOfName]");
                return 1;
            }
            if(GetPVarInt(pl, "StopPM") == 0)
            {
                new Float:px, Float:py, Float:pz;
                GetPlayerPos(playerid, px, py, pz);
                SetPlayerCheckpoint(pl, px, py, pz, 5.0);
                format(str, sizeof(str), "PM: %s has PM-ed you his location. He's marked RED on your radar.", PlayerName[playerid]);
                SendClientMessage(pl, COLOR_RED, str);
            }
            else { SendClientMessage(playerid,COLOR_ERROR,"ERROR: This person has blocked PM's."); }
        }
        else if(!strcmp(opt, "message", true)) // Sends a message to a player.
        {
            if(sscanf(params, "s[16]us[64]", opt, pl, msg))
            {
                SendClientMessage(playerid,COLOR_HELP,"USAGE: /pm [location/message/stop] [ID/PartOfName] [message]");
                return 1;
            }
            if(GetPVarInt(pl, "StopPM") == 0)
            {
                format(str, sizeof(str), "PM: %s says: %s.", PlayerName[playerid], msg);
                SendClientMessage(pl, COLOR_RED, str);
            }
            else { SendClientMessage(playerid,COLOR_ERROR,"ERROR: This person has blocked PM's."); }
        }
        else if(!strcmp(opt, "stop", true)) // Stops PM's from being send to you.
        {
            if(GetPVarInt(playerid, "StopPM") > 0) { SetPVarInt(playerid, "StopPM", 0); SendClientMessage(playerid,COLOR_GREEN,"INFO: PM's Activated."); }
            else { SetPVarInt(playerid, "StopPM", 1); SendClientMessage(playerid,COLOR_RED,"INFO: PM's Blocked."); }
        }
    }
    return 1;
}
It should be like this:

You type: /pm location whizion - and it sends your location to a player named whizion (but it doesn't do nothing).

You type: /pm message whizion yo sup' - and it sends a PM with text: you sup' to a player named whizion (but it doesn't do nothing).

The only thing that's working is /pm stop, but that's really useless if other things don't work.

What am i doing wrong here? Please help, thanks.
Reply
#2

Dude, Lol you made a mistake it should be like this:

if (sscanf(params, "sus", opt, pl, msg))

Something like that D:
Reply
#3

Quote:
Originally Posted by Porsche911
Посмотреть сообщение
Dude, Lol you made a mistake it should be like this:

if (sscanf(params, "sus", opt, pl, msg))

Something like that D:
Nope, sscanf 1.0 was like that, this is 2.0, and that wouldn't change a thing.
Reply
#4

Use strcmp to detect which one there saying.
Reply
#5

Quote:
Originally Posted by Steven82
Посмотреть сообщение
Use strcmp to detect which one there saying.
Well, i am:

if(!strcmp(opt, "location", true))
else if(!strcmp(opt, "message", true))
else if(!strcmp(opt, "message", true))

Reply
#6

Quote:
Originally Posted by Whizion
Посмотреть сообщение
Well, i am:

if(!strcmp(opt, "location", true))
else if(!strcmp(opt, "message", true))
else if(!strcmp(opt, "message", true))

Why are you using ! instead of doing that just make the code like this.

pawn Код:
if(strcmp(opt, "location", true))
{
 // Code Here
 return // your code
}
Reply
#7

Quote:
Originally Posted by Steven82
Посмотреть сообщение
Why are you using ! instead of doing that just make the code like this.

pawn Код:
if(strcmp(opt, "location", true))
{
 // Code Here
 return // your code
}
That ! check's if the strings are the same, because strcmp returns 0 if their are.

And there's nothing wrong with strcmp or with any of my code, it's something with sscanf.

I guess i'll wait for someone who knows it a little better...

But thanks for trying.
Reply
#8

Bumpy.
Reply
#9

Sry for another bump, page 2 (nobody looks at here) and i really need this fast.

I have free time now but i can't continue my work unless i figure out this.

So please help, thanks.
Reply
#10

Quote:
Originally Posted by Steven82
Посмотреть сообщение
Use strcmp to detect which one there saying.
sscanf 2.0 is a replacement for strcmp (among many other functions), because It's faster.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)