Символы, буковки, горячая замена
#13

Quote:
Originally Posted by ^Psycho^
Dr.Psycho (17:56:09 23/02/2010)
ведь была какая то стандартная функция
ReturnUser(playerid)
Код:
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
	new pos = 0;
	while (text[pos] < 0x21) // Strip out leading spaces
	{
		if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
		pos++;
	}
	new userid = INVALID_PLAYER_ID;
	if (IsNumeric(text[pos])) // Check whole passed string
	{
		// If they have a numeric name you have a problem (although names are checked on id failure)
		userid = strval(text[pos]);
		if (userid >=0 && userid < MAX_PLAYERS)
		{
			if(!IsPlayerConnected(userid))
			{
				/*if (playerid != INVALID_PLAYER_ID)
				{
					SendClientMessage(playerid, 0xFF0000AA, "User not connected");
				}*/
				userid = INVALID_PLAYER_ID;
			}
			else
			{
				return userid; // A player was found
			}
		}
		/*else
		{
			if (playerid != INVALID_PLAYER_ID)
			{
				SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
			}
			userid = INVALID_PLAYER_ID;
		}
		return userid;*/
		// Removed for fallthrough code
	}
	// They entered [part of] a name or the id search failed (check names just incase)
	new len = strlen(text[pos]);
	new count = 0;
	new name[MAX_PLAYER_NAME];
	for (new i = 0; i < MAX_PLAYERS; i++)
	{
		if (IsPlayerConnected(i))
		{
			GetPlayerName(i, name, sizeof (name));
			if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
			{
				if (len == strlen(name)) // Exact match
				{
					return i; // Return the exact player on an exact match
					// Otherwise if there are two players:
					// Me and MeYou any time you entered Me it would find both
					// And never be able to return just Me's id
				}
				else // Partial match
				{
					count++;
					userid = i;
				}
			}
		}
	}
	if (count != 1)
	{
		if (playerid != INVALID_PLAYER_ID)
		{
			if (count)
			{
				SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
			}
			else
			{
				SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
			}
		}
		userid = INVALID_PLAYER_ID;
	}
	return userid; // INVALID_USER_ID for bad return
}
Reply


Messages In This Thread
Символы, буковки, горячая замена - by ^Woozie^ - 22.02.2010, 20:29
Re: Символы, буковки, горячая замена - by MX_Master - 23.02.2010, 02:34
Re: Символы, буковки, горячая замена - by ^Woozie^ - 23.02.2010, 05:10
Re: Символы, буковки, горячая замена - by Riaz - 23.02.2010, 06:22
Re: Символы, буковки, горячая замена - by Riaz - 23.02.2010, 06:23
Re: Символы, буковки, горячая замена - by Butilka - 23.02.2010, 14:06
Re: Символы, буковки, горячая замена - by ^Woozie^ - 23.02.2010, 14:59
Re: Символы, буковки, горячая замена - by MX_Master - 23.02.2010, 15:27
Re: Символы, буковки, горячая замена - by ^Woozie^ - 23.02.2010, 19:58
Re: Символы, буковки, горячая замена - by [JIeXa] - 24.02.2010, 01:28
Re: Символы, буковки, горячая замена - by MX_Master - 24.02.2010, 03:53
Re: Символы, буковки, горячая замена - by ^Woozie^ - 24.02.2010, 06:37
Re: Символы, буковки, горячая замена - by Walk_M4n - 24.02.2010, 13:42
Re: Символы, буковки, горячая замена - by CracK - 24.02.2010, 14:13
Re: Символы, буковки, горячая замена - by ^Woozie^ - 24.02.2010, 17:32
Re: Символы, буковки, горячая замена - by ^Woozie^ - 26.02.2010, 19:53
Re: Символы, буковки, горячая замена - by MX_Master - 27.02.2010, 02:32
Re: Символы, буковки, горячая замена - by CracK - 27.02.2010, 05:26
Re: Символы, буковки, горячая замена - by ^Woozie^ - 27.02.2010, 08:18
Re: Символы, буковки, горячая замена - by CracK - 27.02.2010, 10:28
Re: Символы, буковки, горячая замена - by MX_Master - 27.02.2010, 12:04
Re: Символы, буковки, горячая замена - by ^Woozie^ - 27.02.2010, 12:43
Re: Символы, буковки, горячая замена - by MX_Master - 27.02.2010, 13:19
Re: Символы, буковки, горячая замена - by ^Woozie^ - 27.02.2010, 13:25

Forum Jump:


Users browsing this thread: 1 Guest(s)