View Single Post
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 05-01-2021 , 20:32   Re: [L4D2] Shop v2.4 (1 May 2021)
Reply With Quote #17

Quote:
Originally Posted by pan0s View Post
For the listen server, client index over 18 will have the exception "Client index 19 is invalid", so I define it to 18.
Of course, for the server who have 20+ players, they can change it back to 20+ because the dedicated server has no this problem.
That's not how you fix that error. The variable MaxClients is dynamic and can change depending on how many players a server can handle. MAXPLAYERS + 1 handles up to 64 players + world/server index which is what you use for global variables.

To fix the "Client X is invalid" error you usually include this check:
PHP Code:
if (client <= MaxClients
It will make sure that only clients between index 1 to MaxClients will be affected.

You also need to loop through clients consistently. Even on listen servers, this is still the ideal loop:
PHP Code:
for (int i 1<= MaxClientsi++) 
In your current code, I see loops like this:
PHP Code:
for (int i 0MaxClients 1i++) 
There are only certain cases where you would need to directly affect index 0 for listen servers, but most of the time, index 1 still works.
__________________
Psyk0tik is offline