SA-MP Forums Archive
Question about sscanf - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Question about sscanf (/showthread.php?tid=240375)



Question about sscanf - JackYack13 - 15.03.2011

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"?


Re: Question about sscanf - Hashski - 15.03.2011

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