• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Need help with this script!

Kakaher

Member
Joined
Nov 2, 2009
Messages
129
Reaction score
7
Hello everybody!

I found a refine system on the internet, but I can´t get it to work..
It would be great if somebody could please help me out...

here is the lib:
LUA:
-- Perfect Refine System
 
Refine = {
        --[[
                Base de todo o sistema de refino
        ]]--
        config = {
                max = 10, -- Nível máximo de refino padrão
                message = { -- Mensagens enviadas pelo sistema
                        type = MESSAGE_EVENT_DEFAULT,
                        onSuccess = "Your %s has upgraded to level +%s",
                        onFail = "Your %s has downgraded to level +%s",
                        onBreak = "Your %s has broken",
                        invalidGem = "This is not a valid refine gem",
                        gemLevel = "This gem can refine only to level +%s",
                        maxLevel = "Your %s is already in max level"
                },
                --[[
               
                        O seguinte array controla os diferentes atributos que podem
                        melhorados no refino.
                       
                        attributes = {{"attack", true}, {"defense", true}, {"armor", false}}
                       
                        A configuração dele é realmente simples, os valores booleanos dizem respeito
                        ao ganho de pontos no referido atributo. Se 'true' o ganho é igual ao nível do item,
                        se 'false' o ganho é 1.
                       
                        Note que eu configurei para 'attack', 'defense' como 'true' e 'armor' e 'hitchance' como 'false'.
 
                ]]--
                attributes = {{"attack", true}, {"defense", true}, {"armor", false}},
                --[[
                ´      Este array configura o sistema de quebra de equipamento, deixando o sistema muito mais real.
               
                        Configurei para que a quebra só fosse possível depois do +7 com uma chance de 20%.
                       
                        Ou seja se o jogador falhar no refino de um equipamento +7 ou superior, tem 20% de chance de quebrar
                        e perder este equipamento.
                ]]--
                breakConfig = {level = 7, chance = 20},
                --[[
                        Essa opção ativa o broadcast para quando o jogador refinar um equipamento para +7 ou mais.
                ]]--
                doBroadcast = true,
                --[[
                        Essa função calcula a chance de sucesso do refino, veja a chance de alguns.
                       
                        +1      = 100%
                        +2      = 91%
                        +3      = 81%
                        ...    
                        +10     = 10%
                ]]--
                chance = function(level)
                        return math.floor(100 - (((level * 2 * 3) - (level + 1)) * 2.04))
                end
        },
       
        gems = {
                --[[
                        Configure aqui as "pedras" que refinam itens.
                       
                        Você pode configurar quantas pedras quiser e limitar o nível que essa pedra pode fortalecer.
                       
                        Configurei duas, uma pode fortalecer até +6 e a outra até +10.
                       
                        Você pode criar também pedras que dão bônus na chance total de refino :)
                ]]--
                [8306] = {max = 6, bonus = 0},
                [8303] = {max = 10, bonus = 0}
        },
       
        isEquipment = function(self)
                local weapontype = self:getItemWeaponType()
                if (weapontype > 0 and weapontype < 7) or self.item.info.armor ~= 0 then
                        return true
                end
                return false
        end,
       
        setItemName = function(self, name)
                return doItemSetAttribute(self.item.uid, "name", name)
        end,
       
        getItemKeyValue = function(self, key)
                return getItemAttribute(self.item.uid, key)
        end,
       
        setItemKeyValue = function(self, key, value)
                return doItemSetAttribute(self.item.uid, key, value)
        end,
       
        removeItem = function(self, count)
                return doRemoveItem(self.item.uid, count)
        end
}
 
function Refine:load(item)
        --[[
                Função que carrega o item a ser refinado na forma de um objeto.
               
                E você pode usar qualquer função Lua/Open Tibia que se utilize do uid do item como
                um método da classe Refine
               
                Ou seja, é totalmente possível fazer isso em uma Action, por exemplo:
               
                        local obj = Refine:load(itemEx)
                        obj:doRemoveItem(1)
                       
                Ao invés de
               
                        doRemoveItem(item.uid, 1)
                       
                end
        ]]--
        local obj = setmetatable({item = {uid = item.uid, info = getItemInfo(item.itemid)}}, {__index = function(self, index)
                if _G[index] then
                        return setmetatable({callback = _G[index]}, {__call = function(self, ...)
                                return self.callback(item.uid, ...)
                        end})
                else
                        return Refine[index]
                end
        end})
       
        if not obj:isEquipment() then
                return false
        end
        obj:getLevel()
        return obj
end
 
function Refine:getLevel()
        local info = self:getItemName():match("%+(%d+)")
        self.item.level = (tonumber(info) or 0)
        return true
end
 
