AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   CSGO MaxNumPlayersOnCTTeam MaxNumPlayersOnTerrTeam (https://forums.alliedmods.net/showthread.php?t=339107)

Bacardi 08-17-2022 00:39

CSGO MaxNumPlayersOnCTTeam MaxNumPlayersOnTerrTeam
 
I was looking event "switch_team" which only human player can trigger,
this event tell you about
Code:

Server event "switch_team", Tick 24275:
- "numPlayers" = "1"
- "numSpectators" = "0"
- "avg_rank" = "0"
- "numTSlotsFree" = "4"
- "numCTSlotsFree" = "5"

These variables inform you how many free team slots are left, so human player can enter in team T or CT to play.
- CT/T teams max slot number is dynamic, it depends gamemodes maxplayers count and how many map spawn points.

As reminder, when server is using maxplayers_override value, gamemodes maxplayers would not change anymore max player count.

In this plugin sample, command sm_check mimic event "switch_team" calculation.


There are two SDKCalls: MaxNumPlayersOnTerrTeam & MaxNumPlayersOnCTTeam
These return team T and CT maximum slot count, how many players will fit in team. In that map, in that gamemode.

I just share this in here, if someone want test.

PHP Code:


/*
LINUX Signature for MaxNumPlayersOnTerrTeam_sub_B2B7C0:
55 89 E5 83 EC 18 89 5D F8 8B 5D 08 89 75 FC 89 1C 24 E8 ? ? ? ? 84 C0 74 ? 
\x55\x89\xE5\x83\xEC\x18\x89\x5D\xF8\x8B\x5D\x08\x89\x75\xFC\x89\x1C\x24\xE8\x2A\x2A\x2A\x2A\x84\xC0\x74\x2A
     

Linux Signature for MaxNumPlayersOnCTTeam_sub_B23970:
55 89 E5 53 83 EC 14 A1 ? ? ? ? 8B 5D 08 3D ? ? ? ? 74 ? 8B 10 89 04 24 FF 52 40 83 F8 01 
\x55\x89\xE5\x53\x83\xEC\x14\xA1\x2A\x2A\x2A\x2A\x8B\x5D\x08\x3D\x2A\x2A\x2A\x2A\x74\x2A\x8B\x10\x89\x04\x24\xFF\x52\x40\x83\xF8\x01



windows Signature for MaxNumPlayersOnTerrTeam_sub_1041C990:
56 8B F1 8B 0D ? ? ? ? 8B 01 FF 50 20 83 F8 04 75 ? 8B 0D ? ? ? ? 8B 01 FF 50 24 83 F8 01 0F 84 ? ? ? ? 
\x56\x8B\xF1\x8B\x0D\x2A\x2A\x2A\x2A\x8B\x01\xFF\x50\x20\x83\xF8\x04\x75\x2A\x8B\x0D\x2A\x2A\x2A\x2A\x8B\x01\xFF\x50\x24\x83\xF8\x01\x0F\x84\x2A\x2A\x2A\x2A

windows Signature for MaxNumPlayersOnCTTeam_sub_1041CA80:
56 8B F1 8B 0D ? ? ? ? 81 F9 ? ? ? ? 75 ? A1 ? ? ? ? 8B D0 81 F2 ? ? ? ? EB ? 8B 01 FF 50 34 8B 0D ? ? ? ? 8B D0 A1 ? ? ? ? 83 FA 01 74 ? 81 F9 ? ? ? ? 75 ? 35 ? ? ? ? EB ? 8B 01 FF 50 34 83 F8 03 
\x56\x8B\xF1\x8B\x0D\x2A\x2A\x2A\x2A\x81\xF9\x2A\x2A\x2A\x2A\x75\x2A\xA1\x2A\x2A\x2A\x2A\x8B\xD0\x81\xF2\x2A\x2A\x2A\x2A\xEB\x2A\x8B\x01\xFF\x50\x34\x8B\x0D\x2A\x2A\x2A\x2A\x8B\xD0\xA1\x2A\x2A\x2A\x2A\x83\xFA\x01\x74\x2A\x81\xF9\x2A\x2A\x2A\x2A\x75\x2A\x35\x2A\x2A\x2A\x2A\xEB\x2A\x8B\x01\xFF\x50\x34\x83\xF8\x03






*/

#include <sdktools>

enum struct ServerInfo
{
    
int numPlayers;
    
int numSpectators;
    
int numTSlotsFree;
    
int numCTSlotsFree;
    
int numMaxHumans;
}


ServerInfo serverinfo;

Handle hMaxNumPlayersOnTerrTeam;
Handle hMaxNumPlayersOnCTTeam;

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_check"check);
    
HookEventEx("switch_team"switch_team);
}

