Added !balance options to enable/disable balancer, !putbots auto-disables balancer as needed.

This commit is contained in:
Timo Smit 2016-08-04 19:14:00 +02:00
parent 2524a1be9e
commit 00c487a6ef
3 changed files with 46 additions and 3 deletions

View file

@ -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)

View file

@ -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)")

View file

@ -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