Ir para conteúdo

Problemas com espaços no final


maikons

Posts Recomendados

Script do oneshot

http://www.xtibia.com/forum/topic/187075-perfect-upgrade-system/

 

Pessoal do fórum modificou, mas ficou com um problema

 

 

--[[
 
        PERFECT UPGRADE SYSTEM
        2.0
 
        Criado por Oneshot
 
        É proibido a venda ou a cópia sem os devidos créditos desse script.
 
]]--
 
UpgradeHandler = {
    levels = {
        [1] = {90, false, false},
        [2] = {80, false, false},
        [3] = {70, false, false},
        [4] = {60, true, false},
        [5] = {40, true, true}
    },
    broadcast = 8,
    attributes = {
        ["attack"] = 1,
        ["defense"] = 1,
        ["armor"] = 1
    },
    message = {
        console = "Trying to refine %s to level +%s with %s%% success rate.",
        success = "You have upgraded %s to level +%s",
        fail = "You have failed in upgrade of %s to level +%s",
        downgrade = "The upgrade level of %s has downgraded to +%s",
        erase = "The upgrade level of %s has been erased.",
        maxlevel = "The targeted %s is already on max upgrade level.",
        notupgradeable = "This item is not upgradeable.",
        broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
        invalidtool = "This is not a valid upgrade tool.",
        toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
    },
    tools = {
        [8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},
        [8300] = {range = {0, 10}, info = {chance = 0, removeable = true}},
    },
 
    isEquipment = function(self)
        local weaponType = self:getItemWeaponType()
        return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
    end,
 
    setItemName = function(self, name)
        return doItemSetAttribute(self.item.uid, "name", name)
    end,
 
    chance = function(self)
        local chances = {}
        chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
        chances.downgrade = (self.item.level * 5)
        chances.erase = (self.item.level * 3)
 
        return chances
    end
}
 
function UpgradeHandler:new(item)
    local obj, ret = {}
    obj.item = {}
 
    obj.item.level = 0
    obj.item.uid = item.uid
    for key, value in pairs(getItemInfo(item.itemid)) do
        obj.item[key] = value
    end
 
    ret = setmetatable(obj, {__index = function(self, index)
        if _G[index] then
            return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
            return self.callback(item.uid, ...)
            end}))
        else
            return UpgradeHandler[index]
        end
    end})
 
    if ret:isEquipment() then
        ret:update()
        return ret
    end
    return false
end
 
function UpgradeHandler:update()
    self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end
 
function UpgradeHandler:refine(uid, item)
    if not self.item then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
        return "miss"
    end
 
    local tool = self.tools[item.itemid]
 
    if(tool == nil) then
        doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
        return "miss"
    end
 
    if(self.item.level > #self.levels) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
        return "miss"
    end
 
    if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
        return "miss"
    end
 
    local chance = (self:chance().upgrade + tool.info.chance)
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
 
    if(tool.info.removeable == true) then
        doRemoveItem(item.uid, 1)
    end
 
    if chance * 100 > math.random(1, 10000) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
        end
 
        self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
        for key, value in pairs(self.attributes) do
            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
        end
        return "success"
    else
        if item.itemid == 8300 then
            if self.item.level > 0 then
                self:setItemName(self:getItemName():gsub("%+(%d+)", ""))
                for key, value in pairs(self.attributes) do
                    if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                        doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)
                    end
                end
            end
        else
            doRemoveItem(self.item.uid, 1)
        end
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")
    end
end

 

Se você erra com a pedra ID: 8300, a arma continua com os espaços que foram criados pra escrever o +1 e se você continua errando, continua tendo mais espaços até ficar igual a minha arma

 

21:27 You see a thaian sword                            +6 (Atk:52, Def:35).
It weighs 61.00 oz.
ItemID: [7391].
Position: [X: 982] [Y: 1013] [Z: 7].

 

E não para nunca, fica com espaços pra crl!

Link para o comentário
Compartilhar em outros sites

tente assim

--[[
 
        PERFECT UPGRADE SYSTEM
        2.0
 
        Criado por Oneshot
 
        É proibido a venda ou a cópia sem os devidos créditos desse script.
 
]]--
 
