Ir para conteúdo

Featured Replies

Postado
  • Este é um post popular.

Olá pessoal, resolvi criar um sistema de recompensa parecido com o sistema do tibia global para a versão 8.60, mas tie que fazer varias "gambiarras" para ele funcionar nesta versão.

Para quem não conhece: http://www.tibiawiki.com.br/wiki/Loot#Sistema_de_Recompensas

Basicamente meu sistema funciona da seguinte forma:
• você determina as criaturas que irão funcionar com esse sistema (normalmente bosses).
• durante a batalha com a criatura o sistema conta pontos aos jogadores por ataque, bloqueio e suporte ("healar" quem esta na batalha).
• quando a criatura é morta o sistema cria um "loot" de acordo com os pontos e envia-o ao depot do jogador em uma bag determinada nas configurações.

Primeiramente vamos criar o arquivo das configurações gerais, crie uma pasta dentro do "data" com o nome de sistemas e dentro cria um arquivo rewardchest.lua

Spoiler

-- Sistema de recompensa criado por luanluciano93

REWARDCHEST = {
	rewardBagId = 2595,
	formula = {hit = 3, block = 1, suport = 9},
	storageExaust = 60000,
	town_id = 1,
	bosses = {
		["ghazbaran"] = -- todo o nome do boss em letras minúsculas.
		{
			comum = {
				{2143, 10, 100}, -- white pearl
				{2146, 10, 100}, -- small sapphire
				{2145, 10, 100}, -- small diamond
				{2144, 10, 100}, -- black pearl
				{2149, 10, 100}, -- small emeralds
				{5954, 3, 100}, -- demon horn
				{7896, 1, 100}, -- glacier kilt
				{7590, 1, 100}, -- great mana potion
				{2179, 1, 100}, -- gold ring
				{2151, 1, 100}, -- talon
			}, 

			semi_raro = {
				{2152, 90, 100}, -- platinum coin
				{7368, 50, 100}, -- assassin star
				{2130, 1, 100}, -- golden amulet
				{2436, 1, 100}, -- skull staff
				{2447, 1, 100}, -- twin axe
				{2171, 1, 100}, -- platinum amulet
				{2158, 1, 100}, -- blue gem
				{2393, 1, 100}, -- giant sword
				{2164, 1, 100}, -- might ring
				{7454, 1, 100}, -- glorious axe
				{6553, 1, 100}, -- ruthless axe
				{9971, 1, 100}, -- gold ingot
			},

			raro = {
				{2160, 3, 100}, -- crystal coin
				{8887, 1, 100}, -- frozen plate
				{2470, 1, 100}, -- golden legs
				{2472, 1, 100}, -- magic plate armor
				{7431, 1, 100}, -- demonbone
				{2520, 1, 100}, -- demon shield
				{5943, 1, 100}, -- morgaroth hearth
				{2466, 1, 100}, -- golden armor
				{2514, 1, 100}, -- mastermind shield
				{2142, 1, 100}, -- ancient amulet
				{2123, 1, 100}, -- ring of the sky
				{1984, 1, 100}, -- blue tome
			},

			muito_raro = {
				{8866, 1, 100}, -- robe of the ice queen
				{6553, 1, 100}, -- ruthless axe
				{8884, 1, 100}, -- oceanborn leviathan armor
				{2421, 1, 100}, -- thunder hammer
				{2646, 1, 100}, -- golden boots
				{7455, 1, 100}, -- mythril axe
			},
			
			sempre = {
				{2148, 90, 100}, -- gold coin
				{6500, 9, 100}, -- demonic essence
				{2177, 1, 100}, -- life crystal
				{2214, 1, 100}, -- ring of healing
			},
			
			storage = 65479, 
		},
		
		["orshabaal"] = -- nome do boss em todo em letras minísculas
		{
			comum = {
				{2143, 10, 100}, -- white pearl
				{2146, 10, 100}, -- small sapphire
				{2145, 10, 100}, -- small diamond
				{2144, 10, 100}, -- black pearl
				{2149, 10, 100}, -- small emeralds
				{5954, 3, 100}, -- demon horn
				{7896, 1, 100}, -- glacier kilt
				{2432, 1, 100}, -- fire axe
				{2462, 1, 100}, -- devil helmet
				{7590, 1, 100}, -- great mana potion
				{2179, 1, 100}, -- gold ring
				{2151, 1, 100}, -- talon
			}, 

			semi_raro = {
				{2195, 1, 100}, -- boots of haste
				{2436, 1, 100}, -- skull staff
				{2393, 1, 100}, -- giant sword
				{5954, 5, 100}, -- demon horn
			},

			raro = {
				{2470, 1, 100}, -- golden legs
				{2472, 1, 100}, -- magic plate armor
				{2514, 1, 100}, -- mastermind shield
				{2520, 1, 100}, -- demon shield
				{1982, 1, 100}, -- purple tome
				{2123, 1, 100}, -- ring of the sky
			},

			muito_raro = {
				{8890, 1, 100}, -- Robe of the underworld
				{2421, 1, 100}, -- thunder hammer
			},
			
			sempre = {
				{5808, 1, 100}, -- orshabaals brain
				{2171, 1, 100}, -- platinum amulet
				{2148, 90, 100}, -- gold coin
				{2146, 10, 100}, -- small sapphire
			},
			
			storage = 65480, 
		},
		
		["ferumbras"] = -- todo o nome do boss em letras minúsculas.
		{
			comum = {
				{2143, 10, 100}, -- white pearl
				{2146, 10, 100}, -- small sapphire
				{2145, 10, 100}, -- small diamond
				{2144, 10, 100}, -- black pearl
				{2149, 10, 100}, -- small emeralds
				{7416, 1, 100}, -- Bloody Edge
				{7896, 1, 100}, -- glacier kilt
				{2432, 1, 100}, -- fire axe
				{2462, 1, 100}, -- devil helmet
				{7590, 1, 100}, -- great mana potion
				{2179, 1, 100}, -- gold ring
				{2151, 1, 100}, -- talon
			}, 

			semi_raro = {
				{2195, 1, 100}, -- boots of haste
				{2472, 1, 100}, -- magic plate armor
				{2393, 1, 100}, -- giant sword
				{2470, 1, 100}, -- golden legs
				{2514, 1, 100}, -- mastermind shield
			},

			raro = {
				{8885, 1, 100}, -- divine plate
				{2520, 1, 100}, -- demon shield
				{8930, 1, 100}, -- emerald sword
				{2522, 1, 100}, -- great shield
				{2421, 1, 100}, -- thunder hammer
			},

			muito_raro = {
				{5903, 1, 100}, -- ferumbras hat
			},
			
			sempre = {
				{2171, 1, 100}, -- platinum amulet
				{2148, 90, 100}, -- gold coin
				{2146, 10, 100}, -- small sapphire
			},
			
			storage = 65481, 
		},
		["zulazza the corruptor"] = -- todo o nome do boss em letras minúsculas.
		{
			comum = {
				{2158, 1, 100}, -- blue gem
				{2156, 1, 100}, -- red gem
				{2155, 1, 100}, -- green gem
				{2154, 1, 100}, -- yellow gem
				{2153, 1, 100}, -- violet gem
			}, 

			semi_raro = {
				{5944, 5, 100}, -- soul orb
			},

			raro = {
				{2514, 1, 100}, -- mastermind shield
			},

			muito_raro = {
				{11114, 1, 100}, -- dragon scale boots
				{8882, 1, 100}, -- earthborn titan armor
			},
			
			sempre = {
				{2152, 90, 100}, -- platinum coin
				{9971, 5, 100}, -- gold ingot
			},
			
			storage = 65482, 
		},
		["morgaroth"] = -- todo o nome do boss em letras minúsculas.
		{
			comum = {
				{2143, 10, 100}, -- white pearl
				{2146, 10, 100}, -- small sapphire
				{2145, 10, 100}, -- small diamond
				{2144, 10, 100}, -- black pearl
				{2149, 10, 100}, -- small emeralds
				{5954, 3, 100}, -- demon horn
				{7896, 1, 100}, -- glacier kilt
				{2432, 1, 100}, -- fire axe
				{2462, 1, 100}, -- devil helmet
				{7590, 1, 100}, -- great mana potion
				{2179, 1, 100}, -- gold ring
				{2151, 1, 100}, -- talon
			}, 

			semi_raro = {
				{2195, 1, 100}, -- boots of haste
				{2393, 1, 100}, -- giant sword
				{5954, 5, 100}, -- demon horn
				{2123, 1, 100}, -- ring of the sky
			},

			raro = {
				{8886, 1, 100}, -- molten plate
				{2472, 1, 100}, -- magic plate armor
				{8867, 1, 100}, -- dragon robe
				{2514, 1, 100}, -- mastermind shield
				{2520, 1, 100}, -- demon shield
				{1982, 1, 100}, -- purple tome
				{8851, 1, 100}, -- Royal Crossbow
			},

			muito_raro = {
				{2421, 1, 100}, -- thunder hammer
				{2522, 1, 100}, -- great shield
				{8850, 1, 100}, -- chain bolter
			},
			
			sempre = {
				{5943, 1, 100}, -- morgaroths brain
				{2171, 1, 100}, -- platinum amulet
				{2148, 90, 100}, -- gold coin
				{2146, 10, 100}, -- small sapphire
			},
			storage = 65483, 
		},
	}
}

