Raised This Month: $433 Target: $400
 108% 

Solved For loop stopping at iteration 6


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nezur0s
Junior Member
Join Date: Feb 2020
Old 03-22-2020 , 06:21   For loop stopping at iteration 6
Reply With Quote #1

Hello I have in my plugin this for loop
PHP Code:
int Cts[MAXPLAYERS 1];
     
int number 0;
     for (
int i 1MAXPLAYERS 1;i++)
     {
         
PrintToChatAll("Client Number %d",i);
         if (
IsClientConnected(i))
         {
              if (
IsPlayerAlive(i))
              {
                  if (
GetClientTeam(i) == CS_TEAM_CT)
                {
                
Cts[number] = i;
                
number++;
                }
              }
         }
     }
PrintToChatAll("Loop Next"); // only executes half the time in online server 
It's supposed to get all Ct Team clients and put them in Cts array
When i am in my own lan server with bots this loop seems to work just fine
When i try it in a real server with a small number of players (for some reasons it does this more when there are less players) it seems to work half the time and in the other half it stops at client index 6 and the rest of the code under it doesn't get executed. (I am not the server owner and can't get the console output to know the error)

Last edited by Nezur0s; 03-23-2020 at 07:19.
Nezur0s is offline
Marttt
Senior Member
Join Date: Jan 2019
Old 03-22-2020 , 10:33   Re: For loop stopping at iteration 6
Reply With Quote #2

Try to change IsClientConnected to IsClientInGame. (has a difference)

Similar issue here

I dont remember but I think that GetClientTeam fails if the client is not in game.

btw you can reduce the code lines to:

Spoiler
__________________

Last edited by Marttt; 03-22-2020 at 10:40.
Marttt is offline
Nezur0s
Junior Member
Join Date: Feb 2020
Old 03-24-2020 , 10:54   Re: For loop stopping at iteration 6
Reply With Quote #3

Thanks it Works !
Nezur0s is offline
Reply


Thread Tools
Display Modes

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 12:48.


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