UpgradeHandler = {
    levels = {
        [1] = {90, false, false},
        [2] = {80, false, false},
        [3] = {70, false, false},
        [4] = {60, true, false},
        [5] = {40, true, true}
    },
    broadcast = 8,
    attributes = {
        ["attack"] = 1,
        ["defense"] = 1,
        ["armor"] = 1
    },
    message = {
        console = "Trying to refine %s to level +%s with %s%% success rate.",
        success = "You have upgraded %s to level +%s",
        fail = "You have failed in upgrade of %s to level +%s",
        downgrade = "The upgrade level of %s has downgraded to +%s",
        erase = "The upgrade level of %s has been erased.",
        maxlevel = "The targeted %s is already on max upgrade level.",
        notupgradeable = "This item is not upgradeable.",
        broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
        invalidtool = "This is not a valid upgrade tool.",
        toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
    },
    tools = {
        [8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},
        [8300] = {range = {0, 10}, info = {chance = 0, removeable = true}},
    },
 
    isEquipment = function(self)
        local weaponType = self:getItemWeaponType()
        return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
    end,
 
    setItemName = function(self, name)
        return doItemSetAttribute(self.item.uid, "name", name)
    end,
 
    chance = function(self)
        local chances = {}
        chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
        chances.downgrade = (self.item.level * 5)
        chances.erase = (self.item.level * 3)
 
        return chances
    end
}
 
function UpgradeHandler:new(item)
    local obj, ret = {}
    obj.item = {}
 
    obj.item.level = 0
    obj.item.uid = item.uid
    for key, value in pairs(getItemInfo(item.itemid)) do
        obj.item[key] = value
    end
 
    ret = setmetatable(obj, {__index = function(self, index)
        if _G[index] then
            return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
            return self.callback(item.uid, ...)
            end}))
        else
            return UpgradeHandler[index]
        end
    end})
 
    if ret:isEquipment() then
        ret:update()
        return ret
    end
    return false
end
 
function UpgradeHandler:update()
    self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end
 
function UpgradeHandler:refine(uid, item)
    if not self.item then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
        return "miss"
    end
 
    local tool = self.tools[item.itemid]
 
    if(tool == nil) then
        doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
        return "miss"
    end
 
    if(self.item.level > #self.levels) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
        return "miss"
    end
 
    if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
        return "miss"
    end
 
    local chance = (self:chance().upgrade + tool.info.chance)
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
 
    if(tool.info.removeable == true) then
        doRemoveItem(item.uid, 1)
    end
 
    if chance * 100 > math.random(1, 10000) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
        end
 
        self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
        for key, value in pairs(self.attributes) do
            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
        end
        return "success"
    else
        if item.itemid == 8300 then
            if self.item.level < 0 then
                self:setItemName(self:getItemName():gsub("%+(%d+)", ""))
                for key, value in pairs(self.attributes) do
                    if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                        doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)
                    end
                end
            end
        else
            doRemoveItem(self.item.uid, 1)
        end
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")
    end
end
Link para o comentário
Compartilhar em outros sites

 

tente assim

--[[
 
        PERFECT UPGRADE SYSTEM
        2.0
 
        Criado por Oneshot
 
        É proibido a venda ou a cópia sem os devidos créditos desse script.
 
]]--
 
UpgradeHandler = {
    levels = {
        [1] = {90, false, false},
        [2] = {80, false, false},
        [3] = {70, false, false},
        [4] = {60, true, false},
        [5] = {40, true, true}
    },
    broadcast = 8,
    attributes = {
        ["attack"] = 1,
        ["defense"] = 1,
        ["armor"] = 1
    },
    message = {
        console = "Trying to refine %s to level +%s with %s%% success rate.",
        success = "You have upgraded %s to level +%s",
        fail = "You have failed in upgrade of %s to level +%s",
        downgrade = "The upgrade level of %s has downgraded to +%s",
        erase = "The upgrade level of %s has been erased.",
        maxlevel = "The targeted %s is already on max upgrade level.",
        notupgradeable = "This item is not upgradeable.",
        broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
        invalidtool = "This is not a valid upgrade tool.",
        toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
    },
    tools = {
        [8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},
        [8300] = {range = {0, 10}, info = {chance = 0, removeable = true}},
    },
 
    isEquipment = function(self)
        local weaponType = self:getItemWeaponType()
        return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
    end,
 
    setItemName = function(self, name)
        return doItemSetAttribute(self.item.uid, "name", name)
    end,
 
    chance = function(self)
        local chances = {}
        chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
        chances.downgrade = (self.item.level * 5)
        chances.erase = (self.item.level * 3)
 
        return chances
    end
}
 
