GetMaskPlayerID(maskid) { for (new i, j = GetPlayerPoolSize(); i <= j; i++) if (IsPlayerConnected(i) && PlayerInfo[i][pMaskID] == maskid) return i; return INVALID_PLAYER_ID; } CMD:whisper(playerid, params[]) { new targetid, text[128]; if (PlayerInfo[playerid][pDeathState] == DEATH_STATE_DEAD) return SendClientMessage(playerid, COLOR_LIGHTRED, "You can't whisper anyone while being dead."); if (sscanf(params, "us[128]", targetid, text)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /whisper [playerid/name/maskid] [text]"); if (targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_LIGHTRED, "You have specified an invalid player."); if (!IsPlayerNearPlayer(playerid, targetid, 2.5)) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are near the specified player."); if (strlen(params) > 64) { SendClientMessageEx(playerid, COLOR_YELLOW, "* You whisper to %s: %.64s", GetName(targetid, 0), text); SendClientMessageEx(playerid, COLOR_YELLOW, "...%s", text[64]); SendClientMessageEx(targetid, COLOR_YELLOW, "* %s whispers you: %.64s", GetName(playerid, 0), text); SendClientMessageEx(targetid, COLOR_YELLOW, "...%s", text[64]); } else { SendClientMessageEx(playerid, COLOR_YELLOW, "* You whisper to %s: %s", GetName(targetid, 0), text); SendClientMessageEx(targetid, COLOR_YELLOW, "* %s whispers you: %s", GetName(playerid, 0), text); } return 1; }
if (targetid == INVALID_PLAYER_ID && GetMaskPlayerID(targetid) == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_LIGHTRED, "You have specified an invalid player.");
maskid must be greater than MAX_PLAYERS if you want use [playerid / nick / maskid]
|
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.");
}
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;
}
Something like this will do I suppose:
pawn Код:
|
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 Код:
|