2021-03-16, 01:34 PM
I have a function IDByName, as the name of the function says I want to get id by player name.
Function:
Example:
The function was work perfectly for me for a long time. But now when I have 200 players on my server function get bugged and many times when a player is connected function can't found them..
Have anyone ideas why it happened and how I can improve my function?
Function:
Code:
IdByName(const name[])
{
new iPlayer,names[MAX_PLAYER_NAME];
iPlayer = 999;
foreach(new i : Player)
{
? ? GetPlayerName(i, names, sizeof(names));
? ? if(!strcmp(name, names, true))
? ? {
? ? ? ? iPlayer = i;
}
}
return iPlayer;
}
Example:
Code:
? new oie = IdByName(name);
if(IsPlayerConnected(oie)) //player is online and oie is his ID
{
//code
}
else //player is not online
{
//code
}
The function was work perfectly for me for a long time. But now when I have 200 players on my server function get bugged and many times when a player is connected function can't found them..
Have anyone ideas why it happened and how I can improve my function?