Function GetSuperior/InferiorID
#1

Hi, I have a problem with my function GetSuperior(Inferior)Id. Result of a debug :

[DEBUG SUNSHINE (0)]: SUPERIOR 0 | INFERIOR 499

Result required : SUPERIOR 1 | INFERIOR 1
(We are 2 connected, me (ID0) and a player (ID1)).

Can you help me ?

PHP код:
stock GetSuperiorId(playerid)
{
    new
        
player;
    do if(
playerid >= MAX_PLAYERSplayer 0; else player++;
    while(!
IsPlayerConnected(player) && PlayerInfo[player][LoggedIn] == false && PlayerInfo[player][pInMenu] == true && playerid == player);
    return 
playerid;
}
stock GetInferiorId(playerid)
{
    new
        
player;
    do if(
playerid <= 0player 499; else player--;
    while(!
IsPlayerConnected(player) && PlayerInfo[player][LoggedIn] == false && PlayerInfo[player][pInMenu] == true && playerid == player);
    return 
player;

Reply
#2

pawn Код:
stock GetNextPlayerID(id)
{
    for(new i = (id + 1), j = GetPlayerPoolSize(); i <= j; i ++)
    {
        if(!IsPlayerConnected(i))
        {
            continue;
        }
       
        return i;
    }
    return INVALID_PLAYER_ID;
}
Reply
#3

For previous ID ?
Reply
#4

Quote:
Originally Posted by YouServ
Посмотреть сообщение
For previous ID ?
Reverse the function.

Reply
#5

PHP код:
stock GetNextPlayerID(id)
{
    for(new 
= (id 1), GetPlayerPoolSize(); <= j--)
    {
        if(!
IsPlayerConnected(i))
        {
            continue;
        }
        
        return 
i;
    }
    return 
INVALID_PLAYER_ID;

That ?
Reply
#6

You can also use functions from foreach/y_iterate if you already use it since there are Iter_Next and Iter_Prev in it.

PHP код:
GetNextPlayerID(id)
{
    new
        
next_id;
    if ((
next_id Iter_Next(Playerid)) != MAX_PLAYERS) return next_id;
    return ((
next_id Iter_First(Player)) == id) ? INVALID_PLAYER_ID next_id;
}
GetPreviousPlayerID(id)
{
    new
        
previous_id;
    if ((
previous_id Iter_Prev(Playerid)) != MAX_PLAYERS) return previous_id;
    return ((
previous_id Iter_Last(Player)) == id) ? INVALID_PLAYER_ID previous_id;

Reply
#7

pawn Код:
stock GetNextPlayerID(id)
{
    for(new i = (id + 1), j = GetPlayerPoolSize(); i <= j; i ++)
    {
        if(!IsPlayerConnected(i))
        {
            continue;
        }
       
        return i;
    }
    return INVALID_PLAYER_ID;
}

stock GetPreviousPlayerID(id)
{
    for(new i = (id - 1), j = 0; i >= j; i --)
    {
        if(!IsPlayerConnected(i))
        {
            continue;
        }
       
        return i;
    }
    return INVALID_PLAYER_ID;
}
"INVALID_PLAYER_ID" will be returned if there isn't a next or previous player.
Reply
#8

Nice thanks, and have you idea for make a function to get the small ID connected in the server ?
Reply
#9

The lowest player ID?
pawn Код:
stock GetLowestPlayerID()
{
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
    {
        if(!IsPlayerConnected(i))
        {
            continue;
        }
       
        return i;
    }
    return INVALID_PLAYER_ID;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)