Hi, everyone!
I have a question about balancing teams with lua. I have this option on server, but can i excluded bots with this balance? Exactly, when on the server play people(2 on axis and 5 on allies) and bots, balance doesn't work, because all players on the server is 12 (6 on allies and 6 on axis with bots).
This is my lua code:
modname = "balance"
version = "0.1"function et_InitGame(levelTime,randomSeed,restart)et.RegisterModname(modname .. " " .. version)endunevenDiff = 2max_unevenTime = 45max_unevenDiff = 4axisPlayers = {}alliedPlayers = {}unevenTime = 15function et_RunFrame( levelTime )local numAlliedPlayers = table.getn( alliedPlayers )local numAxisPlayers = table.getn( axisPlayers )if numAlliedPlayers >= numAxisPlayers + max_unevenDiff thenlocal clientNum = alliedPlayers[ numAlliedPlayers ]et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " r" )et.G_globalSound("lua/playermove.wav")et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS\"" )elseif numAxisPlayers >= numAlliedPlayers + max_unevenDiff thenlocal clientNum = axisPlayers[ numAxisPlayers ]et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " b" )et.G_globalSound("lua/playermove.wav")et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES\"" )elseif numAlliedPlayers >= numAxisPlayers + unevenDiff thenif unevenTime > 0 thenif tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 thenlocal clientNum = alliedPlayers[ numAlliedPlayers ]et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " r" )et.G_globalSound("lua/playermove.wav")et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS\"" )endelseunevenTime = tonumber( levelTime )endelseif numAxisPlayers >= numAlliedPlayers + unevenDiff thenif unevenTime > 0 thenif tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 thenlocal clientNum = axisPlayers[ numAxisPlayers ]et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " b" )et.G_globalSound("lua/playermove.wav")et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES\"" )endelseunevenTime = tonumber( levelTime )endelseunevenTime = -1endendfunction et_ClientSpawn( clientNum, revived, teamChange, restoreHealth )if teamChange ~= 0 thenlocal team = tonumber( et.gentity_get( clientNum, "sess.sessionTeam" ) )-- these were the teamnumbers prior to the movelocal numAlliedPlayers = table.getn( alliedPlayers )local numAxisPlayers = table.getn( axisPlayers )if team == 1 thenfor i, num in ipairs( alliedPlayers ) doif num == clientNum thentable.remove( alliedPlayers, i )breakendend-- this should not happen but still check for it to avoid doublesfor i, num in ipairs( axisPlayers ) doif num == clientNum thenreturnendend-- make sure a player who (got) moved when teams were uneven doesn't get moved right backif numAlliedPlayers >= numAxisPlayers + unevenDiff thentable.insert( axisPlayers, 1, clientNum )elsetable.insert( axisPlayers, clientNum )endelseif team == 2 thenfor i, num in ipairs( axisPlayers ) doif num == clientNum thentable.remove( axisPlayers, i )breakendendfor i, num in ipairs( alliedPlayers ) doif num == clientNum thenreturnendendif numAxisPlayers >= numAlliedPlayers + unevenDiff thentable.insert( alliedPlayers, 1, clientNum )elsetable.insert( alliedPlayers, clientNum )endelsefor i, num in ipairs( alliedPlayers ) doif num == clientNum thentable.remove( alliedPlayers, i )returnendendfor i, num in ipairs( axisPlayers ) doif num == clientNum thentable.remove( axisPlayers, i )returnendendendendendfunction et_ClientDisconnect( clientNum )for i, num in ipairs( alliedPlayers ) doif num == clientNum thentable.remove( alliedPlayers, i )returnendendfor i, num in ipairs( axisPlayers ) doif num == clientNum thentable.remove( axisPlayers, i )returnendendend