View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-09-2021 , 07:07   Re: Getting global data from non-id publics
Reply With Quote #6

Quote:
Originally Posted by Natsheh View Post
Basically get_players is the same as looping players indexes from 1 to 32 except its done in a module which is much faster

PHP Code:
for(new id 1<= g_iMaxplayersid++)
{
     if(
is_user_connected(id))
     {
  
      }

Speed is not the reason get_players is the recommended way. get_players should be used because it returns directly a list of valid player indexes. Moreover, it allows filtering players based on multiple conditions, which can come in handy.

The speed with a loop that runs at most 32 times is irrelevant. Even if running the loop in a module may be very slightly faster, as a whole get_players is likely slower than just looping from 1 to max players and checking. With get_players there is a loop inside the module, then there is the pawn c++ interop time and then you loop again in plugin over the results from get_players(which may be less than 32 because of filtering/the server is not full). But this is not an issue, because as I said previously, speed is not why get_players is recommended.
__________________
HamletEagle is offline