This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Solved [CSGO] Need Help designing a plugin to handle team joins on bot server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Austin
Senior Member
Join Date: Oct 2005
Old 04-02-2023 , 20:14   [CSGO] Need Help designing a plugin to handle team joins on bot server
Reply With Quote #1

I have a bot server where I force humans to the same team.
This can be easily be handled using
mp_humanteam t/ct/any

What I would like instead is to write a plug in where the first humans to join
the server can pick the team to join t/ct and then after that all other humans
connecting are forced to this team the first human to join picked.

I am thinking I could look for the first human to connect and then set mp_humanteam to the team they choose
and then
when all humans disconnect reset this back to mp_humanteam any

What I need help with is
What is a sure way to know who the first human to join is and what team they selected.

Do all client disconnect on map change? And when to reset mp_humanteam back to = any

And how to handle the case where if several humans are joining the server and they
are all looking at the team join screen what happens after the first human
picks a team? Will humans that already had the team join screen up still be able
to pick a different team even after the first human connected and set the cvar mp_humanteam?

How to make sure considering timing issues all humans are forced to the same
team.

And finally how to make all humans joining after the first humans picks
the team to auto join without seeing the choose team screen first.

Last edited by Austin; 04-05-2023 at 03:46.
Austin is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 04-03-2023 , 11:14   Re: [CSGO] Need Help designing a plugin to handle team joins on bot server
Reply With Quote #2

PHP Code:
#pragma semicolon 1
#pragma newdecls required

static const char TEAMS[][] = {"any""""t""ct"};

ConVar
    hCvar
;
bool
    bTeam
;
int
    iFlags
;

public 
void OnPluginStart()
{
    if(!(
hCvar FindConVar("mp_humanteam"))) SetFailState("Can't find cvar 'mp_humanteam'!");

    
iFlags hCvar.Flags;
    
HookEvent("player_team"Event_Team);
}

public 
void OnMapStart()
{
    
SetHumanTeam();
}

public 
void Event_Team(Event event, const char[] namebool dontBroadcast)
{
    if(
bTeam || event.GetBool("disconnect"))
        return;

    
int buffer GetClientOfUserId(event.GetInt("userid"));
    if(
buffer && IsClientInGame(buffer) && !IsFakeClient(buffer) && (buffer event.GetInt("team")) > 1)
        
SetHumanTeam(buffer);
}

public 
void OnClientDisconnect_Post()
{
    for(
int i 1<= MaxClientsi++) if(IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) > 1) return;

    
SetHumanTeam();
}

stock void SetHumanTeam(int team 0)
{
    
bTeam = !!team;

    
hCvar.Flags iFlags;
    
hCvar.SetString(TEAMS[team], true);
    
hCvar.Flags iFlags FCVAR_CHEAT;
}

public 
void OnPluginEnd()
{
    
hCvar.Flags iFlags;
    
hCvar.SetString(TEAMS[0], true);

__________________

Last edited by Grey83; 04-03-2023 at 11:18.
Grey83 is offline
Austin
Senior Member
Join Date: Oct 2005
Old 04-04-2023 , 16:54   Re: [CSGO] Need Help designing a plugin to handle team joins on bot server
Reply With Quote #3

Grey83,
Thank you for your time, knowledge, and energy to help me.
With this reply you got me to 95% of what I wanted.

I could have been a little clearer on what I wanted.
Here is a simplified version of the requirements.

I want to set the conv mp_humanteam in this way:

1) No humans on the server set
mp_humanteam "any"

2) First human to join the server set
mp_humanteam = The team the first human to join selected = "t"/"ct"

3) For any human that isn't the first to connect DON'T SHOW the choose team screen
and just automatically connect them to the mp_humanteam team.

Everything is working as expected with the following plugin,
except I can't figure out how to implement #3 above...

The Sourcemod community is totally awesome!
Obviously....
Thanks!

PHP Code:
#include <sourcemod>
#include <sdktools>
#pragma semicolon 1
#pragma newdecls required

ConVar mp_humanteam;
bool firstHumanToJoin true;

public 
void OnPluginStart()
{
    
mp_humanteam FindConVar("mp_humanteam");
    
    
HookEvent("player_team"Event_Team);
    
HookEvent("player_connect_full"Event_PlayerConnectFull);

    
SetConVarString(mp_humanteam"any");
    
firstHumanToJoin true;

    
PrintToServer("ABS_CSGO_TeamSelect Loaded");
}

public 
void Event_PlayerConnectFull(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
// check if the client is valid and not assigned to a team yet
    
if (client && !GetClientTeam(client)) 
    {
        
// if they are not the first human to join 
        // auto place them on the human team
        // this also bypasses the team join screen
        
if(!firstHumanToJoin)
        {
            
char team[64];
            
GetConVarString(mp_humanteamteamsizeof(team));
            if(
StrEqual(team"t"false))
                
ChangeClientTeam(client2);
            else if(
StrEqual(team"ct"false))
                
ChangeClientTeam(client3);
        }
    }
}

public 
void Event_Team(Event event, const char[] namebool dontBroadcast)
{
    if(
event.GetBool("disconnect"))
        return;

    
int userid GetClientOfUserId(event.GetInt("userid"));
    if(
userid &&
        
IsClientInGame(userid) &&
        !
IsFakeClient(userid) &&
        
firstHumanToJoin    &&
        (
event.GetInt("team")) > 1)
    {
        if (
event.GetInt("team") == 2)
            
SetConVarString(mp_humanteam"t");
        else if (
event.GetInt("team") == 3)
            
SetConVarString(mp_humanteam"ct");

        
firstHumanToJoin false;
    }
}

public 
void OnMapStart()
{
    
SetConVarString(mp_humanteam"any");
    
firstHumanToJoin true;
}

public 
void OnPluginEnd()
{
    
SetConVarString(mp_humanteam"any");
    
firstHumanToJoin true;


Last edited by Austin; 04-05-2023 at 03:41.
Austin is offline
Austin
Senior Member
Join Date: Oct 2005
Old 04-05-2023 , 03:45   Re: [CSGO] Need Help designing a plugin to handle team joins on bot server
Reply With Quote #4

I got it working and updated the code above.

1) First human to join sees the team join screen and can pick the team.

2)
a) If anyone is still also at the team join screen they will only be able to pick the same team as the first person.
b) If they let the team join screen time out they will be automaticially placed on the human team.

3) If someone connects to the server after a human is already on they will not see the team join screen and they will be automaticially placed on the human team!

tx
Again.

Last edited by Austin; 04-05-2023 at 03:47.
Austin is offline
Reply



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 12:21.


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