loop through all players
Just to clarify my ideas I'm posting this.
PHP Code:
PHP Code:
PHP Code:
Am I correct ? |
Re: loop through all players
|
Re: loop through all players
#2 does NOT do the same thing as #1, even with no flags specified. #1 is guaranteed to loop through every index up to MaxPlayers. Whereas #2 will only loop through all indexes that are occupied in the server.
Say you only have 5 users connected and 32 slots max. #1 will loop through 32 times #2 will loop through 5 times |
Re: loop through all players
#2 is worse way that I wont recomment.
get_players works like this: - First it loops trought 32 results, check if they accept with the flags and put it in players[32]. After it did that, you gonna do a loop again, with the amount of results it added to players[32] with the needed flags. So results in 2 loops, that results in more overlows. So I recomment #1 |
Re: loop through all players
Well nice explanation.
How AMX handles players ID. Is it like ID: 1 to 32 as per players join into the server. And when a player leave that id is assigned to other who joins the server. So the ID is actually one serial number assigned to each player. |
Re: loop through all players
Index is assigned by the Server, not AMXX. The server does it in sequential order.
5 Players join and get assigned Indexes 1-5. Player 2 drops. A new player connects and gets assigned Index 2 Also, I still recommend using get_players over looping through every user. |
Re: loop through all players
Quote:
|
Re: loop through all players
Hmm maybe..
|
Re: loop through all players
Not maybe, it is 100% sure, get_players make checks internally, when the second way has to check if each player is connected, so maxclient * is_user_connected natives calls for nothing.
Anyway, if it is just to print a message, you can send 1 message to everyone : client_print(0, print_chat, "Your message with some patterns like %s", szName) Or you can make your own if it is justified : PHP Code:
Anyway, do never use code #1, never. And about code #2, in your example, 'player' variable is not required because you use it only once, so you can directly use players[i] instead. 'player' is usefull for optimization to prevent multiple use of players[i] (called re-indexing if you read wiki about optimizations). |
Re: loop through all players
Quote:
Actually I don't understand this write_byte() function. It says write bytes to message. In C char is 1 byte. So how these bytes are calculated here for particular message which need to be sent to client. |
| All times are GMT -4. The time now is 11:11. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.