From 00c487a6ef293802b842c657e7b75ca9bc46a367 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Thu, 4 Aug 2016 19:14:00 +0200 Subject: [PATCH] Added !balance options to enable/disable balancer, !putbots auto-disables balancer as needed. --- luascripts/admin/balancer.lua | 18 +++++++++++++++++- luascripts/commands/admin/balance.lua | 24 ++++++++++++++++++++++-- luascripts/commands/admin/putbots.lua | 7 +++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/luascripts/admin/balancer.lua b/luascripts/admin/balancer.lua index 1ae9910..a58df8c 100644 --- a/luascripts/admin/balancer.lua +++ b/luascripts/admin/balancer.lua @@ -34,6 +34,8 @@ balancer.BALANCE_LAST_JOINED = 1 balancer.BALANCE_ONLY_DEAD = 2 balancer.BALANCE_NOT_OBJECTIVE = 4 +local balancerTimer = nil + local lastJoined = {[constants.TEAM_AXIS] = {}, [constants.TEAM_ALLIES] = {}, [constants.TEAM_SPECTATORS] = {}} local evenerCount = 0 @@ -155,9 +157,23 @@ function balancer.onclientdisconnect(clientId) end events.handle("onClientDisconnect", balancer.onclientdisconnect) +function balancer.enable() + balancerTimer = timers.add(balancer.balance, settings.get("g_evenerInterval") * 1000, 0, false, false) +end + +function balancer.disable() + timers.remove(balancerTimer) + + balancerTimer = nil +end + +function balancer.isRunning() + return (balancerTimer ~= nil) +end + function balancer.oninit() if settings.get("g_balancedteams") ~= 0 and settings.get("g_evenerInterval") > 0 then - timers.add(balancer.balance, settings.get("g_evenerInterval") * 1000, 0, false, false) + balancer.enable() end end events.handle("onGameInit", balancer.oninit) diff --git a/luascripts/commands/admin/balance.lua b/luascripts/commands/admin/balance.lua index 7e35462..ccd2b7c 100644 --- a/luascripts/commands/admin/balance.lua +++ b/luascripts/commands/admin/balance.lua @@ -19,8 +19,28 @@ local commands = require "luascripts.wolfadmin.commands.commands" local balancer = require "luascripts.wolfadmin.admin.balancer" function commandBalance(clientId, cmdArguments) - balancer.balance(true, (cmdArguments[1] and cmdArguments[1] == "force")) - + if cmdArguments[1] == "enable" then + if not balancer.isRunning() then + balancer.enable() + + et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dbalancer: ^9balancer enabled.\";") + else + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dbalancer: ^9balancer is already running.\";") + end + elseif cmdArguments[1] == "disable" then + if balancer.isRunning() then + balancer.disable() + + et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dbalancer: ^9balancer disabled.\";") + else + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dbalancer: ^9balancer was not running.\";") + end + elseif cmdArguments[1] == "force" then + balancer.balance(true, true) + else + balancer.balance(true, false) + end + return true end commands.addadmin("balance", commandBalance, "p", "either asks the players to even up or evens them by moving or shuffling players", "^2!balance ^9(^hforce^9)") \ No newline at end of file diff --git a/luascripts/commands/admin/putbots.lua b/luascripts/commands/admin/putbots.lua index 7ce2cc9..3732be6 100644 --- a/luascripts/commands/admin/putbots.lua +++ b/luascripts/commands/admin/putbots.lua @@ -17,6 +17,7 @@ local constants = require "luascripts.wolfadmin.util.constants" local util = require "luascripts.wolfadmin.util.util" +local balancer = require "luascripts.wolfadmin.admin.balancer" local commands = require "luascripts.wolfadmin.commands.commands" local bots = require "luascripts.wolfadmin.game.bots" @@ -41,6 +42,12 @@ function commandPutBots(clientId, cmdArguments) bots.put(team) et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dputbots: ^9all bots were set to ^7"..teamname.." ^9team.\";") + + if (team == constants.TEAM_AXIS or team == constants.TEAM_ALLIES) and balancer.isRunning() then + balancer.disable() + + et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dbalancer: ^9balancer disabled.\";") + end return true end