06-13-2012, 10:25
Well after many request and now actually having some time for it.
I've made a final new version of the team balancer
changes:
- uses AddonFrame instead of threaded sleeps
- removed threadpools/threading
- removed ingame spam
- removed configuration options (where causing trouble anyway, not re-adding)
- optimized code for optimal performance
The team balancer only balances gamemodes where it matters to have balanced teams.
It checks every 3 minutes, and if the difference between teams is bigger then a 1 player difference, it forces a re-balance.
Download:
Source code:
I will NOT be adding the configuration options again!
If you use and/or like my work please +rep using this button
I've made a final new version of the team balancer
changes:
- uses AddonFrame instead of threaded sleeps
- removed threadpools/threading
- removed ingame spam
- removed configuration options (where causing trouble anyway, not re-adding)
- optimized code for optimal performance
The team balancer only balances gamemodes where it matters to have balanced teams.
It checks every 3 minutes, and if the difference between teams is bigger then a 1 player difference, it forces a re-balance.
Download:
Download (Binary - v2.2) (Click to View)
Source (v2.2) (Click to View)
CSHARP Code
- using System;
- using Addon;
-
- namespace TeamBalancer
- {
- public class TeamBalancer : CPlugin
- {
- public int counter = 1;
- public override void OnServerLoad()
- {
- ServerPrint("[Teambalancer] (2.2) By Pieter (thanks to:JariZ,zxz0O0,Nukem,Cyanide)");
- ServerPrint("[Teambalancer] Visit <a href="http://www.itsmods.com" target="_blank" rel="noopener" class="mycode_url">www.itsmods.com</a> for more great mods/plugins for your MW3 Server!");
- ServerPrint("[Teambalancer] Checks and fixes teambalance every 3 minutes for appropriate gametypes");
- }
-
- public override void OnAddonFrame()
- {
- counter++;
- if ((counter/720) == 1) //checks every 720 addonframes (180 seconds * 4)
- {
- balteam();
- counter = 1;
- }
- }
-
- public override void OnMapChange()
- {
- counter = 1;
- }
-
- public override void OnPreMapChange()
- {
- counter = 1;
- }
-
- public override void OnFastRestart()
- {
- counter = 1;
- }
-
- public void balteam()
- {
- try
- {
- String DVg_gametype = GetDvar("g_gametype");
- if (
- DVg_gametype == "dm" ||
- DVg_gametype == "infect" ||
- DVg_gametype == "jugg" ||
- DVg_gametype == "oic" ||
- DVg_gametype == "gun"
- )
- {
- // no balance
- ServerPrint("[TeamBalancer] Balancer off in gamemode: ("+DVg_gametype+")..");
- }
- else
- {
- int axis = 0;
- int allies = 0;
- int teamdiff1 = 0;
- int teamdiff2 = 0;
- foreach (ServerClient client in GetClients())
- {
- if (client.Team == Teams.Allies) { allies++; }
- else if (client.Team == Teams.Axis) { axis++; }
- }
- teamdiff1 = Math.Abs(allies - axis); //calculate the player difference
- teamdiff2 = Math.Abs(axis - allies); //calculate the player difference
- if (teamdiff1 > 1 || teamdiff2 > 1) // set to difference higher as allowed
- {
- ServerCommand("set scr_teambalance \"1\"");
- }
- else
- {
- ServerPrint("[TeamBalancer] Teams allready in balance!");
- }
- }
- }
- catch (Exception ex2) {
- ServerPrint("[Teambalancer] !(Exception)!: " + ex2);
- }
- }
- }
- }
If you use and/or like my work please +rep using this button