function UpgradeHandler:new(item)
    local obj, ret = {}
    obj.item = {}
 
    obj.item.level = 0
    obj.item.uid = item.uid
    for key, value in pairs(getItemInfo(item.itemid)) do
        obj.item[key] = value
    end
 
    ret = setmetatable(obj, {__index = function(self, index)
        if _G[index] then
            return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
            return self.callback(item.uid, ...)
            end}))
        else
            return UpgradeHandler[index]
        end
    end})
 
    if ret:isEquipment() then
        ret:update()
        return ret
    end
    return false
end
 
function UpgradeHandler:update()
    self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end
 
function UpgradeHandler:refine(uid, item)
    if not self.item then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
        return "miss"
    end
 
    local tool = self.tools[item.itemid]
 
    if(tool == nil) then
        doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
        return "miss"
    end
 
    if(self.item.level > #self.levels) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
        return "miss"
    end
 
    if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
        return "miss"
    end
 
    local chance = (self:chance().upgrade + tool.info.chance)
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
 
    if(tool.info.removeable == true) then
        doRemoveItem(item.uid, 1)
    end
 
    if chance * 100 > math.random(1, 10000) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
        end
 
        self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
        for key, value in pairs(self.attributes) do
            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
        end
        return "success"
    else
        if item.itemid == 8300 then
            if self.item.level < 0 then
                self:setItemName(self:getItemName():gsub("%+(%d+)", ""))
                for key, value in pairs(self.attributes) do
                    if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                        doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)
                    end
                end
            end
        else
            doRemoveItem(self.item.uid, 1)
        end
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")
    end
end

 

Nesse script q se passou qnd falha com a 8300 nada acontece, ela continua com o mesmo dano, diz q quebrou, mas continua lá o msm atk

 

Link para o comentário
Compartilhar em outros sites

--[[
 
        PERFECT UPGRADE SYSTEM
        2.0
 
        Criado por Oneshot
 
        É proibido a venda ou a cópia sem os devidos créditos desse script.
 
]]--
 
UpgradeHandler = {
    levels = {
        [1] = {90, false, false},
        [2] = {80, false, false},
        [3] = {70, false, false},
        [4] = {60, true, false},
        [5] = {40, true, true}
    },
    broadcast = 8,
    attributes = {
        ["attack"] = 1,
        ["defense"] = 1,
        ["armor"] = 1
    },
    message = {
        console = "Trying to refine %s to level +%s with %s%% success rate.",
        success = "You have upgraded %s to level +%s",
        fail = "You have failed in upgrade of %s to level +%s",
        downgrade = "The upgrade level of %s has downgraded to +%s",
        erase = "The upgrade level of %s has been erased.",
        maxlevel = "The targeted %s is already on max upgrade level.",
        notupgradeable = "This item is not upgradeable.",
        broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
        invalidtool = "This is not a valid upgrade tool.",
        toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
    },
    tools = {
        [8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},
        [8300] = {range = {0, 10}, info = {chance = 0, removeable = true}},
    },
 
    isEquipment = function(self)
        local weaponType = self:getItemWeaponType()
        return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
    end,
 
    setItemName = function(self, name)
        return doItemSetAttribute(self.item.uid, "name", name)
    end,
 
    chance = function(self)
        local chances = {}
        chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
        chances.downgrade = (self.item.level * 5)
        chances.erase = (self.item.level * 3)
 
        return chances
    end
}
 
function UpgradeHandler:new(item)
    local obj, ret = {}
    obj.item = {}
 
    obj.item.level = 0
    obj.item.uid = item.uid
    for key, value in pairs(getItemInfo(item.itemid)) do
        obj.item[key] = value
    end
 
    ret = setmetatable(obj, {__index = function(self, index)
        if _G[index] then
            return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
            return self.callback(item.uid, ...)
            end}))
        else
            return UpgradeHandler[index]
        end
    end})
 
    if ret:isEquipment() then
        ret:update()
        return ret
    end
    return false
end
 
function UpgradeHandler:update()
    self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end
 
