AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_players or global var (https://forums.alliedmods.net/showthread.php?t=262848)

vitorrossi 05-13-2015 18:46

get_players or global var
 
I have a task that is called every 5 seconds, and in it I use get_players to retrieve all players, and loop through them to get team player counts and team alive counts since I've read that team flags on get_players can return false values sometimes.

I was wondering if having two global variables such as

PHP Code:

g_iConnected
g_iPlayers
[32

and storing and deleting players as

PHP Code:

client_putinserver(id){
    
g_iPlayers[g_iConnected++]
}

client_disconnect(id){
    for(new 
0g_iConnectedi++)
        if(
g_iPlayers[i] == id)
            
g_iPlayers[i] = g_iPlayers[--g_iConnected]
            break


would be a good idea to avoid calling get_players and looping so often. In this way I would also store team counts and alive counts in global vars.

What would be better?

wickedd 05-13-2015 19:49

Re: get_players or global var
 
Quote:

Originally Posted by vitorrossi (Post 2296410)
I've read that team flags on get_players can return false values sometimes.

That's not true, at least NO one has given a way to reproduce it.

Explain exactly what you're trying to do.

fysiks 05-13-2015 20:27

Re: get_players or global var
 
Your code makes absolutely no sense.

Why do you need this information so often?

aron9forever 05-13-2015 23:49

Re: get_players or global var
 
you might wanna be careful with approaches like these
first of all, that's pretty much a micro optimization (if it even is an optimization)
also, there are certain cases in which a player leaves the server yet client_disconnect isn't called

zeus 05-14-2015 03:15

Re: get_players or global var
 
Quote:

Originally Posted by aron9forever (Post 2296486)
you might wanna be careful with approaches like these
first of all, that's pretty much a micro optimization (if it even is an optimization)
also, there are certain cases in which a player leaves the server yet client_disconnect isn't called

For example?

aron9forever 05-14-2015 06:39

Re: get_players or global var
 
Quote:

Originally Posted by zeus (Post 2296521)
For example?

cancel while connecting
any type of client crash or connection loss (client_disconnect will eventually be called, but only after sv_timeout seconds)

Nextra 05-14-2015 11:49

Re: get_players or global var
 
I'm not aware of any issues with get_players in the latest AMXX builds, especially not the "a" or "b" flag. Your approach only complicates the code and will not result in a performance benefit. Quite the opposite actually: get_players will in almost all cases be the fastest method for looping players, as it does all filtering at once (not that it matters).

If you truly wanted to cache data like team and alive counts you would need a very good reason for it. A task that runs every 5 seconds is definitely not one of those reasons. AddToFullPack and similar are pretty much the only use-cases that might qualify.

Quote:

Originally Posted by aron9forever (Post 2296564)
cancel while connecting
any type of client crash or connection loss (client_disconnect will eventually be called, but only after sv_timeout seconds)

The client is technically not disconnected until he times out. That's quite different to "client_disconnected is not called in certain cases". Please be careful with such claims.

vitorrossi 05-14-2015 12:49

Re: get_players or global var
 
Quote:

Originally Posted by Nextra (Post 2296667)
I'm not aware of any issues with get_players in the latest AMXX builds, especially not the "a" or "b" flag. Your approach only complicates the code and will not result in a performance benefit. Quite the opposite actually: get_players will in almost all cases be the fastest method for looping players, as it does all filtering at once (not that it matters).

If you truly wanted to cache data like team and alive counts you would need a very good reason for it. A task that runs every 5 seconds is definitely not one of those reasons. AddToFullPack and similar are pretty much the only use-cases that might qualify.



The client is technically not disconnected until he times out. That's quite different to "client_disconnected is not called in certain cases". Please be careful with such claims.

Ok, I wasn't sure if it would be an optimization or not, but after reading your reply I must agree with you. Thanks.



Quote:

Originally Posted by fysiks (Post 2296431)
Your code makes absolutely no sense.

Why do you need this information so often?

Lol always so helpful


All times are GMT -4. The time now is 09:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.