27.12.2018, 14:49
So I have this function ReturnUser, which is ment to convert a username ( if online ) to an ID so I can use IsPlayerConnected with strings instead of IDs. ( Useful when I for example want to make a set admin level command for offline players. )
The issue is, that it finishes off my strings to find players online. So if I want to do /omakeadmin stef 1, it will finish the string to Stefhan ( if he is online, otherwise it wont finish the line ) instead of looking for Stef.
How do I change this function so it doesn't finish off names?
The issue is, that it finishes off my strings to find players online. So if I want to do /omakeadmin stef 1, it will finish the string to Stefhan ( if he is online, otherwise it wont finish the line ) instead of looking for Stef.
How do I change this function so it doesn't finish off names?
Код:
ReturnUser(text[])
{
new smalltext[MAX_PLAYER_NAME];
strmid(smalltext, text, 0, MAX_PLAYER_NAME); //extract from 0 to 24, put in smalltext
//check if id 0
if(!strcmp(smalltext, "0"))
{
if(IsPlayerConnected(0))
{
return 0; //return id 0
}
else
{
return INVALID_PLAYER_ID;
}
}
//convert str to number
new id = strval(smalltext);
if(id < 0)
{
return INVALID_PLAYER_ID;
}
if(id) //is an id
{
if(IsPlayerConnected(id))
{
return id;
}
else
{
return INVALID_PLAYER_ID;
}
}
else //if part of a players name
{
new playerName[MAX_PLAYER_NAME];
foreach(Player, i)
{
GetPlayerName(i, playerName, MAX_PLAYER_NAME);
if(!strcmp(playerName, smalltext, true, strlen(smalltext)))
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}

