sscanf, again
#1

hello everyone,

can someone tell me what im doing wrong? it keeps saying the usage thing
pawn Код:
if (strcmp("/report", cmdtext, true, 100) == 0)
    {
        new player[24],
            reason[100];
        if(sscanf(cmdtext[100], "{s}us[100]", player, reason)) return SendClientMessage(playerid, 0x00ffaa, "USAGE: /report <player> <reason>");
        {
            for(new i=0;i<MAX_PLAYERS;i++)
            {
                if(IsPlayerAdmin(i))
                {
                    new string[100],
                        playername[30],
                        string2[100];
                    GetPlayerName(playerid, playername, sizeof(playername));
                    format(string, sizeof(string), "Player: %s Reported Player: %u for the reason: %s.", playername, player, reason);
                    SendClientMessage(i, 0x333300, string);
                    format(string2, sizeof(string2), "Your report about: %u with reason %s has been send to the admins.", player, reason);
                    SendClientMessage(playerid, 0x333300, string2);
                }
            }
        }
        return 1;
    }
there will be no wrong awnseres exept "You must use dcmd, zcmd, ycmd" or whatever casue this is only a test.

Greetings,

sansko
Reply
#2

Do you even have the variables new player,reason ?
Reply
#3

Quote:
Originally Posted by Forbidden
Посмотреть сообщение
Do you even have the variables new player,reason ?
updated, added the whole cmd instead of only the sscanf part
Reply
#4

String needs a length too.

pawn Код:
if(sscanf(cmdtext, "us[100]", player, reason))
Reply
#5

First of all, do you use the plugin or the stock version? I recommend using the plugin. Furthermore, you're passing the entire string to sscanf, including the command itself. So for example /mycommand someparam 5 will get passed as a whole to sscanf.

To solve it, you can do this:
pawn Код:
if(sscanf(cmdtext[7], "us", player, reason)) // 7 being the length of the command
Or if you use the plugin (this might not work, not tested):
pawn Код:
if(sscanf(cmdtext, "{s}us", player, reason))
Reply
#6

i combined some of the codes together but i still sont works, and BTW i use the plugin
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
(this might not work, not tested)
Try different things, not just combine them.

Use "us[100]" and see.
Reply
#8

Quote:
Originally Posted by iPLEOMAX
Посмотреть сообщение
Try different things, not just combine them.

Use "us[100]" and see.
um yes i tried that but its not realy working
Reply
#9

Well, How about switching to ZCMD?
I never got it working with strcmp. -_-

And there were lot of faults in your code..

pawn Код:
CMD:report( playerid, cmdtext[] ) //easier and BETTER.
{
        new player, reason[64];
        if(sscanf(cmdtext, "is[64]", player, reason)) return SendClientMessage(playerid, 0x00ffaa, "USAGE: /report <player> <reason>");
        {
            new playername[MAX_PLAYER_NAME], reportedname[MAX_PLAYER_NAME];
            GetPlayerName(playerid, playername, sizeof(playername)); GetPlayerName(player, reportedname, sizeof(reportedname));
       
            new string[128];
            format(string, sizeof(string), "Your report about: %s with reason %s has been send to the admins.", reportedname, reason);
            SendClientMessage(playerid, 0x333300, string);
           
            format(string, sizeof(string), "Player: %s Reported Player: %s for the reason: %s.", playername, reportedname, reason);
            for(new i=0;i<MAX_PLAYERS;i++) { if(IsPlayerAdmin(i)) { SendClientMessage(i, 0x333300, string); } }
        }
        return 1;
    }
Reply
#10

dont matter i already solved it. and i am using y-cmd already, this was just to test for someone else
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)