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[] command, int args) {
/* DEBUG */
int clientTeam = GetClientTeam(client);
PrintToChatAll("TEAM: %d", clientTeam);
/* ------- */
if(GetClientTeam(client) == 1 || GetClientTeam(client) == 2) {
if( GetClientCount(true) < 10 && wins_t == 0 && wins_ct == 0 && 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 == 0 && wins_ct == 0 && kniferound_happened == false) {
PrintHintTextToAll("!!! Game starting !!!");
ServerCommand("exec kniferound.cfg");
HookEvent("round_end", KnifeEnded, EventHookMode_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!