sscanf problem
#5

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.
Reply


Messages In This Thread
sscanf problem - by Face9000 - 04.05.2012, 10:23
Re: sscanf problem - by JaKe Elite - 04.05.2012, 10:25
Re: sscanf problem - by Face9000 - 04.05.2012, 10:28
Re: sscanf problem - by JaKe Elite - 04.05.2012, 10:33
Re: sscanf problem - by Calgon - 04.05.2012, 10:52
Re: sscanf problem - by Face9000 - 04.05.2012, 11:16
Re: sscanf problem - by FOTIS6 - 04.05.2012, 12:35
Re: sscanf problem - by Littlehelper - 13.06.2012, 10:59

Forum Jump:


Users browsing this thread: 1 Guest(s)