function UpgradeHandler:refine(uid, item)
    if not self.item then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
        return "miss"
    end
 
    local tool = self.tools[item.itemid]
 
    if(tool == nil) then
        doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
        return "miss"
    end
 
    if(self.item.level > #self.levels) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
        return "miss"
    end
 
    if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
        return "miss"
    end
 
    local chance = (self:chance().upgrade + tool.info.chance)
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
 
    if(tool.info.removeable == true) then
        doRemoveItem(item.uid, 1)
    end
 
    if chance * 100 > math.random(1, 10000) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
        end
 
        self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
        for key, value in pairs(self.attributes) do
            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
        end
        return "success"
    else
        if item.itemid == 8300 then
            if self.item.level >= 0 then
                self:setItemName(self:getItemName():gsub("%+(%d+)", ""))
                for key, value in pairs(self.attributes) do
                    if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                        doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)
                    end
                end
            end
        else
            doRemoveItem(self.item.uid, 1)
        end
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")
    end
end

veja agora

Link para o comentário
Compartilhar em outros sites

--[[
 
        PERFECT UPGRADE SYSTEM
        2.0
 
        Criado por Oneshot
 
        É proibido a venda ou a cópia sem os devidos créditos desse script.
 
]]--
 
UpgradeHandler = {
    levels = {
        [1] = {90, false, false},
        [2] = {80, false, false},
        [3] = {70, false, false},
        [4] = {60, true, false},
        [5] = {40, true, true}
    },
    broadcast = 8,
    attributes = {
        ["attack"] = 1,
        ["defense"] = 1,
        ["armor"] = 1
    },
    message = {
        console = "Trying to refine %s to level +%s with %s%% success rate.",
        success = "You have upgraded %s to level +%s",
        fail = "You have failed in upgrade of %s to level +%s",
        downgrade = "The upgrade level of %s has downgraded to +%s",
        erase = "The upgrade level of %s has been erased.",
        maxlevel = "The targeted %s is already on max upgrade level.",
        notupgradeable = "This item is not upgradeable.",
        broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
        invalidtool = "This is not a valid upgrade tool.",
        toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
    },
    tools = {
        [8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},
        [8300] = {range = {0, 10}, info = {chance = 0, removeable = true}},
    },
 
    isEquipment = function(self)
        local weaponType = self:getItemWeaponType()
        return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
    end,
 
    setItemName = function(self, name)
        return doItemSetAttribute(self.item.uid, "name", name)
    end,
 
    chance = function(self)
        local chances = {}
        chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
        chances.downgrade = (self.item.level * 5)
        chances.erase = (self.item.level * 3)
 
        return chances
    end
}
 
function UpgradeHandler:new(item)
    local obj, ret = {}
    obj.item = {}
 
    obj.item.level = 0
    obj.item.uid = item.uid
    for key, value in pairs(getItemInfo(item.itemid)) do
        obj.item[key] = value
    end
 
    ret = setmetatable(obj, {__index = function(self, index)
        if _G[index] then
            return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
            return self.callback(item.uid, ...)
            end}))
        else
            return UpgradeHandler[index]
        end
    end})
 
    if ret:isEquipment() then
        ret:update()
        return ret
    end
    return false
end
 
function UpgradeHandler:update()
    self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end
 
function UpgradeHandler:refine(uid, item)
    if not self.item then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
        return "miss"
    end
 
    local tool = self.tools[item.itemid]
 
    if(tool == nil) then
        doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
        return "miss"
    end
 
    if(self.item.level > #self.levels) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
        return "miss"
    end
 
    if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
        return "miss"
    end
 
    local chance = (self:chance().upgrade + tool.info.chance)
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
 
    if(tool.info.removeable == true) then
        doRemoveItem(item.uid, 1)
    end
 
    if chance * 100 > math.random(1, 10000) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
        end
 
        self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
        for key, value in pairs(self.attributes) do
            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
        end
        return "success"
    else
        if item.itemid == 8300 then
            if self.item.level >= 0 then
                self:setItemName(self:getItemName():gsub("%+(%d+)", ""))
                for key, value in pairs(self.attributes) do
                    if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                        doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)
                    end
                end
            end
        else
            doRemoveItem(self.item.uid, 1)
        end
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")
    end
end

veja agora

 

 

