Quote:
Originally Posted by Konstantinos
It wouldn't work because if 4 players connect (IDs 0, 1, 2 and 3) and the first 2 (ID 0 and 1) leave the server, the variable will hold the number 2 but the current IDs of the players is 3 and 4 so the loop will never reach higher.
Yes, using MAX_PLAYERS for player-loops is not the best choice, especially if you haven't re-defined it.
So the best two I can suggest you is either GetPlayerPoolSize or foreach/y_iterate (the most recommended).
|
Quote:
Originally Posted by BloodMaster
Problem is with the ID's.
Let's imagine this:
gMaxPlayers = -1
You connect to the server
gMaxPlayers = 0
I connect to the server
gMaxPlayers = 1
Somebody else connects
gMaxPlayers = 2
Somebody else connects
gMaxPlayers = 3
Okay, everything seems fine for now.
But if I disconnect, players that are left on server are "0, 2 and 3", while your variable is gonna be at only 2, and when you loop it, it wouldn't reach last player.
You can just use an include called "foreach" which does what you want, but more optimized 
|
This is exactly what I want.
The gMaxPlayers would be variable to store the number of the connected players not each player with his ID.
If 4 players connect, gMaxPlayers would be 4, then 2 players quit, gMaxPlayers would be 2. (It starts with 0 on OnGameModeInit as it's always 0 players at that particle moment and increments on OnPlayerConnect)
So basically I would be looping with a max number of the gMaxPlayers rather than the MAX_PLAYERS.
Hopefully I didn't miss-understand what you guys said, and again, it's a simple variable to store the number of the currently connected players.
Quote:
Originally Posted by PrO.GameR
No point reinventing the wheel, use foreach so you only loop thru valid results, you can create your own iterators for example for house veh and business and have an optimized loop for those too.
|
Quote:
Originally Posted by iLearner
How about foreach? (i dont really know if there's anything different in it from for loop)
|
I never really looked into the foreach structure, but I do think programming is a place where the sky's the limit. Why should I count on someone's else work? (Not taking anything from ******, he's in fact, more of an idol for me)