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

Solved [TF2-REQ] Rebalance bots when a player switches teams


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Yemto
New Member
Join Date: Feb 2021
Old 02-10-2021 , 10:17   [TF2-REQ] Rebalance bots when a player switches teams
Reply With Quote #1

I have been looking for a plugin that does this, but haven't found any. I have mp_teams_unbalance_limit set to 0 on my server so players can switch freely. But when they do, I want to check if the teams are uneven, and if they are, a bot is kicked/switched to even them out.

Edit: It's far from perfect, but after searching around on the internet, I managed to create something that worked (https://pastebin.com/aydmR1Hr). I think I'll keep working on it, so I can learn making my own plugins instead.

Last edited by Yemto; 02-12-2021 at 15:44.
Yemto is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 02-10-2021 , 23:51   Re: [TF2-REQ] Rebalance bots when a player switches teams
Reply With Quote #2

I made something similar for my server. Admins can type the command !balance to balance the teams. It's useful for when players voted for botsvshumans and realize they are in over their head. They can then vote for team balance which launches !balance.

Your code kicks Bots when the player count is uneven. The code below does nothing unless the !balance command is used. It then moves players to different teams in an effort to balance the teams evenly. The code isn't complicated and works well for my needs. Maybe it will help you.

PHP Code:
#include <sourcemod> 

#pragma newdecls required

public Plugin myinfo 
{
    
name "Balance Team",
    
author "PC Gamer",
    
description "Place equal number of Players on each team",
    
version "PLUGIN_VERSION 1.0",
}

public 
void OnPluginStart()

    
RegAdminCmd("sm_balance"Command_balteamADMFLAG_SLAY"Balance the Players on Each Team");
}

public 
Action Command_balteam(int clientint args)
{
    
int pcount 1
    
for(int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && (pcount == 0))
        {
            
ChangeClientTeam(i2);  //change player to Red Team
        
}
        if (
IsClientInGame(i) && (pcount == 1)) 
        {
            
ChangeClientTeam(i3);  //change player to Blue Team
        
}
        if (
IsClientInGame(i))
        {
            
pcount++;
        }
    }
    return 
Plugin_Handled;        


Last edited by PC Gamer; 02-10-2021 at 23:52.
PC Gamer is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-11-2021 , 06:51   Re: [TF2-REQ] Rebalance bots when a player switches teams
Reply With Quote #3

I have a plugin for moving bots between teams when a human player requests a team change, for what it's worth.

Only designed to work in fill mode, bots aren't kicked.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Yemto
New Member
Join Date: Feb 2021
Old 02-11-2021 , 10:48   Re: [TF2-REQ] Rebalance bots when a player switches teams
Reply With Quote #4

Quote:
Originally Posted by nosoop View Post
I have a plugin for moving bots between teams when a human player requests a team change, for what it's worth.

Only designed to work in fill mode, bots aren't kicked.
Thanks, this was exactly what I was looking for, and much cleaner than what I was working on.
Yemto is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-11-2021 , 11:18   Re: [TF2-REQ] Rebalance bots when a player switches teams
Reply With Quote #5

Quote:
Originally Posted by Yemto View Post
Thanks, this was exactly what I was looking for, and much cleaner than what I was working on.
Glad to help. I suggest reading over it and trying to understand how it works; hope you continue learning how to write plugins!

(The documentation on it is a bit sparse, will dust it off and commit some documentation / explanation when I have the time later today.)
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop 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 07:05.


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