08.04.2008, 05:42
pawn Код:
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]!='+') // Not a number,'+' or '-'
|| (string[i]=='-' && i!=0) // A '-' but not at first.
|| (string[i]=='+' && i!=0) // A '+' but not at first.
) return false;
}
if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
return true;
}
stock GetPlayerId(string[])
{ // By Alex (touched up by DracoBlue & Cueball)
if(isNumeric(string))
{
new player = strval(string);
if(IsPlayerConnected(player)) return player;
}
else
{
new playername[MAX_PLAYER_NAME];
for(new i=0; i<=MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerName(i, playername, MAX_PLAYER_NAME);
if(strfind(playername, string, true) != -1) return i;
}
}
}
return INVALID_PLAYER_ID;
}
Taken from dutils.inc by DracoBlue But it seems that I made a mistake, the function name is 'GetPlayerId(string[])' (note the Id, as opposed to ID).
Replace this line (in both commands):
pawn Код:
new id = strval(tmp);
pawn Код:
new id = GetPlayerId(tmp);
~Cueball~