Hi Everyone!
I found a balance (LUA) script for ET, but unfortunately only works when there are no bots on the server.
Here’s the full script:
-- original script by .harald http://etpub.org/viewtopic.php?f=10&t=45
-- pheno: fixed the use of removed table.getn to run with Lua 5.2 API (ETpub > 0.9.1)
unevenDiff = 2
max_unevenTime = 20
max_unevenDiff = 4
axisPlayers = {}
alliedPlayers = {}
unevenTime = -1
function et_RunFrame( levelTime )
local numAlliedPlayers = #alliedPlayers
local numAxisPlayers = #axisPlayers
if numAlliedPlayers >= numAxisPlayers + max_unevenDiff then
local clientNum = alliedPlayers[ numAlliedPlayers ]
et.trap_SendConsoleCommand( et.EXEC_APPEND, "put " .. clientNum .. " r ; qsay balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS" )
elseif numAxisPlayers >= numAlliedPlayers + max_unevenDiff then
local clientNum = axisPlayers[ numAxisPlayers ]
et.trap_SendConsoleCommand( et.EXEC_APPEND, "put " .. clientNum .. " b ; qsay balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES" )
elseif numAlliedPlayers >= numAxisPlayers + unevenDiff then
if unevenTime > 0 then
if tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 then
local clientNum = alliedPlayers[ numAlliedPlayers ]
et.trap_SendConsoleCommand( et.EXEC_APPEND, "put " .. clientNum .. " r ; qsay balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS" )
end
else
unevenTime = tonumber( levelTime )
end
elseif numAxisPlayers >= numAlliedPlayers + unevenDiff then
if unevenTime > 0 then
if tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 then
local clientNum = axisPlayers[ numAxisPlayers ]
et.trap_SendConsoleCommand( et.EXEC_APPEND, "put " .. clientNum .. " b ; qsay balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES" )
end
else
unevenTime = tonumber( levelTime )
end
else
unevenTime = -1
end
end
function et_ClientSpawn( clientNum, revived, teamChange, restoreHealth )
if teamChange ~= 0 then
local team = tonumber( et.gentity_get( clientNum, "sess.sessionTeam" ) )
-- these were the teamnumbers prior to the move
local numAlliedPlayers = #alliedPlayers
local numAxisPlayers = #axisPlayers
if team == 1 then
for i, num in ipairs( alliedPlayers ) do
if num == clientNum then
table.remove( alliedPlayers, i )
break
end
end
-- this should not happen but still check for it to avoid doubles
for i, num in ipairs( axisPlayers ) do
if num == clientNum then
return
end
end
-- make sure a player who (got) moved when teams were uneven doesnt get moved right back
if numAlliedPlayers >= numAxisPlayers + unevenDiff then
table.insert( axisPlayers, 1, clientNum )
else
table.insert( axisPlayers, clientNum )
end
elseif team == 2 then
for i, num in ipairs( axisPlayers ) do
if num == clientNum then
table.remove( axisPlayers, i )
break
end
end
for i, num in ipairs( alliedPlayers ) do
if num == clientNum then
return
end
end
if numAxisPlayers >= numAlliedPlayers + unevenDiff then
table.insert( alliedPlayers, 1, clientNum )
else
table.insert( alliedPlayers, clientNum )
end
else
for i, num in ipairs( alliedPlayers ) do
if num == clientNum then
table.remove( alliedPlayers, i )
return
end
end
for i, num in ipairs( axisPlayers ) do
if num == clientNum then
table.remove( axisPlayers, i )
return
end
end
end
end
end
function et_ClientDisconnect( clientNum )
for i, num in ipairs( alliedPlayers ) do
if num == clientNum then
table.remove( alliedPlayers, i )
return
end
end
for i, num in ipairs( axisPlayers ) do
if num == clientNum then
table.remove( axisPlayers, i )
return
end
end
end
If someone knows what to change in order to work teambalance with omnibot too I could be happy.
Thank you for reading and for helping
VargaTom