Question about sscanf
#1

Okay, so I have a simple PM command using ZCMD and sscanf:
Код:
CMD:pm(playerid, params[]){
if(LoggedIn[playerid]){
	new id, text[128];
	if(sscanf(params, "us[128]", id, text)){ return SendClientMessage(playerid, SYSTEM_MESSAGE_COLOR, "Usage: /pm (id/name) (text)"); }
	if(!LoggedIn[id]){ return SendClientMessage(playerid, SYSTEM_MESSAGE_COLOR, "This player is not logged in."); }
        format(Message,sizeof(Message),">>PM %s(%d): %s",pNames[id],id,text);
	SendClientMessage(playerid,PM_OUTGOING_COLOR,Message);
	format(Message,sizeof(Message),"**PM %s(%d): %s",pNames[playerid],playerid,text);
	SendClientMessage(id,PM_INCOMING_COLOR,Message);
	PlayerPlaySound(id,1085,0.0,0.0,0.0);
	printf("PM[%s(%d) >> %s(%d)]: %s", pNames[playerid], playerid, pNames[id], id, text);
	return 1;
}
return SendClientMessage(playerid, SYSTEM_MESSAGE_COLOR, "You need to be logged in"); }
As you can see I'm trying to check whether the player to whom you are sending the PM is logged in (using my log-in system) and if they are not, then it tells you "Player is not logged in". The thing is that ingame if I do for example "/pm 4 blah blah", and there's no player with ID 4 it'll give me the "SERVER: Unknown Command" message while I want it to say "This player is not logged in". However if I change "us[128]" in the format string of sscanf to "is[128", then it works with no problem and displays the right message. But I want to use "u" instead of "i" because then I can also use the name of the player as the command paramter, not just the ID. So does anyone know why is it doing this? Like displaying "SERVER: Unknown command" instead of "Player not logged in"?
Reply
#2

pawn Код:
CMD:pm(playerid, params[])
{
    new id, text[128];
    if(sscanf(params, "us[128]", id, text)) SendClientMessage(playerid, COLOR_GREY, "USAGE: /(p)m [playerid] [text]");
    else
    {
        if(!LoggedIn[id]) return SendClientMessage(playerid, SYSTEM_MESSAGE_COLOR, "This player is not logged in.");
        if(LoggedIn[playerid])
        {
            format(Message,sizeof(Message),">>PM %s(%d): %s",pNames[id],id,text);
            SendClientMessage(playerid,PM_OUTGOING_COLOR,Message);
            format(Message,sizeof(Message),"**PM %s(%d): %s",pNames[playerid],playerid,text);
            SendClientMessage(id,PM_INCOMING_COLOR,Message);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);
            printf("PM[%s(%d) >> %s(%d)]: %s", pNames[playerid], playerid, pNames[id], id, text);
            return 1;
        }
    }
    return SendClientMessage(playerid, SYSTEM_MESSAGE_COLOR, "You need to be logged in");
}
Edited:19:25
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)