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

Auto-Balance

Xerkses

New Member
Joined
May 1, 2009
Messages
16
Reaction score
0
Witam, chciał bym się dowiedzieć jak zrobić auto-balance (1/1)
Z tego co widziałem, było już kilka postów na ten temat i nikt nic nie odpisywał. Co to takie trudne ?

How to make auto-balance ?
this is a "heavy" ?
 
Skrypt dla mapy z 3 miastami, w kazdym miescie sa po 2 swiatynie dla kazdego teamu (2 team, losowe team), w sumie 12 swiatyn. Losownie druzyn, dodawanie punktow za ktore mozna kupic addon, mozliwosc kupienia skull dla chara za sms, blokada relog na 3 sekundy po zalogowaniu, auto zmiana mapu co ustalony czas (domyslnie 30 minut), blokowanie 'dawania' fragow na MC/koledze i duzo innych opcji. Wszystko jak narazie w wersji beta na moim ots i za darmo dla graczy, potem to zoptymalizuje i bede hostowal na powaznie, aktulanie adres do wgladu:
WarOTS - Latest News
MOZE COS Z TEGO ZROZUMIESZ I SOBIE DOPASUJESZ DO OTS
Na tfs 0.3 mozna to zrobic bardzo latwo w pliku data/creaturescripts/scripts/login.lua
Akurat moj skrypt nie jest dla ots 1/1 tylko dla ots z priv. acc dla kazdego i rowna iloscia graczy w druzynach, ale, ze i tak mam 40 online to moge Ci pokazac o co ogolnie chodzi:
../data/creaturescripts/scripts/login.lua
Code:
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
../data/creaturescripts/scripts/playerdeath.lua
Code:
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.guid 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.ip 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.account 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
		local DB_addFrag = 0
		local DB_assist = 0
		local DB_assist_ip = 0
		if addFrag == true then
			DB_addFrag = 1
		end
		if isPlayer(mostDamageKiller) == TRUE then
			DB_assist = getPlayerGUID(mostDamageKiller)
			DB_assist_ip = getPlayerIp(mostDamageKiller)
		end
		db.executeQuery("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `player_ip`, `killer`, `killer_level`, `killer_ip`, `killer_2`, `killer_2_level`, `killer_2_ip`, `add_frag`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. getPlayerIp(cid) .. ", " .. getPlayerGUID(lastHitKiller) .. ", " .. getPlayerLevel(lastHitKiller) .. ", " .. getPlayerIp(lastHitKiller) .. ", " .. getPlayerGUID(mostDamageKiller) .. ", " .. getPlayerLevel(mostDamageKiller) .. ", " .. getPlayerIp(mostDamageKiller) .. ", " .. DB_addFrag .. ");")
	end
	db.executeQuery("UPDATE `players` SET `dies` = `dies`+1 WHERE `id` = " ..getPlayerGUID(cid) .. ";")
	setPlayerStorageValue(cid, STORAGE_TEAM_ID, 0)
	setTeam(cid)
	doTeleportThing(cid, getSpawn(cid), TRUE)
	addEvent(doCreatureAddHealth, 10,cid, getCreatureMaxHealth(cid))
	removeConditions(cid)
	return TRUE
end
w ../data/lib/data.lua na koncu pliku dodac:
Code:
dofile(getDataDir() .. "lib/war.lua")
dodac plik ../data/lib/war.lua, a w nim:
Code:
-- 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,30},{2,30},{3,30}}
WAR_COLORS = {{98,94,64,94},{114,23,114,114}}
WAR_TEAM_NAMES = {'Red Team','Black Team'}
WAR_BROADCAST_INTERVAL_TOP5 = 213

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) <= getConfigInfo('levelStart') and uid ~= cid then
		doPlayerSendCancel(cid, "You can't use potions on other players when you have start level (".. getConfigInfo('levelStart') ..").")
		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







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
 
Tak korzystając z okazji gęsior wiesz może jak zrobić aby po kliknięciu look na gracza wyświetlały się jego fragi?
 
Back
Top