SA-MP Forums Archive
sscanf problem - 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: sscanf problem (/showthread.php?tid=339609)



sscanf problem - Face9000 - 04.05.2012

Hello,today in the middle of test about my gamemode,i read this on the console:

[12:29:31] sscanf warning: Strings without a length are deprecated, please add a destination size.
[12:29:31] sscanf warning: Format specifier does not match parameter count.

What means? Sscanf include/plugin is updated.


Re: sscanf problem - JaKe Elite - 04.05.2012

When it happens?
If that happens every time when you use your command that uses sscanf
Post the code here


Re: sscanf problem - Face9000 - 04.05.2012

I noticed some days ago in the console and before again.The last command i used,that uses sscanf is /loc:

pawn Код:
CMD:loc(playerid, params[])
{
    new id;
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
    if(sscanf(params, "u", id))
    {
        SendClientMessage(playerid, 0xFF0000FF, "Usage: /loc [playerid]");
    }
    else
    {
            new zone[MAX_ZONE_NAME];
            GetPlayer2DZone(id, zone, MAX_ZONE_NAME);
            new playername[MAX_PLAYER_NAME],message2[170];
            GetPlayerName(id,playername,MAX_PLAYER_NAME);
            format(message2,sizeof(message2),"%s(%d)'s current location: %s",playername,id,zone);
            SendClientMessage(playerid,0x00C7FFAA,message2);
    }
    return true;
}



Re: sscanf problem - JaKe Elite - 04.05.2012

I don't see the problem.
Maybe when you are using a command that uses sscanf string it doesn't have the string size
recheck all the commands if you find a command that doesn't have string size put on it

the string size i was talking about is something like this

pawn Код:
new str[92];
if(sscanf(params, "s[92]", str)) return Fail(playerid);



Re: sscanf problem - Calgon - 04.05.2012

Unrelated to your sscanf problem:

You're checking if the ID is connected before you know what the ID even is. This will render your IsPlayerConnected checks pointless.

pawn Код:
CMD:loc(playerid, params[])
{
    new id;
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
    if(sscanf(params, "u", id))
    {
        SendClientMessage(playerid, 0xFF0000FF, "Usage: /loc [playerid]");
    }
    else
    {
            new zone[MAX_ZONE_NAME];
            GetPlayer2DZone(id, zone, MAX_ZONE_NAME);
            new playername[MAX_PLAYER_NAME],message2[170];
            GetPlayerName(id,playername,MAX_PLAYER_NAME);
            format(message2,sizeof(message2),"%s(%d)'s current location: %s",playername,id,zone);
            SendClientMessage(playerid,0x00C7FFAA,message2);
    }
    return true;
}
Specifically here:
pawn Код:
new id;
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
    if(sscanf(params, "u", id))
When you create an integer variable, the default value is zero (0). When you use the 'u' parameter in sscanf, it returns an ID of a player or INVALID_PLAYER_ID. What you're doing is checking if the player is connected before sscanf has a chance to tell you what the ID is.

Your IsPlayerConnected check should be after sscanf.

pawn Код:
CMD:loc(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id))
    {
        SendClientMessage(playerid, 0xFF0000FF, "Usage: /loc [playerid]");
    }
    else
    {
            if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
            new zone[MAX_ZONE_NAME];
            GetPlayer2DZone(id, zone, MAX_ZONE_NAME);
            new playername[MAX_PLAYER_NAME],message2[128];
            GetPlayerName(id,playername,MAX_PLAYER_NAME);
            format(message2,sizeof(message2),"%s(%d)'s current location: %s",playername,id,zone);
            SendClientMessage(playerid,0x00C7FFAA,message2);
    }
    return true;
}
This should fix a problem with your command, but as for the sscanf warning problem, I'm not entirely sure.

Also, chat message strings are only ever 128 characters, not 170.


Re: sscanf problem - Face9000 - 04.05.2012

Okay thanks guys,i'll see what's the problemy by trying one per one the commands.


Re: sscanf problem - FOTIS6 - 04.05.2012

Use this:
Код:
CMD:loc(playerid, params[])
{
    new id;
    if(!sscanf(params, "ii", id))
    {
        if(IsPlayerConnected(id))
        {
            new zone[MAX_ZONE_NAME];
            GetPlayer2DZone(id, zone, MAX_ZONE_NAME);
            new playername[MAX_PLAYER_NAME],message2[128];
            GetPlayerName(id,playername,MAX_PLAYER_NAME);
            format(message2,sizeof(message2),"%s(%d)'s current location: %s",playername,id,zone);
            SendClientMessage(playerid,0x00C7FFAA,message2);
        }
        else return SendClientMessage(playerid, 0xFF0000FF, "ERROR: {FFFFF}This Player is not connected");
    }
    else return SendClientMessage(playerid, 0xFF0000FF, "USAGE: {FFFFFF}/loc [id]");
    return 1;
}



Re: sscanf problem - Littlehelper - 13.06.2012

Quote:
Originally Posted by FOTIS6
Посмотреть сообщение
Use this:
Код:
CMD:loc(playerid, params[])
{
    new id;
    if(!sscanf(params, "ii", id))
    {
        if(IsPlayerConnected(id))
        {
            new zone[MAX_ZONE_NAME];
            GetPlayer2DZone(id, zone, MAX_ZONE_NAME);
            new playername[MAX_PLAYER_NAME],message2[128];
            GetPlayerName(id,playername,MAX_PLAYER_NAME);
            format(message2,sizeof(message2),"%s(%d)'s current location: %s",playername,id,zone);
            SendClientMessage(playerid,0x00C7FFAA,message2);
        }
        else return SendClientMessage(playerid, 0xFF0000FF, "ERROR: {FFFFF}This Player is not connected");
    }
    else return SendClientMessage(playerid, 0xFF0000FF, "USAGE: {FFFFFF}/loc [id]");
    return 1;
}
Why there are two 'ii'? while there is only one integer value used.