u specifier and mask id
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Something like this will do I suppose:
pawn Код:
new targetid, text[128];
   
if (sscanf(params, "us[128]", targetid, text))
    return SendClientMessage(playerid, COLOR_GREY, "USAGE: /whisper [playerid/name/maskid] [text]");
       
if (targetid == INVALID_PLAYER_ID)
{
    if ((!sscanf(params, "is[128]", targetid, text) && targetid > MAX_PLAYERS && GetMaskPlayerID(targetid) == INVALID_PLAYER_ID)
        || targetid < MAX_PLAYERS)
        return SendClientMessage(playerid, COLOR_LIGHTRED, "You have specified an invalid player.");
}
Thank you, it works.

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
There are several other methods to do what you're trying to. I'm up late and this is what I've got in my quick drowsy thinking -

pawn Код:
CMD:whisper(playerid, params[]) {

    new
        target[MAX_PLAYER_NAME], //You're gonna take in ID/name as a string.
        text[128],
        ID //To either be used as player ID or mask ID.
    ;
   
    if(sscanf(params, "s["#MAX_PLAYER_NAME"]s[128]", target, text))
        return SendClientMessage(playerid, COLOR_GREY, "USAGE : /whisper [playerid/name/maskid] [text]");
       
    if(!IsNumeric(target)) //If the second argument given is not numeric, it's probably a player name?
        ID = GetPlayerNameByID(target); //Build a custom function that gets player ID from player name.
    else
        ID = strval(ID); //If it's an integer, it could either be player ID or mask ID.
       
    if(ID > MAX_PLAYERS) //Like you mentioned earlier, if it's greater than MAX_PLAYERS..
        //It's a mask ID.
    else
        //It's a player ID.
       
    return 1;
}
Another idea to do it within sscanf itself is to create a custom sscanf specifier.
Thanks, but Konstantinos' one seems to be easier. :P
Reply


Messages In This Thread
u specifier and mask id - by GoldenLion - 25.12.2016, 16:20
Re: u specifier and mask id - by Jefff - 25.12.2016, 16:26
Re: u specifier and mask id - by GoldenLion - 25.12.2016, 16:38
Re: u specifier and mask id - by Konstantinos - 25.12.2016, 17:06
Re: u specifier and mask id - by Lordzy - 25.12.2016, 17:08
Re: u specifier and mask id - by GoldenLion - 25.12.2016, 17:18

Forum Jump:


Users browsing this thread: 1 Guest(s)