• 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!

Feature Auto Team Balance

Norix

Hosting Service !
Joined
Jan 18, 2008
Messages
544
Reaction score
8
Location
Germany
Hi
I need a Auto Team Balance Source Script, so you have 2 Teams and you login with 1/1 and you will be automatically put in a team. Gesior's War Server has one but its 8.11 and i wanna have 8.4
Does anyone have the script.???
Thanks in advance.
Your's ballack13
 
When player login script checks how much players are in each team. Then change outfit and position. Easy.


Yours,
Gelio
 
@Keraxel

Actually your not giving the sources of your server you just link to the forgotten server svn :huh:
 
Heres the functions;


Code:
function getSmallestTeam()
	local ret = 0
	if teamCount.get(1) > teamCount.get(2) then
		ret = 2
	else
		ret = 1
	end
	return ret
end

playerTeam = {
	get = function(cid)
		if getPlayerStorageValue(cid, PLAYER_STORAGE.TEAM_INFO) == GLOBAL_STORAGE.TEAMS[1] then
			return 1
		else
			return 2
		end
	end,

	set = function(cid, id)
		return setPlayerStorageValue(cid, PLAYER_STORAGE.TEAM_INFO, id)
	end
}

and

Code:
doPlayerSetTeam = {
	login = function (cid)
--		print("getSmallestTeam(): "..getSmallestTeam())
		if  getSmallestTeam() == FALSE then
			return FALSE
		end

		if getPlayerAccess(cid) < 3 then
			local team = getSmallestTeam()
			if team > 0 then
				local teamColor = TEAM_COLOR[team]
				playerTeam.set(cid, GLOBAL_STORAGE.TEAMS[team])
				doCreatureChangeOutfit(cid, {lookType = getCreatureOutfit(cid).lookType, lookHead = teamColor, lookBody = teamColor, lookLegs = teamColor, lookFeet = teamColor, lookTypeEx = color, lookAddons = 3})
				local temple = TEMPLES[playerTeam.get(cid)][areaId.get()]
				doPlayerSetTown(cid, temple)
				doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
				teamCount.add(team, 1)
				doPlayerAddSoul(cid, -getPlayerSoul(cid))
				doSendMagicEffect(getCreaturePosition(cid), 37)
			end
		end

Code:
logout = function (cid)
		if getPlayerAccess(cid) < 3 then
			local team = playerTeam.get(cid)
--			print("getPlayerTeam(cid): "..team)
			if team > 0 then
				teamCount.rem(team, 1)
				playerTeam.set(cid, FALSE)
--				print("Team 1 count: "..teamCount.get(1).."\nTeam 2 count: "..teamCount.get(2))
			end
		end
		return TRUE
	end

and then

Code:
function onLogin(cid)
	return doPlayerSetTeam.login(cid)
end

function onLogout(cid)
	return doPlayerSetTeam.logout(cid)
end
 
Can anyone give me a help ? ?

I wanna do a war server with two accounts of war example : Julera x Danera
but i can't do it with the Team balance of Keraxel War server ;s.
because i can't create account 2/2 in Database ;s and if i create all members of julera world and danera world in account 1/1 will log example: Setzer Gambler in team one and Sir Roxys Crazy in team one :S
Setzer gambler of julera and Sir roxys crazy of danera

Sorry for my bad english .. ;]
 
Last edited:
Heres the functions;


Code:
function getSmallestTeam()
	local ret = 0
	if teamCount.get(1) > teamCount.get(2) then
		ret = 2
	else
		ret = 1
	end
	return ret
end

playerTeam = {
	get = function(cid)
		if getPlayerStorageValue(cid, PLAYER_STORAGE.TEAM_INFO) == GLOBAL_STORAGE.TEAMS[1] then
			return 1
		else
			return 2
		end
	end,

	set = function(cid, id)
		return setPlayerStorageValue(cid, PLAYER_STORAGE.TEAM_INFO, id)
	end
}

and

