SA-MP Forums Archive
Possibly an sscanf issue? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Possibly an sscanf issue? (/showthread.php?tid=550003)



Possibly an sscanf issue? - MythicalMarauder - 10.12.2014

Hi.

I've been struggling with this bug for like an hour, it wasted time. I have no clue what to do in it..
When I do /setplace 0, it sets it to place 0, cool, it works.
But if I did /setplace 1, nothing happens, not even a message appears.

Variables:
pawn Код:
new DefautlPlace = 0;
new ServerPlace;
pawn Код:
CMD:setplace(playerid, params[])
{
    new placeid, string[128];
    if(IsPlayerAdmin(playerid)|| PlayerInfo[playerid][pAdmin] >= 1)
    {
        if(sscanf(params, "u", placeid)) return SendClientMessage(playerid, GREY, "Usage: /setplace [id] | 0: Area 51 | 1: San Fierro | more soon ");
        //if(placeid == ServerPlace) return SendClientMessage(playerid, RED, "This is the current place!");

        if(placeid != ServerPlace)
        {
            switch(placeid)
            {
                case 0:
                {
                    TextDrawHideForAll(Textdraw1);
                    format(string,sizeof(string),"Admin "COL_PINK"%s (%d)"COL_WHITE" has set playing place to "COL_PINK"0 (Area 51)", GetName(playerid), playerid);
                    SendClientMessageToAll(WHITE, string);
                    TextDrawSetString(Textdraw1, "PLACE: ~r~Area 51");
                    TextDrawShowForAll(Textdraw1);
                    ServerPlace = 0;
                    DefaultPlace = -1;
                    for(new i = 0; i < MAX_PLAYERS; i++)
                    {
                        SpawnPlayer(i);
                    }
                }
                case 1:
                {
                    TextDrawHideForAll(Textdraw1);
                    format(string,sizeof(string),"Admin "COL_PINK"%s (%d)"COL_WHITE" has set playing place to "COL_PINK"1 (San Fierro)", GetName(playerid), playerid);
                    SendClientMessageToAll(WHITE, string);
                    TextDrawSetString(Textdraw1, "PLACE: ~r~San Fierro");
                    TextDrawShowForAll(Textdraw1);
                    ServerPlace = 1;
                    DefaultPlace = -1;
                    for(new i = 0; i < MAX_PLAYERS; i++)
                    {
                        SpawnPlayer(i);
                    }
                }
            }
        }
    }
    else
    {
        SendClientMessage(playerid, RED, "You're not an admin");
    }
    return 1;
}
Note; I've used if statements for placeid 0 and 1, same result.


Re: Possibly an sscanf issue? - PinkFloydLover - 10.12.2014

the 'u' is to be used for player ID's and user names
try using 'i' for other integer values.


Re: Possibly an sscanf issue? - Divergent - 10.12.2014

u is the parameter for playerid, use i (integer) or d (decimal) instead

if(sscanf(params, "i", placeid))


Re: Possibly an sscanf issue? - MythicalMarauder - 10.12.2014

Oh my God. I'm too dumb, sorry

I think when I was using 'u' it could only process the number 0 because my id was 0.. Thank you guys. Appreciated.