public 
Action check(int clientint args)
{
    
UpdateServerInfo();
    return 
Plugin_Handled;
}

public 
void OnConfigsExecuted()
{
    
GameData configfile = new GameData("test");

    if(
hMaxNumPlayersOnTerrTeam == null)
    {
        
StartPrepSDKCall(SDKCall_GameRules);

        if(
PrepSDKCall_SetFromConf(configfileSDKConf_Signature"MaxNumPlayersOnTerrTeam"))
            
PrepSDKCall_SetReturnInfo(SDKType_PlainOldDataSDKPass_ByValue);

        
hMaxNumPlayersOnTerrTeam EndPrepSDKCall();
    }

    if(
hMaxNumPlayersOnCTTeam == null)
    {
        
StartPrepSDKCall(SDKCall_GameRules);

        if(
PrepSDKCall_SetFromConf(configfileSDKConf_Signature"MaxNumPlayersOnCTTeam"))
            
PrepSDKCall_SetReturnInfo(SDKType_PlainOldDataSDKPass_ByValue);

        
hMaxNumPlayersOnCTTeam EndPrepSDKCall();
    }

    
delete configfile;

    
UpdateServerInfo();
}



void UpdateServerInfo()
{
    if(
hMaxNumPlayersOnTerrTeam == null || hMaxNumPlayersOnCTTeam == null)
    {
        return;
    }

    
serverinfo.numTSlotsFree SDKCall(hMaxNumPlayersOnTerrTeam);
    
serverinfo.numCTSlotsFree SDKCall(hMaxNumPlayersOnCTTeam);

    
serverinfo.numPlayers 0;
    
serverinfo.numSpectators 0;
    
serverinfo.numMaxHumans GetMaxHumanPlayers();

    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i) || IsFakeClient(i))
            continue;
        
        switch(
GetClientTeam(i))
        {
            case 
0:
                
serverinfo.numPlayers++;
            case 
1:
                
serverinfo.numSpectators++;
            case 
2:
            {
                
serverinfo.numTSlotsFree--;
                
serverinfo.numPlayers++;
            }
            case 
3:
            {
                
serverinfo.numCTSlotsFree--;
                
serverinfo.numPlayers++;
            }
        }
    }


    
PrintToServer("numPlayers %i"serverinfo.numPlayers);
    
PrintToServer("numSpectators %i"serverinfo.numSpectators);
    
PrintToServer("numTSlotsFree %i"serverinfo.numTSlotsFree);
    
PrintToServer("numCTSlotsFree %i"serverinfo.numCTSlotsFree);
    
PrintToServer("numMaxHumans %i"serverinfo.numMaxHumans);
}



