Raised This Month: $51 Target: $400
 12% 

get_players or global var


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 05-13-2015 , 18:46   get_players or global var
Reply With Quote #1

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?

Last edited by vitorrossi; 05-13-2015 at 18:47.
vitorrossi is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 05-13-2015 , 19:49   Re: get_players or global var
Reply With Quote #2

Quote:
Originally Posted by vitorrossi View Post
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.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-13-2015 , 20:27   Re: get_players or global var
Reply With Quote #3

Your code makes absolutely no sense.

Why do you need this information so often?
__________________
fysiks is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-13-2015 , 23:49   Re: get_players or global var
Reply With Quote #4

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
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
zeus
Senior Member
Join Date: Jul 2008
Old 05-14-2015 , 03:15   Re: get_players or global var
Reply With Quote #5

Quote:
Originally Posted by aron9forever View Post
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?
zeus is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-14-2015 , 06:39   Re: get_players or global var
Reply With Quote #6

Quote:
Originally Posted by zeus View Post
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)
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 05-14-2015 , 11:49   Re: get_players or global var
Reply With Quote #7

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 View Post
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.
__________________
In Flames we trust!

Last edited by Nextra; 05-14-2015 at 11:49.
Nextra is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 05-14-2015 , 12:49   Re: get_players or global var
Reply With Quote #8

Quote:
Originally Posted by Nextra View Post
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 View Post
Your code makes absolutely no sense.

Why do you need this information so often?
Lol always so helpful
vitorrossi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:59.


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