AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [CS:GO] How to get team count ? CT/T (https://forums.alliedmods.net/showthread.php?t=339009)

Audite 08-09-2022 11:41

[CS:GO] How to get team count ? CT/T
 
Hi! I'm trying to create my own beacon plugin that checks how many T are left and if only 1 left then add beacon on the last T client.

Code:

public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast){
        for (int i = 1; i <= MaxClients; i++)
        {
                int iTeam;

                // Skip bots or non connected indexes.
                if (!IsClientConnected(i) || IsFakeClient(i))
                        continue;

                iTeam = GetClientTeam(i);

                if(iTeam == CS_TEAM_T){
                        //CHECK HOW MANY ALIVE, IF 1 LEFT PUT BEACON ON THE CLIENT
                }

        }
}

I'm using death hook for reason that if there is 1 player in T and 1 in CT it does not activate.

I'm completely new to sourcepawn and trying to figure stuff out :D Thanks in advance.

Marttt 08-09-2022 17:39

Re: [CS:GO] How to get team count ? CT/T
 
Didn't test but would be something like this.
PHP Code:

    int aliveCTCount;
    
int aliveTCount;
    
int lastTClient;
    
    for (
int client 1client <= MaxClientsclient++)
    {
        if (!
IsClientInGame(client))
            continue;
        
        if (
IsFakeClient(client))
            continue;
        
        if (!
IsPlayerAlive(client))
            continue;
        
        if (
GetClientTeam(client) == CS_TEAM_CT)
        {
            
aliveCTCount++;
        }
        else if (
GetClientTeam(client) == CS_TEAM_T)
        {
            
aliveTCount++;
            
lastTClient client;
        }
    }
    
    if (
aliveCTCount == && aliveTCount == 1)
    {
        
PerformBeacon(lastTClient//Your logic here
    



Bacardi 08-10-2022 05:40

Re: [CS:GO] How to get team count ? CT/T
 
For readable code, above post is good example.



This example is just... with trick.
PHP Code:


public void OnPluginStart()
{
    
HookEvent("player_death"player_death);
}

public 
void player_death(Event event, const char[] namebool dontBroadcast)
{
    
int lastT = -1;
    
int CTcount 0;
    
int team;

    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i))
            continue;
        
        
team GetClientTeam(i);
        
        if(
team || !IsPlayerAlive(i))
            continue;



        if(
team == 2)
        {
            if(
lastT == -1)
            {
                
// We store player index in variable, first time.
                
lastT i;
            }
            else
            {
                
// When there are more than one T alive in team, this variable will get reset (-2)
                
lastT = -2;
            }
        }
        else
        {
            
CTcount++;
        }
    }

    if(
lastT && CTcount 1)
    {
        
ServerCommand("sm_beacon #%i"GetClientUserId(lastT));
    }



Grey83 08-10-2022 13:01

Re: [CS:GO] How to get team count ? CT/T
 
Bacardi, we can improve the algorithm a little more:
PHP Code:

public void OnPluginStart()
{
    
HookEvent("player_death"Event_DeathEventHookMode_PostNoCopy);
}

public 
void Event_Death(Event event, const char[] namebool dontBroadcast)
{
    
int lastTCTcount;
    for(
int i 1team<= MaxClientsi++) if(IsClientInGame(i) && (team GetClientTeam(i)) > && IsPlayerAlive(i))
    {
        if(
team == 2)
        {
            if(!
lastTlastT i;    // We store player index in variable, first time.
            
else if(lastT) return;    // More than one alive terrorist. No more need checks.
        
}
        else 
CTcount++;
    }

    if(
CTcount 1ServerCommand("sm_beacon #%i"GetClientUserId(lastT));



Bacardi 08-10-2022 13:32

Re: [CS:GO] How to get team count ? CT/T
 
That for loop and if statement is wierdest thing I have seen in web :D

Marttt 08-10-2022 14:35

Re: [CS:GO] How to get team count ? CT/T
 
Micro-optimizations like this don't bring many advantages.
Readability and a clean code, IMO - based IRL daily experience - should be a priority instead of the code lines amount, especially in a death hook event.
(unless you are in a big and repeatable loop)
But, EventHookMode_PostNoCopy was a good catch.
Anyway, all snippets are good examples of how to achieve what OP wants.

Audite 08-20-2022 21:15

Re: [CS:GO] How to get team count ? CT/T
 
Thank you everyone. I got to see all the possible ways to do it! Thanks!


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

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