Agora voltou o problema dos espaços

 

17:20 You see a magic longsword    +1 (Atk:56, Def:41).
It can only be wielded properly by knights.
It weighs 43.00 oz.
It is the magic Cyclopmania Sword.
ItemID: [2390].
Position: [X: 948] [Y: 994] [Z: 8].

 

 

Link para o comentário
Compartilhar em outros sites

Mas o resto funcionou bem? ou não?

 

Sim, ta refinando (aumentando o atk/def) igual o meu primeiro script que eu postei, mas fica com um maldito espaço e ele não volta qnd reseta a arma

Link para o comentário
Compartilhar em outros sites


--[[
PERFECT UPGRADE SYSTEM
2.0
Criado por Oneshot
É proibido a venda ou a cópia sem os devidos créditos desse script.
]]--
UpgradeHandler = {
levels = {
[1] = {90, false, false},
[2] = {80, false, false},
[3] = {70, false, false},
[4] = {60, true, false},
[5] = {40, true, true}
},
broadcast = 8,
attributes = {
["attack"] = 1,
["defense"] = 1,
["armor"] = 1
},
message = {
console = "Trying to refine %s to level +%s with %s%% success rate.",
success = "You have upgraded %s to level +%s",
fail = "You have failed in upgrade of %s to level +%s",
downgrade = "The upgrade level of %s has downgraded to +%s",
erase = "The upgrade level of %s has been erased.",
maxlevel = "The targeted %s is already on max upgrade level.",
notupgradeable = "This item is not upgradeable.",
broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
invalidtool = "This is not a valid upgrade tool.",
toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
},
tools = {
[8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},
[8300] = {range = {0, 10}, info = {chance = 0, removeable = true}}
},
isEquipment = function(self)
local weaponType = self:getItemWeaponType()
return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
end,
setItemName = function(self, name)
return doItemSetAttribute(self.item.uid, "name", name)
end,
chance = function(self)
local chances = {}
chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
chances.downgrade = (self.item.level * 5)
chances.erase = (self.item.level * 3)
return chances
end
}
function UpgradeHandler:new(item)
local obj, ret = {}
obj.item = {}
obj.item.level = 0
obj.item.uid = item.uid
for key, value in pairs(getItemInfo(item.itemid)) do
obj.item[key] = value
end
ret = setmetatable(obj, {__index = function(self, index)
if _G[index] then
return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
return self.callback(item.uid, ...)
end}))
else
return UpgradeHandler[index]
end
end})
if ret:isEquipment() then
ret:update()
return ret
end
return false
end
function UpgradeHandler:update()
self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end
function UpgradeHandler:refine(uid, item)
if not self.item then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
return "miss"
end
local tool = self.tools[item.itemid]
if(tool == nil) then
doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
return "miss"
end
if(self.item.level > #self.levels) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
return "miss"
end
if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
return "miss"
end
local chance = (self:chance().upgrade + tool.info.chance)
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
if(tool.info.removeable == true) then
doRemoveItem(item.uid, 1)
end
if chance * 100 > math.random(1, 10000) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
if (self.item.level + 1) >= self.broadcast then
doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
end
self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
for key, value in pairs(self.attributes) do
if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
end
end
return "success"
else
if item.itemid == 8300 then
if self.item.level > 0 then
self:setItemName(self:getItemName():gsub("%+(%d+)", ""))
for key, value in pairs(self.attributes) do
if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)
end
end
end
else
doRemoveItem(self.item.uid, 1)
end
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")
end
end

acho que agora vai :D

Editado por Kissy
Link para o comentário
Compartilhar em outros sites


