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

Lua is it possible to compare the item NAME?

Lurk

Active Member
Joined
Dec 4, 2017
Messages
336
Reaction score
49
hello, I have a refine system on my server and I want to make it so when a player has a specfic wepon at level 16 he can change that weapon for another one, thing is, these upgrade weapons' level are defined by its name, so a Giant Sword that was refined 1 time would be called a Giant Sword +1
I was looking at a lua functions list and didn't find a method to check item names, the closest I found was getItemNameById but that's not good enough I believe
Honestly just knowing a method to check the item name will be enough (is possible at all), any idea?

edit: actually, just found a
Code:
getItemName(uid)
but how can I use this?

edit:
got this error
[8:52:48.904] [Error - TalkAction Interface] [8:52:48.904] data/talkactions/scripts/trocaritems.lua:onSay [8:52:48.904] Description: [8:52:48.904] data/lib/050-function.lua:253: attempt to index a boolean value [8:52:48.905] stack traceback: [8:52:48.906] data/lib/050-function.lua:253: in function 'getItemName' [8:52:48.906] data/talkactions/scripts/trocaritems.lua:9: in function <data/talkactions/scripts/trocaritems.lua:1>

when testing like this
LUA:
if param == "wand" then
if getItemName(uid) == "Star wand +16" then
 doPlayerSendTextMessage(cid, 22, "Você fez uma troca de items!")
 --doPlayerRemoveItem(cid, 12609)
 doPlayerRemoveItem(cid, table["wand"].id, 1)
 doPlayerAddItem(cid, table["wand"].toid, 1)
 else
 doPlayerSendCancel(cid, "Você não tem o item necessário!")
end
return true
end
 
Last edited:
hello, I have a refine system on my server and I want to make it so when a player has a specfic wepon at level 16 he can change that weapon for another one, thing is, these upgrade weapons' level are defined by its name, so a Giant Sword that was refined 1 time would be called a Giant Sword +1
I was looking at a lua functions list and didn't find a method to check item names, the closest I found was getItemNameById but that's not good enough I believe
Honestly just knowing a method to check the item name will be enough (is possible at all), any idea?

edit: actually, just found a
Code:
getItemName(uid)
but how can I use this?

edit:
got this error
[8:52:48.904] [Error - TalkAction Interface] [8:52:48.904] data/talkactions/scripts/trocaritems.lua:onSay [8:52:48.904] Description: [8:52:48.904] data/lib/050-function.lua:253: attempt to index a boolean value [8:52:48.905] stack traceback: [8:52:48.906] data/lib/050-function.lua:253: in function 'getItemName' [8:52:48.906] data/talkactions/scripts/trocaritems.lua:9: in function <data/talkactions/scripts/trocaritems.lua:1>

when testing like this
LUA:
if param == "wand" then
if getItemName(uid) == "Star wand +16" then
doPlayerSendTextMessage(cid, 22, "Você fez uma troca de items!")
--doPlayerRemoveItem(cid, 12609)
doPlayerRemoveItem(cid, table["wand"].id, 1)
doPlayerAddItem(cid, table["wand"].toid, 1)
else
doPlayerSendCancel(cid, "Você não tem o item necessário!")
end
return true
end

uid return false, so uid u tryin pass is wrong, + u sure that name return name, not name + desc? in upgrade system.
 
here's the full upgrade script
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] = {100, false, false},

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

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

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

        [5] = {50, false, false},

        [6] = {40, false, false},

        [7] = {30, false, false},

        [8] = {20, false, false},

        [9] = {15, false, false},

        [10] = {10, false, false},

        [11] = {5, false, false},

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

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

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

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

        [16] = {1, false, false}


    },

    broadcast = 8,

    attributes = {

        ["attack"] = 20,

        ["defense"] = 14,

        ["armor"] = 7

    },

    message = {

        console = "Tentando refinar seu %s para o level +%s com %s%% chance de sucesso.",

        success = "Voce refinou o seu %s para o level +%s",

        fail = "Voce falhou em refinar o seu %s para o level +%s",

        downgrade = "O level do item %s abaixou para +%s",

        erase = "Os leveis de upgrade do item %s foram apagados.",

        maxlevel = "O item %s já chegou no nivel maximo de upgrades.",

        notupgradeable = "Este item nao pode ser refinado.",

        broadcast = "O jogador %s acabou de refinar a sua %s para o level +%s.\nParabens!!",

        invalidtool = "Este nao e um item de upgrade valido.",

        toolrange = "Este item de upgrade so pode ser usado em itens com level entre +%s e +%s"

    },

    tools = {

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

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

        [8299] = {range = {0, 16}, info = {chance = 100, 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(self.levels[self.item.level][3] == true and (self:chance().erase * 100) > math.random(1, 10000)) then

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

            self:setItemName(self.item.name)

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

                if self.item[key] > 0 then

                    doItemSetAttribute(self.item.uid, key, self.item[key])

                end

            end

        elseif(self.levels[self.item.level][2] == true and (self:chance().downgrade * 100) > math.random(1, 10000)) then

            doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.downgrade:format(self.item.name, (self.item.level - 1)))

            self:setItemName((self.item.level == 1 and self.item.name or self:getItemName():gsub("%+(%d+)", "+".. (self.item.level - 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[key] + value * (self.item.level - 1)))

                end

            end

        else

            doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.fail:format(self.item.name, (self.item.level + 1)))

        end

        return "fail"

    end

end
I'm pretty sure it changes just the item's name, and I dunno about this function..
I'm now trying something like
LUA:
local nome1 = getItemName(uid, 12609)
local nome2 = "Star wand +16"

if param == "wand" then
if getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == 12609 and nome1 == nome2 then
doPlayerSendTextMessage(cid, 22, "Você fez uma troca de items!")
--doPlayerRemoveItem(cid, 12609)
doPlayerRemoveItem(cid, table["wand"].id, 1)
doPlayerAddItem(cid, table["wand"].toid, 1)
else
doPlayerSendCancel(cid, "Você não tem o item necessário!")
end
return true
end
but it aint working either

found this on 050-functions
LUA:
function getItemName(uid)
    return getItemDescriptions(uid).name
end

edit again:
just managed to make it work !
LUA:
local slotitem = getPlayerSlotItem(cid, CONST_SLOT_LEFT) -- edite o slot
local nomeitem = getItemNameById(slotitem.itemid) -- tipo isso
local slotitem2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT) -- edite o slot
local nomeitem2 = getItemNameById(slotitem.itemid) -- tipo isso
local nome2 = "Star wand +16"

if param == "wand" then
if nomeitem == nome2 or slotitem2 == nome2 then
doPlayerSendTextMessage(cid, 22, "Você fez uma troca de items!")
--doPlayerRemoveItem(cid, 12609)
doPlayerRemoveItem(cid, table["wand"].id, 1)
doPlayerAddItem(cid, table["wand"].toid, 1)
else
doPlayerSendCancel(cid, "Você não tem o item necessário!")
end
return true
end
but still ain't changing the item since it's returning the default item name, not the new item name which would be star wand +16..
 
Last edited:
Back
Top