public 
void switch_team(Event event, const char[] namebool dontBroadcast)
{
/*
    Server event "switch_team", Tick 9006:
    - "numPlayers" = "1"
    - "numSpectators" = "0"
    - "avg_rank" = "0"
    - "numTSlotsFree" = "11"
    - "numCTSlotsFree" = "12"
*/

    
serverinfo.numPlayers event.GetInt("numPlayers", -1);
    
serverinfo.numSpectators event.GetInt("numSpectators", -1);
    
serverinfo.numTSlotsFree event.GetInt("numTSlotsFree", -1);
    
serverinfo.numCTSlotsFree event.GetInt("numCTSlotsFree", -1);
    
serverinfo.numMaxHumans GetMaxHumanPlayers();


    
PrintToServer("numPlayers %i"serverinfo.numPlayers);
    
PrintToServer("numSpectators %i"serverinfo.numSpectators);
    
PrintToServer("numTSlotsFree %i"serverinfo.numTSlotsFree);
    
PrintToServer("numCTSlotsFree %i"serverinfo.numCTSlotsFree);
    
PrintToServer("numMaxHumans %i"serverinfo.numMaxHumans);




gamedata/test.txt
Code:


"Games"
{
        "csgo"
        {
                "Signatures"
                {
                        "MaxNumPlayersOnCTTeam"
                        {
                                "library"        "server"
                                "windows"        "\x56\x8B\xF1\x8B\x0D\x2A\x2A\x2A\x2A\x81\xF9\x2A\x2A\x2A\x2A\x75\x2A\xA1\x2A\x2A\x2A\x2A\x8B\xD0\x81\xF2\x2A\x2A\x2A\x2A\xEB\x2A\x8B\x01\xFF\x50\x34\x8B\x0D\x2A\x2A\x2A\x2A\x8B\xD0\xA1\x2A\x2A\x2A\x2A\x83\xFA\x01\x74\x2A\x81\xF9\x2A\x2A\x2A\x2A\x75\x2A\x35\x2A\x2A\x2A\x2A\xEB\x2A\x8B\x01\xFF\x50\x34\x83\xF8\x03"
                                "linux"                "\x55\x89\xE5\x53\x83\xEC\x14\xA1\x2A\x2A\x2A\x2A\x8B\x5D\x08\x3D\x2A\x2A\x2A\x2A\x74\x2A\x8B\x10\x89\x04\x24\xFF\x52\x40\x83\xF8\x01"
                        }
                        "MaxNumPlayersOnTerrTeam"
                        {
                                "library"        "server"
                                "windows"        "\x56\x8B\xF1\x8B\x0D\x2A\x2A\x2A\x2A\x8B\x01\xFF\x50\x20\x83\xF8\x04\x75\x2A\x8B\x0D\x2A\x2A\x2A\x2A\x8B\x01\xFF\x50\x24\x83\xF8\x01\x0F\x84\x2A\x2A\x2A\x2A"
                                "linux"                "\x55\x89\xE5\x83\xEC\x18\x89\x5D\xF8\x8B\x5D\x08\x89\x75\xFC\x89\x1C\x24\xE8\x2A\x2A\x2A\x2A\x84\xC0\x74\x2A"
                        }
                }
        }
}


Austin 08-30-2022 03:11

Re: CSGO MaxNumPlayersOnCTTeam MaxNumPlayersOnTerrTeam
 
Bacardi,
can something like this be used to fix the following problem?

The problem:
(Assuming all maps have the required number of spawn points)

The max number of players in a team for CSGO is
maxplayers / 2
Period!

This is different from CS / CZ / CSS
For these games the maxplayers in a team can be up to maxplayers.

This is a problem for my bots servers because I run bots on one team and humans on the other team vs 4-6 bots per human.
For example 4 humans as Ts vs 16 CT bots.
You would think you could rent a 20 slot server.
But for a 20 slots server you get only 10 bots as CT (maxplayers=20 / 2 = 10)

=> You have to rent a 32 slot server! to get 16 bots on a team! <=

I don't need to Get() the number of open slots on a team I need to
OverRide() the number the game engine thinks it has or can allow.

If you know a a way to do this please post an example!
Thank you!

WHY oh WHY did they change this in CSGO to FORCE maxPerTeam to be maxPlayers/2 ?
What was the REASON?

Bacardi 08-30-2022 13:17

Re: CSGO MaxNumPlayersOnCTTeam MaxNumPlayersOnTerrTeam
 
Some convars are hidden, so use sm_cvar command to change below cvars


Code:

mp_limitteams 0
- Max # of players 1 team can have over another (0 disables check)

Code:

mp_autoteambalance 0
- Balance teams when hit limit of mp_teams_unbalance_limit (0 disables check)

Code:

mp_teams_unbalance_limit 0
- Teams are unbalanced when one team has this many more players than the other team. (0 disables check)

Code:

bot_auto_vacate 0
- If nonzero, bots will automatically leave to make room for human players.
This keep one bot less when server is full.
Disable this, server get full by bots also and you can't join in server

Code:

mp_humanteam T
- Restricts human players to a single team {any, CT, T}


Code:

bot_join_team CT
- Determines the team bots will join into. Allowed values: 'any', 'T', or 'CT'.


Code:

bot_quota_mode match
Allowed values: 'normal', 'fill', and 'match'.
If 'fill', the server will adjust bots to keep N players in the game, where N is bot_quota.
If 'match', the server will maintain a 1:N ratio of humans to bots, where N is bot_quo

Code:

bot_quota 4
- Determines the total number of bots in the game.
When mode is match, 1:N ratio of human to bots


...use gamemode_casual_server.cfg (or another game mode cfg) to override Valve game mode settings.

Try those, do those help ?

BeepIsla 08-30-2022 23:16

Re: CSGO MaxNumPlayersOnCTTeam MaxNumPlayersOnTerrTeam
 
Alternatively just do what the leaked source code does: https://github.com/perilouswithadoll...#L12597-L12610

Which is basically just either "maxplayers / 2" or just counting the enabled spawn points

Bacardi 08-31-2022 08:00

Re: CSGO MaxNumPlayersOnCTTeam MaxNumPlayersOnTerrTeam
 
Quote:

Originally Posted by BeepIsla (Post 2787788)
Alternatively just do what the leaked source code does: https://github.com/perilouswithadoll...#L12597-L12610

Which is basically just either "maxplayers / 2" or just counting the enabled spawn points

It's seems to easier to mention, how to do it instead give a code sample,
when we are in Snippets and Tutorials section.

I should have post this "topic" in Discord chat, this forum is getting useless.


All times are GMT -4. The time now is 19:52.

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