--[[
PERFECT UPGRADE SYSTEM
2.0
Criado por Oneshot
É proibido a venda ou a cópia sem os devidos créditos desse script.
]]--
UpgradeHandler = {
levels = {
[1] = {90, false, false},
[2] = {80, false, false},
[3] = {70, false, false},
[4] = {60, true, false},
[5] = {40, true, true}
},
broadcast = 8,
attributes = {
["attack"] = 1,
["defense"] = 1,
["armor"] = 1
},
message = {
console = "Trying to refine %s to level +%s with %s%% success rate.",
success = "You have upgraded %s to level +%s",
fail = "You have failed in upgrade of %s to level +%s",
downgrade = "The upgrade level of %s has downgraded to +%s",
erase = "The upgrade level of %s has been erased.",
maxlevel = "The targeted %s is already on max upgrade level.",
notupgradeable = "This item is not upgradeable.",
broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
invalidtool = "This is not a valid upgrade tool.",
toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
},
tools = {
[8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},
[8300] = {range = {0, 10}, info = {chance = 0, removeable = true}}
},
isEquipment = function(self)
local weaponType = self:getItemWeaponType()
return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
end,
setItemName = function(self, name)
return doItemSetAttribute(self.item.uid, "name", name)
end,
chance = function(self)
local chances = {}
chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
chances.downgrade = (self.item.level * 5)
chances.erase = (self.item.level * 3)
return chances
end
}
function UpgradeHandler:new(item)
local obj, ret = {}
obj.item = {}
obj.item.level = 0
obj.item.uid = item.uid
for key, value in pairs(getItemInfo(item.itemid)) do
obj.item[key] = value
end
ret = setmetatable(obj, {__index = function(self, index)
if _G[index] then
return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
return self.callback(item.uid, ...)
end}))
else
return UpgradeHandler[index]
end
end})
if ret:isEquipment() then
ret:update()
return ret
end
return false
end
function UpgradeHandler:update()
self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end
function UpgradeHandler:refine(uid, item)
if not self.item then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
return "miss"
end
local tool = self.tools[item.itemid]
if(tool == nil) then
doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
return "miss"
end
if(self.item.level > #self.levels) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
return "miss"
end
if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
return "miss"
end
local chance = (self:chance().upgrade + tool.info.chance)
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
if(tool.info.removeable == true) then
doRemoveItem(item.uid, 1)
end
if chance * 100 > math.random(1, 10000) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
if (self.item.level + 1) >= self.broadcast then
doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
end
self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
for key, value in pairs(self.attributes) do
if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
end
end
return "success"
else
if item.itemid == 8300 then
if self.item.level > 0 then
self:setItemName(self:getItemName():gsub("%+(%d+)", ""))
for key, value in pairs(self.attributes) do
if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)
end
end
end
else
doRemoveItem(self.item.uid, 1)
end
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")
end
end

acho que agora vai :D

 

 

Continua o maldito erro dos espaços brother :(((

 

Link para o comentário
Compartilhar em outros sites


--[[

 

PERFECT UPGRADE SYSTEM

2.0

 

Criado por Oneshot

 

É proibido a venda ou a cópia sem os devidos créditos desse script.

 

]]--

 

UpgradeHandler = {

levels = {

[1] = {90, false, false},

[2] = {80, false, false},

[3] = {70, false, false},

[4] = {60, true, false},

[5] = {40, true, true}

},

broadcast = 8,

attributes = {

["attack"] = 1,

["defense"] = 1,

["armor"] = 1

},

message = {

console = "Trying to refine %s to level +%s with %s%% success rate.",

success = "You have upgraded %s to level +%s",

fail = "You have failed in upgrade of %s to level +%s",

downgrade = "The upgrade level of %s has downgraded to +%s",

erase = "The upgrade level of %s has been erased.",

maxlevel = "The targeted %s is already on max upgrade level.",

notupgradeable = "This item is not upgradeable.",

broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",

invalidtool = "This is not a valid upgrade tool.",

toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"

},

tools = {

[8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},

[8300] = {range = {0, 10}, info = {chance = 0, removeable = true}}

},

 

isEquipment = function(self)

local weaponType = self:getItemWeaponType()

return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)

end,

 

setItemName = function(self, name)

return doItemSetAttribute(self.item.uid, "name", name)

end,

 

chance = function(self)

local chances = {}

chances.upgrade = (self.levels[self.item.level + 1][1] or 100)

chances.downgrade = (self.item.level * 5)

chances.erase = (self.item.level * 3)

 

return chances

end

}

 

function UpgradeHandler:new(item)

local obj, ret = {}

obj.item = {}

 

obj.item.level = 0

obj.item.uid = item.uid

for key, value in pairs(getItemInfo(item.itemid)) do

obj.item[key] = value

end

 

ret = setmetatable(obj, {__index = function(self, index)

if _G[index] then

return (setmetatable({callback = _G[index]}, {__call = function(self, ...)

return self.callback(item.uid, ...)

end}))

else

return UpgradeHandler[index]

end

end})

 

if ret:isEquipment() then

ret:update()

return ret

end

return false

end

 

function UpgradeHandler:update()

self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)

end

 

function UpgradeHandler:refine(uid, item)

if not self.item then

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)

return "miss"

end

 

local tool = self.tools[item.itemid]

 

if(tool == nil) then

doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)

return "miss"

end

 

if(self.item.level > #self.levels) then

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))

return "miss"

end

 

if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))

return "miss"

end

 

local chance = (self:chance().upgrade + tool.info.chance)

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))

 

if(tool.info.removeable == true) then

doRemoveItem(item.uid, 1)

end

 

if chance * 100 > math.random(1, 10000) then

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))

if (self.item.level + 1) >= self.broadcast then

doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))

end

 

self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))

for key, value in pairs(self.attributes) do

if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then

doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)

end

end

return "success"

else

if item.itemid == 8300 then

if self.item.level > 0 then

self:setItemName(self:getItemName():gsub("%+(%d+)",""))

for key, value in pairs(self.attributes) do

if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then

doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)

end

end

end

else

doRemoveItem(self.item.uid, 1)

end

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")

end

end

 

Link para o comentário
Compartilhar em outros sites

Cotinua esse maldito problema :@:@

Só que agora ta bugando tudo, chega uma hora que o item não quer mais refinar

18:26 Trying to refine mace to level +4 with 65% success rate.
18:26 You have upgraded mace to level +4

18:27 You see a mace      +4 (Atk:20, Def:15).
It weighs 28.00 oz.
ItemID: [2398].
Position: [X: 393] [Y: 931] [Z: 6].

PBg5lXw.png

lib/upgradesystem.lua
--[[
 
        PERFECT UPGRADE SYSTEM
        2.0
 
        Criado por Oneshot
 
        É proibido a venda ou a cópia sem os devidos créditos desse script.
 
]]--
 
UpgradeHandler = {
    levels = {
        [1] = {95, false, false},
        [2] = {85, false, false},
        [3] = {75, false, false},
        [4] = {65, true, false},
        [6] = {55, false, false},
        [7] = {45, false, false},
        [8] = {35, false, false},
        [9] = {25, false, false},
        [10] = {15, true, true}
    },
    broadcast = 8,
    attributes = {
        ["attack"] = 1,
        ["defense"] = 1,
        ["armor"] = 1
    },
    message = {
        console = "Trying to refine %s to level +%s with %s%% success rate.",
        success = "You have upgraded %s to level +%s",
        fail = "You have failed in upgrade of %s to level +%s",
        downgrade = "The upgrade level of %s has downgraded to +%s",
        erase = "The upgrade level of %s has been erased.",
        maxlevel = "The targeted %s is already on max upgrade level.",
        notupgradeable = "This item is not upgradeable.",
        broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
        invalidtool = "This is not a valid upgrade tool.",
        toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
    },
    tools = {
        [8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},
        [8300] = {range = {0, 10}, info = {chance = 0, removeable = true}}
    },
 
    isEquipment = function(self)
        local weaponType = self:getItemWeaponType()
        return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
    end,
 
    setItemName = function(self, name)
        return doItemSetAttribute(self.item.uid, "name", name)
    end,
 
    chance = function(self)
        local chances = {}
        chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
        chances.downgrade = (self.item.level * 5)
        chances.erase = (self.item.level * 3)
 
        return chances
    end
}
 
function UpgradeHandler:new(item)
    local obj, ret = {}
    obj.item = {}
 
    obj.item.level = 0
    obj.item.uid = item.uid
    for key, value in pairs(getItemInfo(item.itemid)) do
        obj.item[key] = value
    end
 
    ret = setmetatable(obj, {__index = function(self, index)
        if _G[index] then
            return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
            return self.callback(item.uid, ...)
            end}))
        else
            return UpgradeHandler[index]
        end
    end})
 
    if ret:isEquipment() then
        ret:update()
        return ret
    end
    return false
end
 
function UpgradeHandler:update()
    self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end
 
