IsPlayerConnected question
#1

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
Reply
#2

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
}
Reply
#3

or you use sscanf
pawn Код:
sscanf(targetname, "r", ID);
Reply
#4

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+
Reply
#5

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;
}
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)