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

[CS:GO] GetClientTeam() returns incosistent numbers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jamo
Junior Member
Join Date: Aug 2018
Old 03-11-2020 , 16:51   [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #1

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!

Last edited by Jamo; 03-11-2020 at 17:27.
Jamo is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 03-11-2020 , 17:47   Re: [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #2

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.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 03-11-2020 at 17:48.
DJ Tsunami is offline
Vaggelis
Senior Member
Join Date: May 2017
Old 03-11-2020 , 18:39   Re: [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #3

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.
Vaggelis is offline
Jamo
Junior Member
Join Date: Aug 2018
Old 03-12-2020 , 09:15   Re: [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #4

Quote:
Originally Posted by Vaggelis View Post
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.

Last edited by Jamo; 03-12-2020 at 09:17.
Jamo is offline
Jamo
Junior Member
Join Date: Aug 2018
Old 03-12-2020 , 09:15   Re: [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #5

Quote:
Originally Posted by DJ Tsunami View Post
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.
Jamo is offline
Vaggelis
Senior Member
Join Date: May 2017
Old 03-12-2020 , 11:40   Re: [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #6

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. */ 
Vaggelis is offline
Jamo
Junior Member
Join Date: Aug 2018
Old 03-12-2020 , 12:58   Re: [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #7

Quote:
Originally Posted by Vaggelis View Post
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 is offline
Jamo
Junior Member
Join Date: Aug 2018
Old 03-12-2020 , 19:10   Re: [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #8

Guys I really need help with this. I can't find ANY solution to ONLY count players.
Jamo is offline
Vaggelis
Senior Member
Join Date: May 2017
Old 03-13-2020 , 02:48   Re: [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #9

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

Vaggelis is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-13-2020 , 15:22   Re: [CS:GO] GetClientTeam() returns incosistent numbers
Reply With Quote #10

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
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas 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 02:30.


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