function UpgradeHandler:refine(uid, item)
    if not self.item then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
        return "miss"
    end
 
    local tool = self.tools[item.itemid]
 
    if(tool == nil) then
        doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
        return "miss"
    end
 
    if(self.item.level > #self.levels) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
        return "miss"
    end
 
    if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
        return "miss"
    end
 
    local chance = (self:chance().upgrade + tool.info.chance)
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
 
    if(tool.info.removeable == true) then
        doRemoveItem(item.uid, 1)
    end
 
    if chance * 100 > math.random(1, 10000) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
        end
 
        self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
        for key, value in pairs(self.attributes) do
            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
        end
        return "success"
    else
        if item.itemid == 8300 then
            if self.item.level > 0 then
                self:setItemName(self:getItemName():gsub("%+(%d+)",""))
                for key, value in pairs(self.attributes) do
                    if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                        doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)
                    end
                end
            end
        else
            doRemoveItem(self.item.uid, 1)
        end
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")
    end
end
Link para o comentário
Compartilhar em outros sites


--[[

 

PERFECT UPGRADE SYSTEM

2.0

 

Criado por Oneshot

 

É proibido a venda ou a cópia sem os devidos créditos desse script.

 

]]--

 

UpgradeHandler = {

levels = {

[1] = {90, false, false},

[2] = {80, false, false},

[3] = {70, false, false},

[4] = {60, true, false},

[5] = {40, true, true}

},

broadcast = 8,

attributes = {

["attack"] = 1,

["defense"] = 1,

["armor"] = 1

},

message = {

console = "Trying to refine %s to level +%s with %s%% success rate.",

success = "You have upgraded %s to level +%s",

fail = "You have failed in upgrade of %s to level +%s",

downgrade = "The upgrade level of %s has downgraded to +%s",

erase = "The upgrade level of %s has been erased.",

maxlevel = "The targeted %s is already on max upgrade level.",

notupgradeable = "This item is not upgradeable.",

broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",

invalidtool = "This is not a valid upgrade tool.",

toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"

},

tools = {

[8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},

[8300] = {range = {0, 10}, info = {chance = 0, removeable = true}}

},

 

isEquipment = function(self)

local weaponType = self:getItemWeaponType()

return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)

end,

 

setItemName = function(self, name)

return doItemSetAttribute(self.item.uid, "name", name)

end,

 

chance = function(self)

local chances = {}

chances.upgrade = (self.levels[self.item.level + 1][1] or 100)

chances.downgrade = (self.item.level * 5)

chances.erase = (self.item.level * 3)

 

return chances

end

}

 

function UpgradeHandler:new(item)

local obj, ret = {}

obj.item = {}

 

obj.item.level = 0

obj.item.uid = item.uid

for key, value in pairs(getItemInfo(item.itemid)) do

obj.item[key] = value

end

 

ret = setmetatable(obj, {__index = function(self, index)

if _G[index] then

return (setmetatable({callback = _G[index]}, {__call = function(self, ...)

return self.callback(item.uid, ...)

end}))

else

return UpgradeHandler[index]

end

end})

 

if ret:isEquipment() then

ret:update()

return ret

end

return false

end

 

function UpgradeHandler:update()

self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)

end

 

function UpgradeHandler:refine(uid, item)

if not self.item then

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)

return "miss"

end

 

local tool = self.tools[item.itemid]

 

if(tool == nil) then

doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)

return "miss"

end

 

if(self.item.level > #self.levels) then

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))

return "miss"

end

 

if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))

return "miss"

end

 

local chance = (self:chance().upgrade + tool.info.chance)

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))

 

if(tool.info.removeable == true) then

doRemoveItem(item.uid, 1)

end

 

if chance * 100 > math.random(1, 10000) then

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))

if (self.item.level + 1) >= self.broadcast then

doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))

end

 

self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))

for key, value in pairs(self.attributes) do

if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then

doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)

end

end

return "success"

else

if item.itemid == 8300 then

if self.item.level > 0 then

self:setItemName(self:getItemName():gsub("%+(%d+)", ""))

for key, value in pairs(self.attributes) do

if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then

doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)

end

end

end

else

doRemoveItem(self.item.uid, 1)

end

doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")

end

end

 

Link para o comentário
Compartilhar em outros sites

  • 2 weeks later...

O tópico foi fechado e movido para lixeira por estar inativo a mais de 10 dias. Caso seja preciso reabrir o mesmo, favor entrar em contato com a equipe.

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...