use get_players or MaxClients

Сообщения
13
Реакции
1
Which should i use?
Код:
    for(new i; i < MaxClients; i++)
    {
        if( !is_user_bot(i)  &&  is_user_alive(i)  &&  get_member(i, m_iTeam) == TEAM_CT  ) {

            iClose[i] = true;
        }
    }
Код:
    new players[MAX_PLAYERS], num;

    get_players(players, num, "ace", "CT");

    for(new i; i < num; i++)
    {

        iClose[players[i]] = true;

    }
 
Сообщения
278
Реакции
137
If you will use for(new.., first you should check if is player connected.

Код:
//if( !is_user_bot(i)  &&  is_user_alive(i)  &&  get_member(i, m_iTeam) == TEAM_CT  ) {
if(  is_user_alive(i) && !is_user_bot(i)  &&  get_member(i, m_iTeam) == TEAM_CT  ) {
 
Последнее редактирование модератором:
Сообщения
2,491
Реакции
2,794
Помог
61 раз(а)
for(new i; i < MaxClients; i++)
Corerct range is from 1 to MaxClients (included). In your example you will never get last player index, and have extra check with 0 index (which means world)

get_players(players, num, "ace", "CT");
amxx hooks message TeamInfo. And if some plugin changed team and send custom message it will not catch new team. Fortunately there are some fixes for this inside amxx. But the bug can be from time to time.

Thanks for the comments but which one would you suggest me to use?
It depends on what you want to do. And there is no the best method which you must always use.
 
Сообщения
278
Реакции
137
Not really. is_user_alive will return false if user is disconnected.
triprice, it's better to use second approach. A bit faster.
Yeap, it will return false. That's why I told him to check if user is connected (is_user_alive does it). You could have checked my example. I meant he should use "is_user_alive" before "is_user_bot" because it will give an error. [ you can't check people who is not connected if they are bots or not.
I meant that if you want to use for(new..., first, you should check if he is connected. Then what you want.

Код:
for( new id = 1; id <= MaxClients; id++)
{
           if(is_user_alive(id))     // Only Alives
           if(is_user_connected(id) && !is_user_alive(id))  // Only Deads
           if(is_user_connected(id) && ...)  // Any

           //if(is_user_bot(id) && is_user_connected(id)) or is_user_bot(id) && is_user_alive(id)) is wrong.
}
*

Btw, triprice, use like that;

Код:
new players[MAX_PLAYERS], num, player;
// or you can use static player;
get_players(players, num, "ace", "CT");

for (new i=0; i<num; i++)
{
   player = players[i];
}
 
Последнее редактирование модератором:
  • Нравится
Реакции: Ayk

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

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