• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Team Balance, HELP! REP++

Ub Kenobi

Member
Joined
Apr 10, 2009
Messages
144
Reaction score
8
Location
Sweden
Hey

I need a team balance script to my "capture the flag" event.

I should be a waiting room and every 30 min, all in the room will be teleported into the event.

The one I got now doesn't balance the teams right every time.

LUA:
local t = {
	redPos = {x = 2552, y = 1951, z = 7},
	bluePos = {x = 2534, y = 1903, z = 7},
	redStorage = 15000,
	blueStorage = 15001,
	fromPos = {x = 384, y = 103, z = 7},
	toPos = {x = 397, y = 114, z = 7}
}
local conditionBlue = createConditionObject(CONDITION_OUTFIT)
	setConditionParam(conditionBlue, CONDITION_PARAM_TICKS, 1800 * 1000)
	addOutfitCondition(conditionBlue, {lookType = 130, lookHead = 87, lookBody = 87, lookLegs = 87, lookFeet = 87})
local conditionRed = createConditionObject(CONDITION_OUTFIT)
	setConditionParam(conditionRed, CONDITION_PARAM_TICKS, 1800 * 1000)
	addOutfitCondition(conditionRed, {lookType = 130, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94})
local function teleportThing(minutes)
	local event = 0
    if minutes == 0 then
     		for _, cid in ipairs(getPlayersOnline()) do
			if isInRange(getThingPos(cid), t.fromPos, t.toPos) then
				if math.random(1, 3) < 3 then
					setPlayerStorageValue(cid, t.redStorage, 1)
					doAddCondition(cid, conditionRed)
					doTeleportThing(cid, t.redPos, true)
				else
					setPlayerStorageValue(cid, t.blueStorage, 1)
					doAddCondition(cid, conditionBlue)
					doTeleportThing(cid, t.bluePos, true)
				end
			end
		end
		return true
	end

	if minutes == 60 then
		doBroadcastMessage("Capture The Flag will begin in " .. minutes .. " minute!")
	elseif minutes <= 5 then
		doBroadcastMessage("Capture The Flag will begin in " .. minutes .. " minutes!")
	else
		doBroadcastMessage("Capture The Flag will begin in " .. minutes .. " minutes!")
	end
	event = addEvent(teleportThing, 60, minutes - 60)
	return true
end
function onThink(interval, lastExecution)
	return teleportThing(math.abs(math.ceil(1)))
end

Please help, I really need this. REP++
 
try this -- not sure --

How should it work? <-- if it have no bugs

If there is even players(ex :10 players) in theis place it will make 2 teams each have 5 players.

if there is Odd number(ex: 11 players) then it teleport the 11nth player to temple with mssg saying sorry kicked for team balance and then devide the rest to 2 team of 5 players



LUA:
local t = {
	redPos = {x = 2552, y = 1951, z = 7},
	bluePos = {x = 2534, y = 1903, z = 7},
	redStorage = 15000,
	blueStorage = 15001,
	fromPos = {x = 384, y = 103, z = 7},
	toPos = {x = 397, y = 114, z = 7}
}
local conditionBlue = createConditionObject(CONDITION_OUTFIT)
	setConditionParam(conditionBlue, CONDITION_PARAM_TICKS, 1800 * 1000)
	addOutfitCondition(conditionBlue, {lookType = 130, lookHead = 87, lookBody = 87, lookLegs = 87, lookFeet = 87})
local conditionRed = createConditionObject(CONDITION_OUTFIT)
	setConditionParam(conditionRed, CONDITION_PARAM_TICKS, 1800 * 1000)
	addOutfitCondition(conditionRed, {lookType = 130, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94})
local function teleportThing(minutes)
	local event = 0
    if minutes == 0 then
		players = {}
     		for _, cid in ipairs(getPlayersOnline()) do
				if isInRange(getThingPos(cid), t.fromPos, t.toPos) then
					table.insert(players,cid)
				end
			end
			if math.mod(#players, 2) ~= 0 then	
                doTeleportThing(players[#players],getTownTemplePosition(getPlayerTown(players[#players])),false)
				doSendMagicEffect(getThingPosition(players[#players]),10)
				doPlayerSendTextMessage(players[#players], 19, "Sorry, you have been kicked from event to balance teams.")					
				table.remove(players)
            end
			for i = 1, math.floor(#players/2) do
				setPlayerStorageValue(players[i], t.redStorage, 1)
				doAddCondition(players[i], conditionRed)
				doTeleportThing(players[i], t.redPos, true)
			end
			for i = math.floor(#players/2)+1 , #players do
				setPlayerStorageValue(players[i], t.blueStorage, 1)
				doAddCondition(players[i], conditionBlue)
				doTeleportThing(players[i], t.bluePos, true)
			end
		
		return true
	end
 
	if minutes == 60 then
		doBroadcastMessage("Capture The Flag will begin in " .. minutes .. " minute!")
	elseif minutes <= 5 then
		doBroadcastMessage("Capture The Flag will begin in " .. minutes .. " minutes!")
	else
		doBroadcastMessage("Capture The Flag will begin in " .. minutes .. " minutes!")
	end
	event = addEvent(teleportThing, 60, minutes - 60)
	return true
end
function onThink(interval, lastExecution)
	return teleportThing(math.abs(math.ceil(1)))
end
 
Back
Top