u specifier and mask id
#1

Hi, I made a whisper command, but I want it to work like that a player can type other player's part of name, id or mask id to whisper him. Here's the GetMaskPlayerID function and the command:
Код:
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;
}
What I tried to do is
Код:
	if (targetid == INVALID_PLAYER_ID && GetMaskPlayerID(targetid) == INVALID_PLAYER_ID)
		return SendClientMessage(playerid, COLOR_LIGHTRED, "You have specified an invalid player.");
but then I realized that if I try to type in a mask id then sscanf will return 65535 because the mask id is an invalid player id so I can't use GetMaskPlayerID. So how would it be possible to use both u specifier and GetMaskPlayerID?

Also I have another question: shall I use normal variables or static variables (e.g for "targetid") in commands?
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: 3 Guest(s)