SA-MP Forums Archive
Get Player id from name - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Get Player id from name (/showthread.php?tid=558468)



Get Player id from name - n00el - 17.01.2015

Hello, i have a varible 'nev' for e.g. "Thommas_Cook".
And the code is:
Код:
new id = GetPlayerID(nev);
if (IsPlayerConnected(id)) {
   // 1
}
else
{
   // 2
}
The second cames always, when the player (Thommas Cook) is connected, or not connected. Why?
I debug it with prinf(id) and printf(nev) and it's good, (id = playerid, 0), nev is Thommas_Cook


Re: Get Player id from name - BroZeus - 17.01.2015

Use sscanf its lot more easier and has a specifier already for that
Example
pawn Код:
new id;
if(sscanf(nev, "u", id))
{
     //player is NOT connected
}
else
{
     //now 'id' contains id of the player who's name is in 'nev'
}
PS. You need sscanf plugin and include to use this function