Neste arquivo esta configurado 4 bosses para vocês verem como funciona para adicionar mais criaturas (você terá que ter o mínimo de conhecimento para entender)


Depois em creaturescript crie dois arquivos:
rewardchest_boss.lua:

Spoiler

-- Sistema de recompensa criado por luanluciano93

dofile('data/sistemas/rewardchest.lua')

local function addRewardLoot(uid, bossName, tabela_reward)
	local money = math.random(10, 40)
	local msg = "The following items are available in your reward chest:"
	local chest = doCreateItemEx(REWARDCHEST.rewardBagId)

	doItemSetAttribute(chest, "description", "Reward System has kill the boss ".. bossName ..".")

	if table.maxn(tabela_reward) > 0 then
		for x = 1, table.maxn(tabela_reward) do
			local rand = math.random(100)
			if rand <= tabela_reward[x][3] then
				local count = math.random(1, tabela_reward[x][2])
				doAddContainerItem(chest, tabela_reward[x][1], count)
				msg = msg .. " ".. (count > 1 and count or "") .." "..getItemNameById(tabela_reward[x][1])..","
			end
		end
		doPlayerSendTextMessage(uid, MESSAGE_INFO_DESCR, msg .. " and ".. money .." platinum coins.")
	else
		doPlayerSendTextMessage(uid, MESSAGE_INFO_DESCR, msg .. " ".. money .." platinum coins.")
	end

	doAddContainerItem(chest, 2152, money)
	doPlayerSendMailByName(getPlayerName(uid), chest, REWARDCHEST.town_id)

	local boss = REWARDCHEST.bosses[bossName]
	setPlayerStorageValue(uid, boss.storage, 0)
	doSendMagicEffect(getPlayerPosition(uid), CONST_ME_MAGIC_BLUE)
