AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [CS:GO] GetClientTeam() returns incosistent numbers (https://forums.alliedmods.net/showthread.php?t=322012)

Jamo 03-11-2020 16:51

[CS:GO] GetClientTeam() returns incosistent numbers
 
Hey there.

I'm currently working on a plugin that is supposed to automatically start the knife round once all players all connected. After that the winning team can decide !switch or !stay and so on... You know the procedure.
Some of the plugins features are working fine, but I struggle to count the players in order to determine when the knife round has to start.

My current counter works like this (just a small snippet out of a big .sp. Pls ignore non-declared variables and so on):
PHP Code:

AddCommandListener(Listener_JoinTeam"jointeam");

public 
Action Listener_JoinTeam(int client, const char[] commandint args) {
        
/* DEBUG */
    
int clientTeam GetClientTeam(client);
    
PrintToChatAll("TEAM: %d"clientTeam);
        
/* ------- */
    
if(GetClientTeam(client) == || GetClientTeam(client) == 2) {
        if( 
GetClientCount(true) < 10 && wins_t == && wins_ct == && kniferound_happened == false) {
              
int currPlayerCount;
              
currPlayerCount GetClientCount(true);
            
PrintToChatAll("Wating till all players are connected! Currently: %d / 10",currPlayerCount);
          } else if(
GetClientCount(true) == 10 && wins_t == && wins_ct == && kniferound_happened == false) {
            
PrintHintTextToAll("!!! Game starting !!!");
            
ServerCommand("exec kniferound.cfg");
            
HookEvent("round_end"KnifeEndedEventHookMode_PostNoCopy);
            
PrintToChatAll("\x10!!! KNIFE !!!\x01");
            
PrintToChatAll("\x10!!! KNIFE !!!\x01");
            
PrintToChatAll("\x10!!! KNIFE !!!\x01");    
          }
    }


Explanation:
The code above the first if statement is just for debugging purposes. I'll come back to that later.
The first if statement should check rather the player joined a team or if he's a spectator. I don't want to count connects if they join the spectators!!
So, now I come back to the debug part.
If you run this on a server, you'll notice that the returned number are inconsistent!

My testing setup:
- Laptop
- CS:GO Server on Debian 10 VM
- Running CS:GO, joined the Server
- Main PC
- Running CS:GO, joined the Server

Testing procedure:
I switched teams on the Laptop, as well as the Main PC, and checked the returned numbers in the chat.

Results (in the order I tested):
Joining T -> Returned Number: 3
Joining CT -> Returned Number: 2
Joining T -> Returned Number: 3
Joining CT -> Returned Number: 2
(so far so good)
Joining Spec -> Returned Number: 3
Joining CT -> Returned Number: 1

I think you now got a pretty good look at my issue.

I would be SO glas if somebody knows a fix for that!

Thanks in advance! :)

DJ Tsunami 03-11-2020 17:47

Re: [CS:GO] GetClientTeam() returns incosistent numbers
 
PHP Code:

if(GetClientTeam(client) == || GetClientTeam(client) == 2) { 

Shouldn't this be 2 and 3 (T and CT)?

And maybe you want GetTeamClientCount to only count players on T and CT.

Vaggelis 03-11-2020 18:39

Re: [CS:GO] GetClientTeam() returns incosistent numbers
 
Well, you can use if(GetClientTeam(client) > 1), also if you have spectators in-game GetClientCount may return them too, im not sure i have never used that function. Try the classic loop... <= MaxClients to count them.

Jamo 03-12-2020 09:15

Re: [CS:GO] GetClientTeam() returns incosistent numbers
 
Quote:

Originally Posted by Vaggelis (Post 2686639)
Well, you can use if(GetClientTeam(client) > 1), also if you have spectators in-game GetClientCount may return them too, im not sure i have never used that function. Try the classic loop... <= MaxClients to count them.

"GetClientCount" also counts spectators. That's why I have to go through all that...

Edit: "if(GetClientTeam(client) > 1)". Pls see my initial post. You can see there, that even a CT showed up as Team ID 1.

Jamo 03-12-2020 09:15

Re: [CS:GO] GetClientTeam() returns incosistent numbers
 
Quote:

Originally Posted by DJ Tsunami (Post 2686635)
PHP Code:

if(GetClientTeam(client) == || GetClientTeam(client) == 2) { 

Shouldn't this be 2 and 3 (T and CT)?

And maybe you want GetTeamClientCount to only count players on T and CT.

Changing the if-statements wouldn't do anything to the fact that the numbers are inconsistent.

Vaggelis 03-12-2020 11:40

Re: [CS:GO] GetClientTeam() returns incosistent numbers
 
I guess you check their team too early with your way
PHP Code:

#define CS_TEAM_NONE        0   /**< No team yet. */
#define CS_TEAM_SPECTATOR   1   /**< Spectators. */
#define CS_TEAM_T           2   /**< Terrorists. */
#define CS_TEAM_CT          3   /**< Counter-Terrorists. */ 


Jamo 03-12-2020 12:58

Re: [CS:GO] GetClientTeam() returns incosistent numbers
 
Quote:

Originally Posted by Vaggelis (Post 2686717)
I guess you check their team too early with your way
PHP Code:

#define CS_TEAM_NONE        0   /**< No team yet. */
#define CS_TEAM_SPECTATOR   1   /**< Spectators. */
#define CS_TEAM_T           2   /**< Terrorists. */
#define CS_TEAM_CT          3   /**< Counter-Terrorists. */ 


I have already implemented that in my code. I can confirm that it works because I am able to get the team scores.

Jamo 03-12-2020 19:10

Re: [CS:GO] GetClientTeam() returns incosistent numbers
 
Guys I really need help with this. I can't find ANY solution to ONLY count players.

Vaggelis 03-13-2020 02:48

Re: [CS:GO] GetClientTeam() returns incosistent numbers
 
PHP Code:

if(CountPlayers() == 10)
{
    ...


PHP Code:

int CountPlayers()
{
    
int count
    
    
for(int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && GetClientTeam(i) > 1)
        {
            
count++
        }
    }
    
    return 
count



Dragokas 03-13-2020 15:22

Re: [CS:GO] GetClientTeam() returns incosistent numbers
 
Isn't it a timing issue? So, listening for that command returned for you non-expected result, before actual join the team.
Consider using "player_team" event.

Or re-write logic entirelly, round_start -> CreateTimer + above Vaggelis code.
Or [ANY] Wait Connection


All times are GMT -4. The time now is 00:26.

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