Question about get_players - for(new....)

Сообщения
278
Реакции
137
Hello,
I learned lots of methods to get players.
And I wanted to ask you which one should I use.
Many people told me all these codes are same, i should use whatever I want.
Which one should I use?

(I always use get_players)

PHP:
func()
{
    // g_MaxPlayers = get_member_game(m_nMaxPlayers);     in plugin_init
    // g_connected  [true] on putinserver [false] on disconnected

    // for(new id = 1; id <= MAX_CLIENTS; id++)
    // for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
    for(new id = 1; id <= g_MaxPlayers; id++)
    {
        if(get_member(id, m_iTeam) == TEAM_TERRORIST && g_connected[id])
        {
            client_print_color(id, id, "You are a terrorist");
        }
    }
}

func_get_players()
{
    new players[MAX_CLIENTS], inum;
    // maybe it should be new, idk
    static id;
    get_players(players, inum, "e", "TERRORIST");
    for(new i; i<inum; i++)
    {
        id = players[i];
        client_print_color(id, id, "You are a terrorist");
    }
}
 
Сообщения
1,420
Реакции
2,511
Помог
58 раз(а)
Код:
for(new i = 1; i <= MaxClients; i++)
{
    if(is_user_connected(i) && !is_user_bot(i) && get_member(i, m_iTeam) == TEAM_TERRORIST)
        client_print_color(i, print_team_red, "^1You are a ^3terrorist");
}
Код:
new iPlayers[MAX_PLAYERS], iPlayerCount;
get_players_ex(iPlayers, iPlayerCount, GetPlayers_ExcludeBots|GetPlayers_MatchTeam, "TERRORIST");

for(new i; i < iPlayerCount; i++)
{
    client_print_color(iPlayers[i], print_team_red, "^1You are a ^3terrorist");
}
The difference is that in the first case there is only once for loop, while in the second case there are two (the first one is done in get_players). Theoretically, the second should be faster because the first for loop is done in C++ and not pawn, but there are two for loops so the first one, IIRC, is faster, but there will be MaxClients iterarions (MaxClients equals to the number of slots of server), while in the second case there will be as much iterations as players were found.
 
Сообщения
278
Реакции
137
but there are two for loops so the first one, IIRC, is faster, but there will be MaxClients iterarions (MaxClients equals to the number of slots of server), while in the second case there will be as much iterations as players were found.
So, you recommend me to use first one?
Isn't a problem that checking if(is_user_connected(i) && !is_user_bot(i) && get_member(i, m_iTeam) == TEAM_TERRORIST)
as far as number of players?

Код:
for(new i = 1; i <= MaxClients; i++)
{
    if(is_user_connected(i) && !is_user_bot(i) && get_member(i, m_iTeam) == TEAM_TERRORIST)
        client_print_color(i, print_team_red, "^1You are a ^3terrorist");
}
 
Сообщения
147
Реакции
29
w0w any difference between get_players and _ex ?
 
Сообщения
147
Реакции
29
Oh i though i will be missing something more than syntax, spasibo!
 
Сообщения
1,420
Реакции
2,511
Помог
58 раз(а)

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу