Hello, Everyone
Some one Can Edit the text to Can use like a stone in items
he is working like over some in order.
I Need Change To working on items like a stone
i fix Lib You can Look IN
OTX-Tibia 8.60
Action Code V He work like that V
<action actionid="12500" script="upgrade_leech.lua"/>
Need change To work like > <action itemid="12500" script="upgrade_leech.lua"/>
Some one Can Edit the text to Can use like a stone in items
he is working like over some in order.
I Need Change To working on items like a stone
i fix Lib You can Look IN
OTX-Tibia 8.60
Action Code V He work like that V
<action actionid="12500" script="upgrade_leech.lua"/>
Need change To work like > <action itemid="12500" script="upgrade_leech.lua"/>
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
--[[
stackpos 0: ground
stackpos 1: top item
...
stackpos last: top down item
]]
local tile = getTileInfo(toPosition)
if (tile) then
local upgradeItem = nil
local firstItemIndex = tile.things - 2
if (firstItemIndex > 0) then
toPosition.stackpos = firstItemIndex
upgradeItem = getLeechUpgrade(getThingFromPosition(toPosition))
else
doPlayerSendCancel(cid, "Coloque o item e a receita para dar upgrade.")
doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
return true
end
if (not upgradeItem) then
doPlayerSendCancel(cid, "Esse item não pode ser feito upgrade.")
doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
return true
end
if (upgradeItem:isAtMaxLifeLeech() and upgradeItem:isAtMaxManaLeech()) then
doPlayerSendCancel(cid, "Esse item já está com todos os atributos no maximo.")
doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
return true
end
local toRemove = {}
local recipe = upgradeItem:getRecipe()
for i = #recipe, 1, -1 do
toPosition.stackpos = firstItemIndex - i
local tileItem = getThingFromPosition(toPosition)
if (tileItem.itemid ~= recipe[i].itemId or math.max(1, tileItem.type) < recipe[i].count) then
doPlayerSendCancel(cid, "Receita invalida, coloque os items certos nas ordem correta.")
doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
return true
end
toRemove[#toRemove + 1] = {item = tileItem, count = recipe[i].count}
end
for i = 1, #toRemove do
doRemoveItem(toRemove[i].item.uid, toRemove[i].count)
end
if (upgradeItem:getBreakChance() < math.random(100)) then
upgradeItem:addLifeLeech(upgradeItem:getLifeLeechGain())
upgradeItem:addManaLeech(upgradeItem:getManaLeechGain())
upgradeItem:addBreakChance(upgradeItem:getBreakChanceGain())
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Upgrade feito com sucesso.")
doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_BLUE)
else
doRemoveItem(upgradeItem.item.uid)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "O item foi quebrado.")
doSendMagicEffect(getThingPosition(cid), CONST_ME_BLOCKHIT)
return true
end
else
doPlayerSendCancel(cid, "Piso invalido.")
doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
end
return true
end
Lua:
LeechUpgrade = {
life_leech_attribute = "LULifeLeech", -- atributo do life leech
mana_leech_attribute = "LUManaLeech", -- atributo do mana leech
break_chance_attribute = "LUBreakChance", -- atributo da chance de quebrar
break_chance_per_upgrade = 10, -- aumento da chance de quebrar por uso
max_life_leech = 10, -- maximo de life leech
max_mana_leech = 10, -- maximo de mana leech
-- Knights
items = {
-- Assault sword
[8931] = {
slot = "hands", -- slot
life_leech_gain = {1, 3}, -- ganho de life leech {min, max}
mana_leech_gain = {1, 1}, -- ganho de mana leech {min, max}
-- receita na ordem apos a arma
recipe_order = {
[1] = {itemId = 8301, count = 1}, -- Gold Nugget
}
},
-- Assault Axe
[8927] = {
slot = "hands", -- slot
life_leech_gain = {1, 3}, -- ganho de life leech {min, max}
mana_leech_gain = {1, 1}, -- ganho de mana leech {min, max}
-- receita na ordem apos a arma
recipe_order = {
[1] = {itemId = 8301, count = 1}, -- Gold Nugget
}
},
-- Assault Mace
[8926] = {
slot = "hands", -- slot
life_leech_gain = {1, 3}, -- ganho de life leech {min, max}
mana_leech_gain = {1, 1}, -- ganho de mana leech {min, max}
-- receita na ordem apos a arma
recipe_order = {
[1] = {itemId = 10558, count = 1}, -- Gold Nugget
}
},
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Paladins
-- Assault Bowbolt
[8850] = {
slot = "hands", -- slot
life_leech_gain = {1, 2}, -- ganho de life leech {min, max}
mana_leech_gain = {1, 2}, -- ganho de mana leech {min, max}
-- receita na ordem apos a arma
recipe_order = {
[1] = {itemId = 8301, count = 1}, -- Gold Nugget
}
},
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Mages
-- Starlix Staff
[2453] = {
slot = "hands", -- slot
life_leech_gain = {1, 1}, -- ganho de life leech {min, max}
mana_leech_gain = {1, 3}, -- ganho de mana leech {min, max}
-- receita na ordem apos a arma
recipe_order = {
[1] = {itemId = 8301, count = 1}, -- Gold Nugget
}
},
}
}
local translateSlot = {
["head"] = CONST_SLOT_HEAD,
["helmet"] = CONST_SLOT_HEAD,
["necklace"] = CONST_SLOT_NECKLACE,
["amulet"] = CONST_SLOT_NECKLACE,
["backpack"] = CONST_SLOT_BACKPACK,
["bag"] = CONST_SLOT_BACKPACK,
["armor"] = CONST_SLOT_ARMOR,
["body"] = CONST_SLOT_ARMOR,
["right"] = CONST_SLOT_RIGHT,
["right-hand"] = CONST_SLOT_RIGHT,
["hand-right"] = CONST_SLOT_RIGHT,
["left"] = CONST_SLOT_LEFT,
["left-hand"] = CONST_SLOT_LEFT,
["hand-left"] = CONST_SLOT_LEFT,
["legs"] = CONST_SLOT_LEGS,
["feet"] = CONST_SLOT_FEET,
["boots"] = CONST_SLOT_FEET,
["ring"] = CONST_SLOT_RING,
["ammo"] = CONST_SLOT_AMMO,
["ammunation"] = CONST_SLOT_AMMO,
["hand"] = {CONST_SLOT_RIGHT, CONST_SLOT_LEFT},
["hands"] = {CONST_SLOT_RIGHT, CONST_SLOT_LEFT}
}
-- Item metatable
function getLeechUpgrade(item)
local itemInfo = LeechUpgrade.items[item.itemid]
if (itemInfo) then
return setmetatable({item = item, info = itemInfo}, {__index = LeechUpgrade})
end
return nil
end
function LeechUpgrade:getLifeLeechGain()
return math.random(self.info.life_leech_gain[1], self.info.life_leech_gain[2])
end
function LeechUpgrade:getManaLeechGain()
return math.random(self.info.mana_leech_gain[1], self.info.mana_leech_gain[2])
end
function LeechUpgrade:getBreakChanceGain()
return self.break_chance_per_upgrade
end
function LeechUpgrade:isInRightSlot(slot)
local wieldSlot = translateSlot[self.info.slot]
if (type(wieldSlot) == "table") then
return isInArray(wieldSlot, slot)
end
return wieldSlot == slot
end
function LeechUpgrade:getRecipe()
return self.info.recipe_order
end
-- Get
function LeechUpgrade:getLifeLeech()
return math.max(0, tonumber(getItemAttribute(self.item.uid, self.life_leech_attribute)) or 0)
end
function LeechUpgrade:getManaLeech()
return math.max(0, tonumber(getItemAttribute(self.item.uid, self.mana_leech_attribute)) or 0)
end
function LeechUpgrade:getBreakChance()
return math.max(0, tonumber(getItemAttribute(self.item.uid, self.break_chance_attribute)) or 0)
end
-- Set
function LeechUpgrade:setLifeLeech(value)
doItemSetAttribute(self.item.uid, self.life_leech_attribute, value)
end
function LeechUpgrade:setManaLeech(value)
doItemSetAttribute(self.item.uid, self.mana_leech_attribute, value)
end
function LeechUpgrade:setBreakChance(value)
doItemSetAttribute(self.item.uid, self.break_chance_attribute, value)
end
-- Add
function LeechUpgrade:addLifeLeech(value)
doItemSetAttribute(self.item.uid, self.life_leech_attribute, math.min(self.max_life_leech, self:getLifeLeech() + value))
end
function LeechUpgrade:addManaLeech(value)
doItemSetAttribute(self.item.uid, self.mana_leech_attribute, math.min(self.max_mana_leech, self:getManaLeech() + value))
end
function LeechUpgrade:addBreakChance(value)
doItemSetAttribute(self.item.uid, self.break_chance_attribute, self:getBreakChance() + value)
end
-- Is
function LeechUpgrade:isAtMaxLifeLeech()
return self:getLifeLeech() == self.max_life_leech
end
function LeechUpgrade:isAtMaxManaLeech()
return self:getManaLeech() == self.max_mana_leech
end
-- Description
function LeechUpgrade:getLifeLeechDescription()
local lifeLeech = self:getLifeLeech()
if (lifeLeech <= 0) then
return "Nenhum"
end
return lifeLeech .. "%% Life Leech"
end
function LeechUpgrade:getManaLeechDescription()
local manaLeech = self:getManaLeech()
if (manaLeech <= 0) then
return "Nenhum"
end
return manaLeech .. "%% Mana Leech"
end
Last edited: