Raised This Month: $12 Target: $400
 3% 

[HELP] help with int, for loop...


Post New Thread Reply   
 
Thread Tools Display Modes
dustinandband
Senior Member
Join Date: May 2015
Old 07-16-2019 , 14:20   Re: [HELP] help with int, for loop...
Reply With Quote #11

Quote:
Originally Posted by Ilusion9 View Post
then you should use only IsClientInGame and !IsFakeClient for PrintScores function. useless verification = waste of memory and time from server processor.
It's not a big deal. There's other plugins that are widely used that have redundant checking every 0.5 seconds.

https://github.com/Attano/L4D2-Compe...pechud.sp#L104

https://github.com/Attano/L4D2-Compe...pechud.sp#L123

https://github.com/Attano/L4D2-Compe...pechud.sp#L536

Last edited by dustinandband; 07-16-2019 at 14:22.
dustinandband is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-16-2019 , 17:06   Re: [HELP] help with int, for loop...
Reply With Quote #12

LMAO. Doesnt think optimisation is a big deal.

There have been numerous threads around the bad habit of a ValidClient function.

Just dont be lazy!

Code:
public void PrintScores() 
{ 
    int i_CTCount, i_TCount; 
     
    for (int i = 1; i <= MaxClients; i++) 
    {     
        if (!IsClientInGame(i))
            continue;

        if (IsFakeClient(i))
            continue;

        if(GetClientTeam(i) == 2) // Terror 
            i_TCount += g_playerspoints[i]; 
             
        if(GetClientTeam(i) == 3) // CT 
            i_CTCount += g_playerspoints[i]; 
    } 

    PrintToChatAll("Team Terror has total %d points.", i_TCount); 
    PrintToChatAll("Team CT has total %d points.", i_CTCount); 
}
__________________

Last edited by Neuro Toxin; 07-17-2019 at 16:34.
Neuro Toxin is offline
dustinandband
Senior Member
Join Date: May 2015
Old 07-16-2019 , 18:08   Re: [HELP] help with int, for loop...
Reply With Quote #13

I wasn't saying it's not a big deal in every case. I'm saying getting in a tissy over one function that has a redundant check is dumb.

e.g. my version of the specHUD plugin (designed for survival) is optimized cause the HUD gets redrawn every 3.0 seconds and wanted to speed up that loop:

Spoiler


In OP's case - it's probably a command or something that doesn't get executed that often. Really isn't a big deal if you have a redundant check if the client's index is above 0 and != MaxClients, especially if you use that function for more than one thing and want to avoid errors just in-case.
dustinandband is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 07-17-2019 , 06:05   Re: [HELP] help with int, for loop...
Reply With Quote #14

PHP Code:
!IsClientConnected(i) || !IsClientInGame(i
also, there are topics about these two functions, if you check IsClientInGame, then checking IsClientConnected is useless.
IsClientInGame = IsClientConnected + InGame

these things are small things, but if you have 10, 15 plugins doing useless things, all together can cause problems for your server.
__________________

Last edited by Ilusion9; 07-17-2019 at 06:07.
Ilusion9 is offline
Dr.Doctor
AlliedModders Donor
Join Date: Feb 2017
Location: Hong Kong
Old 07-17-2019 , 18:18   Re: [HELP] help with int, for loop...
Reply With Quote #15

Overuse of IsValidClient will not cause any problem on your server.

But of course, avoid using IsValidClient makes the code cleaner.
__________________
Dr.Doctor is offline
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 07-21-2019 , 06:33   Re: [HELP] help with int, for loop...
Reply With Quote #16

Quote:
Originally Posted by Neuro Toxin View Post
LMAO. Doesnt think optimisation is a big deal.

There have been numerous threads around the bad habit of a ValidClient function.

Just dont be lazy!

Code:
public void PrintScores() 
{ 
    int i_CTCount, i_TCount; 
     
    for (int i = 1; i <= MaxClients; i++) 
    {     
        if (!IsClientInGame(i))
            continue;

        if (IsFakeClient(i))
            continue;

        if(GetClientTeam(i) == 2) // Terror 
            i_TCount += g_playerspoints[i]; 
             
        if(GetClientTeam(i) == 3) // CT 
            i_CTCount += g_playerspoints[i]; 
    } 

    PrintToChatAll("Team Terror has total %d points.", i_TCount); 
    PrintToChatAll("Team CT has total %d points.", i_CTCount); 
}
and how to get the highst and the lowest points from the team like: PrinToChatAll "Team CT: Player X has the highst points (X points) and Player X has the lowest ponit (X points)" and the same from Team Terror...
iskenderkebab33 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-21-2019 , 16:39   Re: [HELP] help with int, for loop...
Reply With Quote #17

Add variables for lowest/highest score of each team for the client loop.

Code:
int i_TMin, i_TMax;
int i_TMinClient, i_TMaxClient
Initialise the mins to a high value a player couldn't get.

Code:
i_TMin = 9999;
Check and store...

Code:
if (GetClientTeam(i) == CS_TEAM_T)
{
    i_TCount += g_playerspoints[i];
    
    if (g_playerspoints[i] < i_TMin)
    {
        i_TMin = g_playerspoints[i];
        i_TMinClient = i;
    }
    else if (g_playerspoints[i] == i_TMin)
    {
        // you probably want to figure out who will be based lower on another stat
    }
}
And print.

Code:
PrintToChatAll("Team T: player %N has the lowest points (%d points).", i_TMinClient, i_TMin);
Do the opposite for max.

Do it again for CS_TEAM_CT.
__________________

Last edited by Neuro Toxin; 07-21-2019 at 16:47.
Neuro Toxin is offline
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 07-22-2019 , 01:45   Re: [HELP] help with int, for loop...
Reply With Quote #18

Quote:
Originally Posted by Neuro Toxin View Post
Add variables for lowest/highest score of each team for the client loop.

Code:
int i_TMin, i_TMax;
int i_TMinClient, i_TMaxClient
Initialise the mins to a high value a player couldn't get.

Code:
i_TMin = 9999;
Check and store...

Code:
if (GetClientTeam(i) == CS_TEAM_T)
{
    i_TCount += g_playerspoints[i];
    
    if (g_playerspoints[i] < i_TMin)
    {
        i_TMin = g_playerspoints[i];
        i_TMinClient = i;
    }
    else if (g_playerspoints[i] == i_TMin)
    {
        // you probably want to figure out who will be based lower on another stat
    }
}
And print.

Code:
PrintToChatAll("Team T: player %N has the lowest points (%d points).", i_TMinClient, i_TMin);
Do the opposite for max.

Do it again for CS_TEAM_CT.
thanks.
iskenderkebab33 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 03:56.


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