help + rep
#5

bump..

Quote:

/----------------------------------------------------------

#define RETURN_USER_FAILURE -1
#define RETURN_USER_MULTIPLE -2

stock ReturnUser(text[])
{
new pos = 0;
new userid = RETURN_USER_FAILURE;

while(text[pos] < 0x21) { // Strip out leading spaces
if(text[pos] == 0) return RETURN_USER_FAILURE; // No passed text
pos++;
}

if(isNumeric(text[pos])) { // Check whole passed string
userid = strval(text[pos]);
if(userid >=0 && userid < MAX_PLAYERS)
{
if(IsPlayerConnected(userid)) return userid;
return RETURN_USER_FAILURE;
}
}

// 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+1];

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;
}
else { // Partial match
count++;
userid = i;
}
}
}
}

if(!count) return RETURN_USER_FAILURE;
if(count > 1) return RETURN_USER_MULTIPLE;

return userid;
}

//----------------------------------------------------------

Reply


Messages In This Thread
help + rep - by JuzDoiT - 05.05.2017, 15:16
Re: help + rep - by lackmail - 05.05.2017, 15:20
Re: help + rep - by iLearner - 05.05.2017, 15:21
Re: help + rep - by NaS - 05.05.2017, 15:24
Re: help + rep - by JuzDoiT - 05.05.2017, 15:43
Re: help + rep - by Vince - 05.05.2017, 15:58
Re: help + rep - by JuzDoiT - 05.05.2017, 16:01
Re: help + rep - by ShihabSoft - 05.05.2017, 17:08

Forum Jump:


Users browsing this thread: 1 Guest(s)