end

local function addLoot(tabela_loot, tabela_reward, all_loot)
	if table.maxn(tabela_loot) > 0 then
		if all_loot then
			for x = 1, table.maxn(tabela_loot) do
				table.insert(tabela_reward, tabela_loot[x])
			end
		else
			table.insert(tabela_reward, tabela_loot[math.random(table.maxn(tabela_loot))])
		end
	end

	return tabela_reward
end

local function rewardChestSystem(bossName)
	local players = {}
	local boss = REWARDCHEST.bosses[bossName]

	for _, uid in ipairs(getPlayersOnline()) do
		if getPlayerStorageValue(uid, boss.storage) > 0 then
			table.insert(players, uid)
		end
	end

	table.sort(players, function(a, b) return getPlayerStorageValue(a, boss.storage) > getPlayerStorageValue(b, boss.storage) end)

	local porcentagem = math.ceil(getPlayerStorageValue(players[1], boss.storage))

	for i = 1, table.maxn(players) do

		local tabela_reward = {}
		local pontos = getPlayerStorageValue(players[i], boss.storage)

		if i == 1 then
			addLoot(boss.comum, tabela_reward, false)
			addLoot(boss.semi_raro, tabela_reward, false)
			addLoot(boss.raro, tabela_reward, false)
			addLoot(boss.sempre, tabela_reward, true)
		elseif i >= 2 and pontos >= math.ceil((porcentagem * 0.8)) then
			addLoot(boss.comum, tabela_reward, false)
			addLoot(boss.semi_raro, tabela_reward, false)
			addLoot(boss.raro, tabela_reward, false)
			addLoot(boss.muito_raro, tabela_reward, false)
		elseif pontos < math.ceil((porcentagem * 0.8)) and pontos >= math.ceil((porcentagem * 0.6)) then
			addLoot(boss.comum, tabela_reward, false)
			addLoot(boss.semi_raro, tabela_reward, false)
			addLoot(boss.raro, tabela_reward, false)
		elseif pontos < math.ceil((porcentagem * 0.6)) and pontos >= math.ceil((porcentagem * 0.4)) then
			addLoot(boss.comum, tabela_reward, false)
			addLoot(boss.semi_raro, tabela_reward, false)
		elseif pontos < math.ceil((porcentagem * 0.4)) and pontos >= math.ceil((porcentagem * 0.1)) then
			addLoot(boss.comum, tabela_reward, false)
		end

		addRewardLoot(players[i], bossName, tabela_reward)
	end
