AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [HELP] help with int, for loop... (https://forums.alliedmods.net/showthread.php?t=317432)

iskenderkebab33 07-13-2019 09:01

[HELP] help with int, for loop...
 
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 :3

backwards 07-13-2019 18:03

Re: [HELP] with int for CSGO
 
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.

iskenderkebab33 07-13-2019 19:29

Re: [HELP] with int for CSGO
 
Quote:

Originally Posted by 1337norway (Post 2659008)
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

dustinandband 07-15-2019 23:32

Re: [HELP] help with int, for loop...
 
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);



iskenderkebab33 07-16-2019 05:05

Re: [HELP] help with int, for loop...
 
Quote:

Originally Posted by dustinandband (Post 2659258)
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!

Ilusion9 07-16-2019 06:17

Re: [HELP] help with int, for loop...
 
Quote:

Originally Posted by dustinandband (Post 2659258)
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.

iskenderkebab33 07-16-2019 10:59

Re: [HELP] help with int, for loop...
 
Quote:

Originally Posted by Ilusion9 (Post 2659278)
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

I am inevitable 07-16-2019 12:31

Re: [HELP] help with int, for loop...
 
Quote:

Originally Posted by Ilusion9 (Post 2659278)
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.

dustinandband 07-16-2019 12:37

Re: [HELP] help with int, for loop...
 
Quote:

Originally Posted by Ilusion9 (Post 2659278)
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.

Ilusion9 07-16-2019 13:08

Re: [HELP] help with int, for loop...
 
Quote:

Originally Posted by dustinandband (Post 2659340)
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.


All times are GMT -4. The time now is 22:34.

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