SSCANF help.
#1

I'm trying to make a report cmd like this:
the player can do
/report [text] or /report [playerid] [report text]

I made this:

pawn Код:
CMD:report(playerid, params[])
{
    new id, text[128];
    if(!sscanf(params, "s[128]", text) && sscanf(params, "us[128]", id, text))
    {
        Reported{playerid} = true;
        format(ReportText[playerid], 128, "%s", params);
        ReportPlayer[playerid] = INVALID_PLAYER_ID;
        SCMEx(playerid, COLOR_CYAN, "You have sent a report: %s", params);
        format(mstr, sizeof(mstr), "The player %s[ID:%d] has reported: %s.", GetNameEx(playerid), playerid, params);
        AdminsMSG(COLOR_LIGHTRED, mstr);
    }
    else if(!sscanf(params, "us[128]", id, text))
    {
        Reported{playerid} = true;
        format(ReportText[playerid], 128, "%s", params);
        ReportPlayer[playerid] = id;
        SCMEx(playerid, COLOR_CYAN, "You have reported %s[ID:%d]: %s", GetNameEx(id), id, params);
        format(mstr, sizeof(mstr), "> %s[ID:%d] reported %s[ID:%d]: %s.", GetNameEx(playerid), playerid, GetNameEx(id), id, params);
        AdminsMSG(COLOR_LIGHTRED, mstr);
    }
    else return SyntaxMSG(playerid, "/report (Optional[playerid]) [report text]");
    return 1;
}
But it's kinda buggy .. can anyone help me or tell me what's wrong?
Reply
#2

pawn Код:
CMD:report(playerid, params[])
{
    if(!sscanf(params, "Us[128]", params[0], params[1]))
    {
        if(!params[0])
       {
              Reported{playerid} = true;
              format(ReportText[playerid], 128, "%s", params[1]);
              ReportPlayer[playerid] = INVALID_PLAYER_ID;
              SCMEx(playerid, COLOR_CYAN, "You have sent a report: %s", params[1]);
              format(mstr, sizeof(mstr), "The player %s[ID:%d] has reported: %s.", GetNameEx(playerid), playerid,                    params[1]);
              AdminsMSG(COLOR_LIGHTRED, mstr);
    }
    else if(params[0])
    {
        Reported{playerid} = true;
        format(ReportText[playerid], 128, "%s", params[1]);
        ReportPlayer[playerid] = id;
        SCMEx(playerid, COLOR_CYAN, "You have reported %s[ID:%d]: %s", GetNameEx(id), params[0], params[1]);
        format(mstr, sizeof(mstr), "> %s[ID:%d] reported %s[ID:%d]: %s.", GetNameEx(playerid), playerid, GetNameEx(params[0]), params[0], params[1]);
        AdminsMSG(COLOR_LIGHTRED, mstr);
    }
    else return SyntaxMSG(playerid, "/report (Optional[playerid]) [report text]");
    return 1;
}
I think that should work. Also check this:
https://sampforum.blast.hk/showthread.php?tid=120356
The part of optional specifiers.
Reply
#3

Try it like this, I can't really test it but I'm pretty sure it should work.

pawn Код:
CMD:report(playerid, params[])
{
    new id, text[128];
   
    if(!isnull(params))
    {
        sscanf(params, "us[128]", id, text);
        if(id != INVALID_PLAYER_ID)
        {
            Reported{playerid} = true;
            format(ReportText[playerid], 128, "%s", params);
            ReportPlayer[playerid] = INVALID_PLAYER_ID;
            SCMEx(playerid, COLOR_CYAN, "You have sent a report: %s", params);
            format(mstr, sizeof(mstr), "The player %s[ID:%d] has reported: %s.", GetNameEx(playerid), playerid, params);
            AdminsMSG(COLOR_LIGHTRED, mstr);
        }
        else
        {
            if(!isnull(text))
            {
                Reported{playerid} = true;
                format(ReportText[playerid], 128, "%s", params);
                ReportPlayer[playerid] = id;
                SCMEx(playerid, COLOR_CYAN, "You have reported %s[ID:%d]: %s", GetNameEx(id), id, params);
                format(mstr, sizeof(mstr), "> %s[ID:%d] reported %s[ID:%d]: %s.", GetNameEx(playerid), playerid, GetNameEx(id), id, params);
                AdminsMSG(COLOR_LIGHTRED, mstr);
            }
            else SyntaxMSG(playerid, "/report (Optional[playerid]) [report text]");
        }
    }
    else SyntaxMSG(playerid, "/report (Optional[playerid]) [report text]");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)