Team Force Balance


(vargatom) #1

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


(phisherman) #2

You want the script to ignore bots, did I understand that correctly? So if there’s 5 players + 2 bots on the axis and 3 players + 4 bots on the allied team, you want the script to put one player from the Axis to the Allies?

//I updated the script, see attachment. I didn’t test it though, so there might be syntax errors.


(vargatom) #3

Thank you very much for taking your time to my problem!:slight_smile:

You understood very well what I thought. The BOTs ignored and only adjust the balance with human players.
I tested it and I found a bug (# 67 lines missing end) but now works. If autoBalanceInterval is set to 5 balancing time is 90s ( is too much ) so it I shifted to 2. So I like it.
It would be nice if the players are informed immediately about in one of team has two more players. So if someone wants to switch teams can do during this time.:confused:


(phisherman) #4

[QUOTE=vargatom;555575]If autoBalanceInterval is set to 5 balancing time is 90s[/QUOTE]Indeed, I ****ed that up. It should be fixed now, so setting it to 5 will actually mean 5 seconds.

It would be nice if the players are informed immediately about in one of team has two more players
You can do this by setting autoBalanceInterval to something small, like 1 second.
So if someone wants to switch teams can do during this time
I have added voluntaryChangeTime, take a look:


(vargatom) #5

Unfortunately. this version does not work. It detects that a team has more players and print:


but nothing happens.:rolleyes:


(phisherman) #6

Very true, I have made a mistake. The script was attempting to move the player to the stronger team rather than the weaker team. Try again:


(vargatom) #7

It’s great! Thank You!


(phisherman) #8

Does it work or are you just tired of reporting bugs? [noparse];)[/noparse] If it does, I will add it to my scripts collection.


(vargatom) #9

Add to your collection! It working perfectly Thanks!
Is public this collection?:slight_smile:


(phisherman) #10

Yes it is, take a look here. All the links are in the first post, you don’t have to scroll through the entire thread.


(cccdfern) #11

@phisherman
So, I can’t actually see a way to message you directly, therefore unfortunately necro’ing.

I was wondering/hoping I could get a copy of your omnibot team-balance lua as none of these threads have download links for it.

Thanks


(KeMoN) #12

Hi there,
I’ve just had a chat with phishi. The LUA scripts were all attached to their respective posts, so his guess was that they got lost during the redesign of the forum. Maybe @Moobabe knows a bit more about the transformation process from old to new forum. Is it possible that post attachments (not linked files) could have been lost during that process? It’s about this thread.

Unfortunately, phishi doesn’t have any backups locally. So unless someone else has downloaded all of them and could re-upload them somewhere else, you might be out of luck.