Code:
doPlayerSetTeam = {
	login = function (cid)
--		print("getSmallestTeam(): "..getSmallestTeam())
		if  getSmallestTeam() == FALSE then
			return FALSE
		end

		if getPlayerAccess(cid) < 3 then
			local team = getSmallestTeam()
			if team > 0 then
				local teamColor = TEAM_COLOR[team]
				playerTeam.set(cid, GLOBAL_STORAGE.TEAMS[team])
				doCreatureChangeOutfit(cid, {lookType = getCreatureOutfit(cid).lookType, lookHead = teamColor, lookBody = teamColor, lookLegs = teamColor, lookFeet = teamColor, lookTypeEx = color, lookAddons = 3})
				local temple = TEMPLES[playerTeam.get(cid)][areaId.get()]
				doPlayerSetTown(cid, temple)
				doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
				teamCount.add(team, 1)
				doPlayerAddSoul(cid, -getPlayerSoul(cid))
				doSendMagicEffect(getCreaturePosition(cid), 37)
			end
		end

Code:
logout = function (cid)
		if getPlayerAccess(cid) < 3 then
			local team = playerTeam.get(cid)
--			print("getPlayerTeam(cid): "..team)
			if team > 0 then
				teamCount.rem(team, 1)
				playerTeam.set(cid, FALSE)
--				print("Team 1 count: "..teamCount.get(1).."\nTeam 2 count: "..teamCount.get(2))
			end
		end
		return TRUE
	end

and then

Code:
function onLogin(cid)
	return doPlayerSetTeam.login(cid)
end

function onLogout(cid)
	return doPlayerSetTeam.logout(cid)
end

and where add?
 
data/lib/war.lua from my old war server:
PHP:
-- config --
WAR_MAP_NAMES = {'Fibula', 'Edron', 'Thais'}
WAR_SPAWNS = {}
WAR_SPAWNS[1] = {{2,3},{4,5}} -- map 1
WAR_SPAWNS[2] = {{6,7},{8,9}} -- map 2
WAR_SPAWNS[3] = {{11,12},{13,14}} -- map 2
WAR_MAP_CYCLE = {{1,1},{2,1},{3,1}}
WAR_COLORS = {{98,94,64,94},{114,23,114,114}}
WAR_TEAM_NAMES = {'Team 1','Team 2'}
WAR_BROADCAST_INTERVAL_TOP5 = 213

WAR_START_LEVEL = 80
WAR_TEAMS = 1

WAR_POINTS_FOR_KILL = 3
WAR_POINTS_FOR_KILL_ASSIST = 1

--------------------------------------------------------
STORAGE_LAST_KILLER_GUID = 10100
STORAGE_LAST_KILLER_GUID_TIMES = 10101
STORAGE_LAST_KILLER_IP = 10200
STORAGE_LAST_KILLER_IP_TIMES = 10201
STORAGE_LAST_KILLER_ACCOUNT = 10300
STORAGE_LAST_KILLER_ACCOUNT_TIMES = 10301
STORAGE_POINTS = 11000
STORAGE_TEAM_ID = 12000
STORAGE_SKULL = 13000
STORAGE_DEPOT = 14000

GLOBAL_STORAGE_MAP = 500
GLOBAL_STORAGE_MAP_CHANGE_TIME = 501
GLOBAL_STORAGE_TEAM_1_FRAGS = 600
GLOBAL_STORAGE_TEAM_2_FRAGS = 700
GLOBAL_STORAGE_BROADCAST_TOP5 = 800

warInitialized = 0

function getSpawn(cid)
	local map_info = WAR_MAP_CYCLE[getGlobalStorageValue(GLOBAL_STORAGE_MAP)]
	local map_id = map_info[1]
	local map_spawns = WAR_SPAWNS[map_id]
	local team_spawns = map_spawns[getPlayerStorageValue(cid, STORAGE_TEAM_ID)]
	return getTownTemplePosition(team_spawns[math.random(1,#team_spawns)])
end

function getTeamMembers(id)
	local players = getPlayersOnline()
	local team = {}
	if #players == 0 then
		return team
	end
	for i, cid in ipairs(players) do
		if getPlayerStorageValue(cid, STORAGE_TEAM_ID) == id and getPlayerGroupId(cid) == 1 then
			table.insert(team, cid)
		end
	end
	return team
end

function updateOutfit(cid)
	if WAR_TEAMS == 1 then --outfit
		local colors = WAR_COLORS[getPlayerStorageValue(cid, STORAGE_TEAM_ID)]
		local outfit = getCreatureOutfit(cid)
		outfit.lookHead = colors[1]
		outfit.lookBody = colors[2]
		outfit.lookLegs = colors[3]
		outfit.lookFeet = colors[4]
		doCreatureChangeOutfit(cid, outfit)
	end
end

function setTeam(cid)
	if WAR_TEAMS ~= 1 then
		setPlayerStorageValue(cid, STORAGE_TEAM_ID, 1)
	else
		local team1 = getTeamMembers(1)
		local team2 = getTeamMembers(2)
		if #team1 >= #team2 then
			setPlayerStorageValue(cid, STORAGE_TEAM_ID, 2)
		else
			setPlayerStorageValue(cid, STORAGE_TEAM_ID, 1)
		end
		updateOutfit(cid)
	end
end

function cronWar()
	if getGlobalStorageValue(GLOBAL_STORAGE_MAP_CHANGE_TIME) < os.time() then -- change map
		local map_info = WAR_MAP_CYCLE[getNextMapId()]
		local map_id = map_info[1]
		doBroadcastMessage("Map change... Name: " .. WAR_MAP_NAMES[map_id] .. " Time: " .. map_info[2] .. " minutes", MESSAGE_INFO_DESCR)
		if WAR_TEAMS == 1 then
			doBroadcastMessage(getTeamScore(), MESSAGE_STATUS_DEFAULT)
		end
		setMap(getNextMapId())
	elseif getGlobalStorageValue(GLOBAL_STORAGE_BROADCAST_TOP5) < os.time() then -- broadcast top 5
		setGlobalStorageValue(GLOBAL_STORAGE_BROADCAST_TOP5, os.time()+WAR_BROADCAST_INTERVAL_TOP5)
		addEvent(doBroadcastMessage, 1000, getTop5Players(), MESSAGE_STATUS_CONSOLE_ORANGE)
	end
	addEvent(cronWar, 1000)
end

function getNextMapId()
	if getGlobalStorageValue(GLOBAL_STORAGE_MAP) == #WAR_MAP_CYCLE then
		return 1
	end
	return getGlobalStorageValue(GLOBAL_STORAGE_MAP)+1
end

function getTop5Players()
	local players = getPlayersOnline()
	if #players == 0 then
		return top5text
	end
	local player1 = {0,-1}
	local player2 = {0,-1}
	local player3 = {0,-1}
	local player4 = {0,-1}
	local player5 = {0,-1}
	local top5text = "Top 5 fraggers"
	for i, cid in ipairs(players) do
		if getPlayerSoul(cid) > player1[2] then
			player5 = {player4[1], player4[2]}
			player4 = {player3[1], player3[2]}
			player3 = {player2[1], player2[2]}
			player2 = {player1[1], player1[2]}
			player1 = {cid, getPlayerSoul(cid)}
		elseif getPlayerSoul(cid) > player2[2] then
			player5 = {player4[1], player4[2]}
			player4 = {player3[1], player3[2]}
			player3 = {player2[1], player2[2]}
			player2 = {cid, getPlayerSoul(cid)}
		elseif getPlayerSoul(cid) > player3[2] then
			player5 = {player4[1], player4[2]}
			player4 = {player3[1], player3[2]}
			player3 = {cid, getPlayerSoul(cid)}
		elseif getPlayerSoul(cid) > player4[2] then
			player5 = {player4[1], player4[2]}
			player4 = {cid, getPlayerSoul(cid)}
		elseif getPlayerSoul(cid) > player1[2] then
			player5 = {cid, getPlayerSoul(cid)}
		end
	end
	if player1[1] > 0 then
		top5text = top5text .. "\n1. " .. getCreatureName(player1[1]) .. " - " .. player1[2] .. " frags"
	end
	if player2[1] > 0 then
		top5text = top5text .. "\n2. " .. getCreatureName(player2[1]) .. " - " .. player2[2] .. " frags"
	end
	if player3[1] > 0 then
		top5text = top5text .. "\n3. " .. getCreatureName(player3[1]) .. " - " .. player3[2] .. " frags"
	end
	if player4[1] > 0 then
		top5text = top5text .. "\n4. " .. getCreatureName(player4[1]) .. " - " .. player4[2] .. " frags"
	end
	if player5[1] > 0 then
		top5text = top5text .. "\n5. " .. getCreatureName(player5[1]) .. " - " .. player5[2] .. " frags"
	end
	return top5text
end

function getTeamScore()
	return WAR_TEAM_NAMES[1] .. " - " .. getGlobalStorageValue(GLOBAL_STORAGE_TEAM_1_FRAGS) .. " : " .. getGlobalStorageValue(GLOBAL_STORAGE_TEAM_2_FRAGS) .. " - " .. WAR_TEAM_NAMES[2]
end

function setMap(id)
	local map_info = WAR_MAP_CYCLE[id]
	setGlobalStorageValue(GLOBAL_STORAGE_MAP,id)
	setGlobalStorageValue(GLOBAL_STORAGE_MAP_CHANGE_TIME,os.time()+map_info[2]*60)
	setGlobalStorageValue(GLOBAL_STORAGE_TEAM_1_FRAGS,0)
	setGlobalStorageValue(GLOBAL_STORAGE_TEAM_2_FRAGS,0)
	local players = getPlayersOnline()
	for i, cid in ipairs(players) do
		if getPlayerStorageValue(cid, STORAGE_DEPOT) == 0 then
			doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
			doCreatureAddMana(cid, getCreatureMaxMana(cid))
			doTeleportThing(cid, getSpawn(cid), TRUE)
			removeConditions(cid)
		end
	end
	for i, cid in ipairs(players) do
		removeConditions(cid)
	end
end

function removeConditions(cid)
	doRemoveCondition(cid, CONDITION_INFIGHT)
	doRemoveCondition(cid, CONDITION_PARALYZE)
	doRemoveCondition(cid, CONDITION_ENERGY)
	doRemoveCondition(cid, CONDITION_FIRE)
	doRemoveCondition(cid, CONDITION_POISON)
	doRemoveCondition(cid, CONDITION_DRUNK)
end

function canDrinkPotion(cid, uid)
	if getPlayerLevel(cid) <= WAR_START_LEVEL and uid ~= cid then
		doPlayerSendCancel(cid, "You can't use potions on other players when you have start level.")
		return TRUE
	elseif getTilePzInfo(getCreaturePosition(cid)) == TRUE or getTilePzInfo(getCreaturePosition(uid)) == TRUE then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE)
		return TRUE
	elseif getPlayerIp(cid) == getPlayerIp(uid) and uid ~= cid then
		doPlayerSendCancel(cid, "You can't use potions on other players with same IP as yours (MC).")
		return TRUE
	end
	return FALSE
end






-- not in use
function setSkillsAndMlvl(cid)
	if getPlayerVocation(cid) < 1 or getPlayerVocation(cid) > 4 then
		return
	end
	skills = NEW_CHAR_SKILLS[getPlayerVocation(cid)]
	for i=0, 6 do
		for s=11, skills[i+1] do
			doPlayerAddSkillTry(cid, i, getPlayerRequiredSkillTries(cid, i, s))
		end
	end
	for i=1, skills[8] do
		doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, i))
	end
end
login.lua:
PHP:
local anti_logout = createConditionObject(CONDITION_INFIGHT)
setConditionParam(anti_logout, CONDITION_PARAM_TICKS, 3000)

function onLogin(cid)
	if warInitialized == 0 then
		warInitialized = 1
		setPlayerStorageValue(cid, STORAGE_TEAM_ID, 1)
		setMap(1)
		cronWar()
	end
	if getPlayerStorageValue(cid, STORAGE_POINTS) == -1 then
		setPlayerStorageValue(cid, STORAGE_POINTS, 0)
	end
	if getPlayerStorageValue(cid, STORAGE_SKULL) > 0 then
		doCreatureSetSkullType(cid,getPlayerStorageValue(cid, STORAGE_SKULL))
	end
	--doAddCondition(cid, anti_logout)
	setPlayerStorageValue(cid, STORAGE_TEAM_ID, 0)
	setPlayerStorageValue(cid, STORAGE_DEPOT, 0)
	setTeam(cid)
	doTeleportThing(cid, getSpawn(cid), TRUE)
	registerCreatureEvent(cid, "PlayerDeath")
	registerCreatureEvent(cid, "PlayerThink")
	return TRUE
end
playerdeath.lua:
PHP:
local fragConfig = {
	ip = getConfigInfo('fragLimitIP'),
	guid = getConfigInfo('fragLimitGUID'),
	account = getConfigInfo('fragLimitAccount')
}

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
	local addFrag = true
	if isPlayer(lastHitKiller) == TRUE then
		-- anti MC, give frag ect.
		if getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_GUID) ~= getPlayerGUID(cid) then
			setPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_GUID, getPlayerGUID(cid))
			setPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_GUID_TIMES, 0)
		else
			setPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_GUID_TIMES, getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_GUID_TIMES)+1)
		end
		if getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_IP) ~= getPlayerIp(cid) then
			setPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_IP, getPlayerIp(cid))
			setPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_IP_TIMES, 0)
		else
			setPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_IP_TIMES, getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_IP_TIMES)+1)
		end
		if getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_ACCOUNT) ~= getPlayerAccountId(cid) then
			setPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_ACCOUNT, getPlayerAccountId(cid))
			setPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_ACCOUNT_TIMES, 0)
		else
			setPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_ACCOUNT_TIMES, getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_ACCOUNT_TIMES)+1)
		end
		if getPlayerIp(lastHitKiller) == getPlayerIp(cid) then
			doPlayerSendTextMessage(lastHitKiller, MESSAGE_STATUS_CONSOLE_ORANGE, "You killed player with same IP as yours. You will not gain frag. Multi-client?")
			addFrag = false
		elseif getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_GUID_TIMES) >= fragConfig.fragLimitGUID then
			doPlayerSendTextMessage(lastHitKiller, MESSAGE_STATUS_CONSOLE_ORANGE, "You killed same player " .. getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_GUID_TIMES) .. " times. You will not gain frag. Friend give you frags?")
			addFrag = false
		elseif getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_IP_TIMES) >= fragConfig.fragLimitIP then
			doPlayerSendTextMessage(lastHitKiller, MESSAGE_STATUS_CONSOLE_ORANGE, "You killed player with same IP " .. getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_IP_TIMES) .. " times. You will not gain frag. Friend give you frags?")
			addFrag = false
		elseif getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_ACCOUNT_TIMES) >= fragConfig.fragLimitAccount then
			doPlayerSendTextMessage(lastHitKiller, MESSAGE_STATUS_CONSOLE_ORANGE, "You killed player with same account number " .. getPlayerStorageValue(lastHitKiller, STORAGE_LAST_KILLER_ACCOUNT_TIMES) .. " times. You will not gain frag. Friend give you frags?")
			addFrag = false
		end
		if addFrag then
			doPlayerAddSoul(lastHitKiller, 1)
			setPlayerStorageValue(lastHitKiller, STORAGE_POINTS, getPlayerStorageValue(lastHitKiller, STORAGE_POINTS)+WAR_POINTS_FOR_KILL)
			db.executeQuery("UPDATE `players` SET `frags` = `frags`+1 WHERE `id` = " ..getPlayerGUID(lastHitKiller) .. ";")
			if isPlayer(mostDamageKiller) == TRUE and lastHitKiller ~= mostDamageKiller then
				db.executeQuery("UPDATE `players` SET `supports` = `supports`+1 WHERE `id` = " ..getPlayerGUID(mostDamageKiller) .. ";")
				setPlayerStorageValue(mostDamageKiller, STORAGE_POINTS, getPlayerStorageValue(mostDamageKiller, STORAGE_POINTS)+WAR_POINTS_FOR_KILL_ASSIST)
			end
			if getPlayerStorageValue(cid, STORAGE_SKULL) <= 0 then
				if getPlayerSoul(lastHitKiller) >= 5 and getPlayerSoul(lastHitKiller) < 10 then
					doCreatureSetSkullType(lastHitKiller,SKULL_WHITE)
				elseif getPlayerSoul(lastHitKiller) >= 10 and getPlayerSoul(lastHitKiller) < 15 then
					doCreatureSetSkullType(lastHitKiller,SKULL_RED)
				elseif getPlayerSoul(lastHitKiller) >= 15 then
					doCreatureSetSkullType(lastHitKiller,SKULL_YELLOW)
				elseif getPlayerSoul(lastHitKiller) >= 25 then
					doCreatureSetSkullType(lastHitKiller,SKULL_GREEN)
				end
			end
			if getPlayerStorageValue(lastHitKiller, STORAGE_TEAM_ID) == 1 then
				setGlobalStorageValue(GLOBAL_STORAGE_TEAM_1_FRAGS,getGlobalStorageValue(GLOBAL_STORAGE_TEAM_1_FRAGS)+1)
			else
				setGlobalStorageValue(GLOBAL_STORAGE_TEAM_2_FRAGS,getGlobalStorageValue(GLOBAL_STORAGE_TEAM_2_FRAGS)+1)
			end
		end
	end
	db.executeQuery("UPDATE `players` SET `dies` = `dies`+1 WHERE `id` = " ..getPlayerGUID(cid) .. ";")
	setPlayerStorageValue(cid, STORAGE_TEAM_ID, 0)
	removeConditions(cid)
	setTeam(cid)
	doTeleportThing(cid, getSpawn(cid), TRUE)
	addEvent(doCreatureAddHealth, 10,cid, getCreatureMaxHealth(cid))
	addEvent(doCreatureAddMana, 10,cid, getCreatureMaxMana(cid))
	removeConditions(cid)
	return TRUE
end
You cant use it without source and database structure modifications, but you can copy some ideas from it.
 
Back
Top