02.02.2013, 14:03
How i can get the playerid by its name?
stock ReturnUser(text[])
{
new pos = 0;
while (text[pos] < 0x21)
{
if(text[pos] == 0) return INVALID_PLAYER_ID;
pos++;
}
new userid = INVALID_PLAYER_ID;
if(isNumeric(text[pos]))
{
userid = strval(text[pos]);
if(userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
userid = INVALID_PLAYER_ID;
else return userid;
}
}
new len = strlen(text[pos]);
new count3 = 0;
new pname[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerName(i, pname, sizeof (pname));
if(strcmp(pname, text[pos], true, len) == 0)
{
if(len == strlen(pname)) return i;
else
{
count3++;
userid = i;
}
}
}
}
if(count3 != 1)
{
userid = INVALID_PLAYER_ID;
}
return userid;
}
C:\Users\Acer\Desktop\samp03e_svr_R2_win32\gamemod es\sa-rp.pwn(536) : error 017: undefined symbol "isNumeric" Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase |
stock isNumeric(const string[])
{
new length=strlen(string);
if (length==0) return false;
for (new i = 0; i < length; i++)
{
if ((string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') || (string[i]=='-' && i!=0) || (string[i]=='+' && i!=0))
{
return false;
}
}
if (length==1 && (string[0]=='-' || string[0]=='+')) { return false; }
return true;
}