Raised This Month: $32 Target: $400
 8% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 07-13-2019 , 09:01   [HELP] help with int, for loop...
Reply With Quote #1

Hello, i have a int
PHP Code:
int g_playerspoints[MAXPLAYERS+1]; 
for every player and for every kill the player gets more points, now i will do this:

all player has different points, how can i get the total points of a team Terror and CT and print it to chat like: "Team Terror has total: X points and team CT has total X points"
and how can i get the lowest and highest points from a team like: print to chat "Team Terror: player X is the first with x points" and "Team Terror: player X has the lowest points" and also with CT.

would be happy if someone can help me.. thanks

Last edited by iskenderkebab33; 07-13-2019 at 09:03.
iskenderkebab33 is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 07-13-2019 , 18:03   Re: [HELP] with int for CSGO
Reply With Quote #2

Use a for loop in all these situations. Loop through every possible player slot on the server and check for valid players, if they are valid you can then add to a temp variable var += g_playerspoints[client] and get a total at the end. For lowest/highest score you will loop through all players with a temp variable again and check if < or > previous highest or lowess. Then you set the new lowest record to that variable along with a second variable which keeps track of which player had the lowest/highest.
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 07-13-2019 , 19:29   Re: [HELP] with int for CSGO
Reply With Quote #3

Quote:
Originally Posted by 1337norway View Post
Use a for loop in all these situations. Loop through every possible player slot on the server and check for valid players, if they are valid you can then add to a temp variable var += g_playerspoints[client] and get a total at the end. For lowest/highest score you will loop through all players with a temp variable again and check if < or > previous highest or lowess. Then you set the new lowest record to that variable along with a second variable which keeps track of which player had the lowest/highest.
so i need a for loop for both teams like:

PHP Code:
for (int i 1<= MaxClientsi++)
{
    if (
IsValidClient(i))
    {
        if(
GetClientTeam(i) == 2// Terror
        
{
            
g_playerspoints[i]+=;
            
            
PrinToChatAll("Team Terror has total %d points."g_playerspoints[i]);
        }
        
        if(
GetClientTeam(i) == 3// CT
        
{
            
g_playerspoints[i]+=;
            
            
PrinToChatAll("Team CT has total %d points."g_playerspoints[i]);
        }
    }

right? if thats wrong, can you show me a example pls

Last edited by iskenderkebab33; 07-13-2019 at 19:30.
iskenderkebab33 is offline
dustinandband
Senior Member
Join Date: May 2015
Old 07-15-2019 , 23:32   Re: [HELP] help with int, for loop...
Reply With Quote #4

You'd do something like this

PHP Code:
public void PrintScores()
{
    
int i_CTCounti_TCount;
    
    for (
int i 1<= MaxClientsi++)
    {    
        if (
IsValidClient(i))
        {
            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);
}

public 
bool IsValidClient(int client)
{
    return 
client <= MaxClients && IsClientInGame(client) && IsClientConnected(client) && !IsFakeClient(client);

dustinandband is offline
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 07-16-2019 , 05:05   Re: [HELP] help with int, for loop...
Reply With Quote #5

Quote:
Originally Posted by dustinandband View Post
You'd do something like this

PHP Code:
public void PrintScores()
{
    
int i_CTCounti_TCount;
    
    for (
int i 1<= MaxClientsi++)
    {    
        if (
IsValidClient(i))
        {
            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);
}

public 
bool IsValidClient(int client)
{
    return 
client <= MaxClients && IsClientInGame(client) && IsClientConnected(client) && !IsFakeClient(client);

thanks!
iskenderkebab33 is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 07-16-2019 , 06:17   Re: [HELP] help with int, for loop...
Reply With Quote #6

Quote:
Originally Posted by dustinandband View Post
You'd do something like this

PHP Code:
public void PrintScores()
{
    
int i_CTCounti_TCount;
    
    for (
int i 1<= MaxClientsi++)
    {    
        if (
IsValidClient(i))
        {
            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);
}

public 
bool IsValidClient(int client)
{
    return 
client <= MaxClients && IsClientInGame(client) && IsClientConnected(client) && !IsFakeClient(client);

you loop through players from 1 to MaxClients and then you check if the player's index is between 1 and MaxClients? that's a waste of time.
__________________

Last edited by Ilusion9; 07-16-2019 at 06:18.
Ilusion9 is offline
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 07-16-2019 , 10:59   Re: [HELP] help with int, for loop...
Reply With Quote #7

Quote:
Originally Posted by Ilusion9 View Post
you loop through players from 1 to MaxClients and then you check if the player's index is between 1 and MaxClients? that's a waste of time.
what do you mean? i don't understand
iskenderkebab33 is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-16-2019 , 12:31   Re: [HELP] help with int, for loop...
Reply With Quote #8

Quote:
Originally Posted by Ilusion9 View Post
you loop through players from 1 to MaxClients and then you check if the player's index is between 1 and MaxClients? that's a waste of time.
What do you mean waste of time?

Adding an extra if statement, exculding invalid player indexes is a waste of time? Well so be it. I bet he'd prefer "wasting time", than getting error logs.
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
dustinandband
Senior Member
Join Date: May 2015
Old 07-16-2019 , 12:37   Re: [HELP] help with int, for loop...
Reply With Quote #9

Quote:
Originally Posted by Ilusion9 View Post
you loop through players from 1 to MaxClients and then you check if the player's index is between 1 and MaxClients? that's a waste of time.
I do it Incase the function gets used elsewhere, so you don’t have to write another function that checks if the client index is above 0.
dustinandband is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 07-16-2019 , 13:08   Re: [HELP] help with int, for loop...
Reply With Quote #10

Quote:
Originally Posted by dustinandband View Post
I do it Incase the function gets used elsewhere, so you don’t have to write another function that checks if the client index is above 0.
then you should use only IsClientInGame and !IsFakeClient for PrintScores function. useless verification = waste of memory and time from server processor.
__________________
Ilusion9 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:06.


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