05.03.2014, 18:06
How should I do when the servers are kindly requested to chat @ if, somehow ID so give me the name of the player example: @0 went to play tanks ==> EmpireSk went to play tanks
?
// OnPlayerText:
if (text[0] == '@')
{
new
id;
if ((id = RetrieveID(text)) != INVALID_PLAYER_ID)
{
new
name[21];
GetPlayerName(id, name, sizeof (name));
// format and send..
}
}
stock RetrieveID(const text[])
{
new
pos,
id[3],
bool: numeric = true;
while (text[++pos] > ' ')
{
if (pos > sizeof (id)) break;
if (!('0' <= text[pos] <= '9'))
{
numeric = false;
break;
}
id[pos - 1] = text[pos];
}
if (numeric && !isnull(id)) return strval(id);
return INVALID_PLAYER_ID;
}
#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
"test1"
"@ test2"
"@0 test3" // it worked because it's valid and connected player
"@3 test4"
"@444444 test5"
"@4@ test6"
if (numeric && !isnull(id)) return strval(id);
if (numeric && !isnull(id) && IsPlayerConnected(strval(id))) return strval(id);