IsPlayerConnected question - 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: IsPlayerConnected question (
/showthread.php?tid=568267)
IsPlayerConnected question -
maximthepain - 21.03.2015
Hey, I would like to ask you guys,
Is there any way to check by name IsPlayerConnected?
for example: If I'm offline removing account, I want to use IsPlayerConnected(strval(targetname))...
And if he is connected then let the admin know that he should not remove connected player.
But HOW? I'm not sure this will work just like it sound, I didn't check the code, however I searched and didn't understand quick solution for this.
Please explain
Re: IsPlayerConnected question -
Jefff - 21.03.2015
pawn Код:
IsPlayerOnline(const nick[])
{
if(!nick[0]) return INVALID_PLAYER_ID; // empty nick
static name[MAX_PLAYER_NAME + 1];
for(new i, g = GetMaxPlayers(); i < g; i++)
if(IsPlayerConnected(i))
{
GetPlayerName(i, name, sizeof(name));
if(!strcmp(nick, name))
return i;
}
return INVALID_PLAYER_ID;
}
// in cmd
new ID = IsPlayerOnline(targetname);
if(ID != INVALID_PLAYER_ID) // or if you don't want ID use if(IsPlayerOnline(targetname) != INVALID_PLAYER_ID)
{
// player is online
}
else
{
// player is offline
}
AW: IsPlayerConnected question -
Nero_3D - 21.03.2015
or you use sscanf
pawn Код:
sscanf(targetname, "r", ID);
Re: IsPlayerConnected question -
maximthepain - 21.03.2015
Quote:
Originally Posted by Jefff
pawn Код:
IsPlayerOnline(const nick[]) { if(!nick[0]) return INVALID_PLAYER_ID; // empty nick
static name[MAX_PLAYER_NAME + 1]; for(new i, g = GetMaxPlayers(); i < g; i++) if(IsPlayerConnected(i)) { GetPlayerName(i, name, sizeof(name)); if(!strcmp(nick, name)) return i; }
return INVALID_PLAYER_ID; }
// in cmd new ID = IsPlayerOnline(targetname); if(ID != INVALID_PLAYER_ID) // or if you don't want ID use if(IsPlayerOnline(targetname) != INVALID_PLAYER_ID) { // player is online } else { // player is offline }
|
Yes thanks man! this codes helps me the way i needed it.
Tried with sscanf and couldn't make it work. I know its simple yet i cannot understand how to use it right. rep+
Re: IsPlayerConnected question -
Pottus - 21.03.2015
lol dude using sscanf() is very basic.
pawn Код:
IsPlayerOnline(const name[])
{
new pid;
if(!sscanf(nick, "u", pid))
{
new checkname[MAX_PLAYER_NAME+1];
GetPlayerName(pid, checkname, MAX_PLAYER_NAME+1);
if(!strcmp(nick, checkname)) return pid;
}
return INVALID_PLAYER_ID;
}
}