function Refine:upgrade(cid, gem)
        --[[
                Função principal do sistema
        ]]--
        local refineItem = self.gems[gem.itemid]
       
        if not refineItem then
                doPlayerSendTextMessage(cid, self.config.message.type, self.config.message.invalidGem)
                return false
        end
       
        if self.item.level == self.config.maxLevel then
                doPlayerSendTextMessage(cid, self.config.message.type, self.config.message.maxLevel)
                return false
        else
                if self.item.level >= refineItem.max then
                        doPlayerSendTextMessage(cid, self.config.message.type, self.config.message.gemLevel:format(refineItem.max))
                        return false
                end
        end
       
        doRemoveItem(gem.uid, 1)
        if math.random(1, 100) <= self.config.chance(self.item.level) + refineItem.bonus then
                doPlayerSendTextMessage(cid, self.config.message.type, self.config.message.onSuccess:format(self:getItemName(), (self.item.level + 1)))
                if self.config.doBroadcast == true and (self.item.level + 1) >= 7 then
                        doBroadcastMessage("The ".. self:getItemName() .." of ".. getCreatureName(cid) .." is now in level +".. self.item.level + 1 ..".")
                end
                if self.item.level > 0 then
                        self:setItemName(self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)))
                        local p = self.config.attributes
                        for i = 1, #p do
                                if self:getItemKeyValue(p[i][1]) ~= nil then
                                        self:setItemKeyValue(p[i][1], (self:getItemKeyValue(p[i][1]) + (p[i][2] == true and (self.item.level + 1) or 1)))
                                end
                        end
                else
                        self:setItemName(self:getItemName() .." +1")
                        local p = self.config.attributes
                        for i = 1, #p do
                                if self.item.info[p[i][1]] ~= 0 or self:getItemWeaponType() ~= 5 then
                                        self:setItemKeyValue(p[i][1], self.item.info[p[i][1]] + 1)
                                end
                        end
                end
                return true
        else
                doPlayerSendTextMessage(cid, self.config.message.type, self.config.message.onFail:format(self:getItemName(), (self.item.level - 1)))
                if self.config.breakConfig.chance > 0 and math.random(1, 100) <= self.config.breakConfig.chance and self.item.level >= self.config.breakConfig.level then
                        doPlayerSendTextMessage(cid, self.config.message.type, self.config.message.onBreak:format(self:getItemName()))
                        self:removeItem(1)
                else
                        if self.item.level > 1 then
                                self:setItemName(self:getItemName():gsub("%+(%d+)", "+".. (self.item.level - 1)))
                                local p = self.config.attributes
                                for i = 1, #p do
                                        if self:getItemKeyValue(p[i][1]) ~= nil then
                                                self:setItemKeyValue(p[i][1], (self:getItemKeyValue(p[i][1]) - (p[i][2] == true and self.item.level or 1)))
                                        end
                                end
                        else
                                self:setItemName(self.item.info.name)
                                local p = self.config.attributes
                                for i = 1, #p do
                                        if self.item.info[p[i][1]] ~= 0 or self:getItemWeaponType() ~= 5 then
                                                self:setItemKeyValue(p[i][1], self.item.info[p[i][1]])
                                        end
                                end
                        end
                end
                return false
        end
end

and here is the action:
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local obj = Refine:load(itemEx)
        if obj and obj:upgrade(cid, item) then
                doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
        else
                doSendMagicEffect(toPosition, CONST_ME_POFF)
                return false
        end
        return true
end

When I try to refine any item, I get this error:
Code:
[Error - Action Interface]
data/actions/scripts/refine.lua:onUse
Description:
data/lib/refine.lua:162: attemp to call field 'chance' (a nill  value)
stack traceback:
data/lib/refine.lua:162: in function 'upgrade'
data/actions/scripts/refine.lua:3 in function <data/actions/scripts/refine.lua:1>

Thanks already everybody for the help!
I´ll rep!

----EDIT
Ok, I found what the problem is...

I also have this script on my server:
LUA:
--[[
Ressurect Rune System 2.0
Developed by Notorious
If you modify, please preserve credits
--]]

local function getCorpseInfo(uid) --~ function by Notorious
local description = getItemSpecialDescription(uid)
local _,_,owner_,killer_ = string.find(description, "You recognize (.+)%. %a* was killed by %a*%s*(.+)%.")
return {owner = owner_ or nil, killer = killer_ or nil}
end

--~ These vars are not local because we have to use it in the talkaction
deactivated, activated = -1, 1 --~ Change only if you know what you are doing
config = {
stoCheck = 100,
stoPosx = 101,
stoPosy = 102,
stoPosz = 103,
corpses = {6080, 3058, 3059, 2960},
securityDelay = 60 -- Seconds
}

function onUse(cid, item, frompos, item2, topos)

if item2.uid == cid then
return doPlayerSendCancel(cid, "You cannot use this rune on yourself.")
end


if isInArray(config.corpses, item2.itemid) then --~ Is it a valid corpse?
local owner = getCorpseInfo(item2.uid).owner
if owner then --~ Is it a player corpse?
owner = getCreatureByName(owner)
if isPlayer(owner) then --~ Is the player online?
doPlayerSendTextMessage(owner, MESSAGE_STATUS_CONSOLE_ORANGE, "Through the request from " .. getCreatureName(cid) .. " the gods are trying to ressurect you. Do you accept?")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You requested the gods to ressurect " .. getCreatureName(owner) .. ".")
doPlayerSetStorageValue(owner, config.stoCheck, activated)
addEvent(doPlayerSetStorageValue, config.securityDelay*1000, owner, config.stoCheck, deactivated)
-- Store corpse position --
doPlayerSetStorageValue(owner, config.stoPosx, getThingPos(item2.uid).x)
doPlayerSetStorageValue(owner, config.stoPosy, getThingPos(item2.uid).y)
doPlayerSetStorageValue(owner, config.stoPosz, getThingPos(item2.uid).z)
----------------------------
doSendMagicEffect(getThingPos(item2.uid), 2) doSendMagicEffect(getThingPos(item2.uid), 56)
doRemoveItem(item.uid, 1) doRemoveItem(item2.uid)
else
doPlayerSendCancel(cid, "The owner of this corpse is not online.")
end
else
doPlayerSendCancel(cid, "This is not a corpse from a player.")
end
end

return true
end

For some reason this script makes the refine system to not work anymore...
Does anybody know why ?
 
Last edited:
Back
Top