end

function onDeath(cid, corpse, killer)
	local boss = REWARDCHEST.bosses[getCreatureName(cid):lower()]
	if boss then
		addEvent(rewardChestSystem, 1000, getCreatureName(cid):lower())
	end
	return true
end

function onStatsChange(cid, attacker, type, combat, value)
	if isMonster(cid) and type == STATSCHANGE_HEALTHLOSS and isPlayer(attacker) then
		local boss = REWARDCHEST.bosses[getCreatureName(cid):lower()]
		if boss and attacker then
			setPlayerStorageValue(attacker, boss.storage, getPlayerStorageValue(attacker, boss.storage) + math.ceil((value / REWARDCHEST.formula.hit)))
		end
	end
	return true
end

 


rewardchest_pontos.lua

Spoiler

-- Sistema de recompensa criado por luanluciano93

dofile('data/sistemas/rewardchest.lua')

function onLogin(cid)
	for key, value in pairs(REWARDCHEST.bosses) do
		if getPlayerStorageValue(cid, value.storage) > 0 then
			setPlayerStorageValue(cid, value.storage, 0)
		end
	end
	registerCreatureEvent(cid, "RewardChestStats")
	return true
end

function onStatsChange(cid, attacker, type, combat, value)
	if isMonster(attacker) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then
		local boss = REWARDCHEST.bosses[getCreatureName(attacker):lower()]
		if boss then
			setPlayerStorageValue(cid, boss.storage, getPlayerStorageValue(cid, boss.storage) + math.ceil((value / REWARDCHEST.formula.block)))
			setPlayerStorageValue(cid, REWARDCHEST.storageExaust, os.time() + 5)
		end
	elseif (isPlayer(attacker) and (type == STATSCHANGE_HEALTHGAIN or type == STATSCHANGE_MANAGAIN) and (getCreatureHealth(cid) < getCreatureMaxHealth(cid)) and (getPlayerStorageValue(cid, REWARDCHEST.storageExaust) >= os.time())) then
		for key, valor in pairs(REWARDCHEST.bosses) do
			if getPlayerStorageValue(cid, valor.storage) > 0 then
				if getCreatureHealth(cid) + value > getCreatureMaxHealth(cid) then
					local add = getCreatureMaxHealth(cid) - getCreatureHealth(cid)
					setPlayerStorageValue(attacker, valor.storage, getPlayerStorageValue(attacker, valor.storage) + math.ceil((add / REWARDCHEST.formula.suport)))
				else
					setPlayerStorageValue(attacker, valor.storage, getPlayerStorageValue(attacker, valor.storage) + math.ceil((value / REWARDCHEST.formula.suport)))
				end
			end
		end
	end
	return true
end

 


Lembrando que em todas as criaturas que forem adicionadas ao sistema além de coloca-las no rewarchest.lua você deve add isso no xml do monstro: 

<script> 
  <event name="RewardChestDeath"/>
  <event name="RewardChestMonster"/>
</script>

E isso no creaturescript.xml

<!-- Sistema de recompensa criado por luanluciano93 -->
<event type="login" name="RewardChestLogin" event="script" value="rewardchest_pontos.lua"/>
<event type="statschange" name="RewardChestStats" event="script" value="rewardchest_pontos.lua"/>
<event type="death" name="RewardChestDeath" event="script" value="rewardchest_boss.lua"/>
<event type="statschange" name="RewardChestMonster" event="script" value="rewardchest_boss.lua"/>


Basicamente é isso, qualquer dúvida postem aqui ... abraços!

LINK DO SCRIPT NO GITHUB: https://github.com/luanluciano93/ESTUDOS/tree/master/LUA/REWARD_SYSTEM_860

  • Respostas 92
  • Visualizações 19.9k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • luanluciano93
    luanluciano93

    msg = msg .. " ".. (tabela_reward[x][2] > 1 and tabela_reward[x][2] or "") .." ".. getItemNameById(tabela_reward[x][1]) ..","  

  • luanluciano93
    luanluciano93

    pessoal, só final de semana para fixar

  • Coloquei em meu servidor 8.60 (TFS 0.4) e funcionou de primeira sem erros na distro ou algo parecido. Sistema perfeito. Rep + !! Uma dica para quem quer imitar o global com este sistema e ter uma

Posted Images

Postado

Parabéns, seu tópico de conteúdo foi aprovado!
Muito obrigado pela sua contribuição, nós do Tibia King agradecemos.
Seu conteúdo com certeza ajudará à muitos outros, você recebeu +1 REP.

Spoiler

Congratulations, your content has been approved!
Thank you for your contribution, we of Tibia King we are grateful.
Your content will help many other users, you received +1 REP.

 

Postado

[15:35:23.415] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/rewardchest_boss.lua:17: unexpected symbol near '...'
[15:35:23.416] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/rewardchest_boss.lua)
[15:35:23.419] data/creaturescripts/scripts/rewardchest_boss.lua:17: unexpected symbol near '...'
[15:35:23.422] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/rewardchest_boss.lua:17: unexpected symbol near '...'
[15:35:23.424] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/rewardchest_boss.lua)
[15:35:23.428] data/creaturescripts/scripts/rewardchest_boss.lua:17: unexpected symbol near '...'

 

Este erro acontece quando mata o boss.

 

[15:37:26.088] [Error - CreatureScript Interface]
[15:37:26.093] In a timer event called from:
[15:37:26.096] data/creaturescripts/scripts/rewardchest_boss.lua:onDeath
[15:37:26.098] Description:
[15:37:26.103] (luaDoItemSetAttribute) Item not found

 

Versão TFS: 0.4 (8.60)

Editado por esnio12 (veja o histórico de edições)

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo