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

Help to use slotPosition

fyalhed

Member
Joined
Nov 18, 2017
Messages
155
Reaction score
20
armor is working but slot not...
what do i doing wrong?

console
Code:
10

[2:1:22.375] [Error - Action Interface] 
[2:1:22.375] data/actions/scripts/upgrade.lua:onUse
[2:1:22.375] Description: 
[2:1:22.376] data/lib/upgradesystem.lua:111: attempt to index a boolean value
[2:1:22.376] stack traceback:
[2:1:22.376]     data/lib/upgradesystem.lua:111: in function 'refine'
[2:1:22.376]     data/actions/scripts/upgrade.lua:11: in function <data/actions/scripts/upgrade.lua:1>

source: https://github.com/Fir3element/3777...5cb1f55a34035e42746b3/src/luascript.cpp#L9923

line 111 is this IF:
Code:
    print(self.item.armor)
    if getItemInfo(self.item.itemid).slotPosition == CONST_SLOT_ARMOR then

full script:
Code:
--PERFECT UPGRADE SYSTEM
UpgradeHandler = {
    nameLv = {
        [1] = "[R]",
        [2] = "[G]",
        [3] = "[B]",
    },
    completeNameLv = {
        [1] = "red",
        [2] = "green",
        [3] = "blue",
    },
    levels = {
          [1] = {80, false, false},
          [2] = {40, false, false},
          [3] = {20, false, false},
    },
    broadcast = 3,
    attributes = {
          ["attack"] = 10,
          ["defense"] = 5,
          ["armor"] = 3
    },
    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 = 20, removeable = true}}
    },
    isEquipment = function(self)
        local weaponType = self:getItemWeaponType()
        return ((weaponType > 0 and weaponType < 8) 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()
   -- this will return the level by the quality or 0 if it has no quality.
    self.item.level = 0
    for r, v in ipairs(self.nameLv) do
        if self:getItemName():find(v) then
            self.item.level = r
        end
    end
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(tool.range[1] and self.item.level < tool.range[1]) or (tool.range[2] and self.item.level >= tool.range[2]) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
        return "miss"
    end
    -- 
    -- não pode encantar set, anti idiota ficar sem arma
    print(self.item.armor)
    if getItemInfo(self.item.itemid).slotPosition == CONST_SLOT_ARMOR then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, "You can not upgrade your equipment! It can broken!")
    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.completeNameLv[self.item.level + 1])))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, self.completeNameLv[self.item.level + 1]))
        end
        -- it says if the item's level is greater then 0 (meaning is level equal to 1 or more) if it is add 1 more
        -- if the current level equals 0 add 1 to it
        --self:setItemName(self.item.level > 0 and (self:getItemName():gsub(self.nameLv[self.item.level], ""))..self.nameLv[self.item.level + 1] or self:getItemName().." "..self.nameLv[1])
        self:setItemName(self.item.level > 0 and self.nameLv[self.item.level + 1]..(self:getItemName():gsub("%["..self.nameLv[self.item.level].."%]", "")) or self.nameLv[1].." "..self:getItemName())
        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
                -- this will remove any number with a + sign in front of it from the string
                --self:setItemName(self:getItemName():gsub((" "..self.nameLv[self.item.level]), ""))
                self:setItemName(self:getItemName():gsub(("%["..self.nameLv[self.item.level].."%] "), ""))
                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
 
Solution
<action itemid="8306" event="script" value="upgrade.lua"/>

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isCreature(itemEx.uid) then
        return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    end

    local obj = UpgradeHandler:new(itemEx)
    if(obj == false) then
        return doPlayerSendCancel(cid, UpgradeHandler.message.notupgradeable)
    end

    local status = obj:refine(cid, item)
    if status == "success" then
        --doSendAnimatedText(toPosition, "Success!", COLOR_GREEN)
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
    elseif status == "fail" then
        --doSendAnimatedText(toPosition, "Fail!", COLOR_RED)...
OP
fyalhed

fyalhed

Member
Joined
Nov 18, 2017
Messages
155
Reaction score
20
upgradesystem.lua (-- cant upgrade an item from set, anti dumb)
Code:
--PERFECT UPGRADE SYSTEM
UpgradeHandler = {
    nameLv = {
        [1] = "[R]",
        [2] = "[G]",
        [3] = "[B]",
    },
    completeNameLv = {
        [1] = "red",
        [2] = "green",
        [3] = "blue",
    },
    levels = {
          [1] = {80, false, false},
          [2] = {40, false, false},
          [3] = {20, false, false},
    },
    broadcast = 3,
    attributes = {
          ["attack"] = 3,
          ["defense"] = 2,
          ["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 = 20, removeable = true}}
    },
    isEquipment = function(self)
        local weaponType = self:getItemWeaponType()
        return ((weaponType > 0 and weaponType < 8) 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()
   -- this will return the level by the quality or 0 if it has no quality.
    self.item.level = 0
    for r, v in ipairs(self.nameLv) do
        if self:getItemName():find(v) then
            self.item.level = r
        end
    end
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(tool.range[1] and self.item.level < tool.range[1]) or (tool.range[2] and self.item.level >= tool.range[2]) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
        return "miss"
    end
    --
    -- cant upgrade an item from set, anti dumb
    -- print_r(self.item)
    local itemslot = getThingPosition(self.item.uid)
    print(itemslot.x, itemslot.y, itemslot.z)
    -- if (itemslot >= CONST_SLOT_FIRST) and (itemslot <= CONST_SLOT_LAST) then
    --     doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, "You can not upgrade your equipment! It can broken!")
    -- 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.completeNameLv[self.item.level + 1])))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, self.completeNameLv[self.item.level + 1]))
        end
        -- it says if the item's level is greater then 0 (meaning is level equal to 1 or more) if it is add 1 more
        -- if the current level equals 0 add 1 to it
        --self:setItemName(self.item.level > 0 and (self:getItemName():gsub(self.nameLv[self.item.level], ""))..self.nameLv[self.item.level + 1] or self:getItemName().." "..self.nameLv[1])
        self:setItemName(self.item.level > 0 and self.nameLv[self.item.level + 1]..(self:getItemName():gsub("%["..self.nameLv[self.item.level].."%]", "")) or self.nameLv[1].." "..self:getItemName())
        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
                -- this will remove any number with a + sign in front of it from the string
                --self:setItemName(self:getItemName():gsub((" "..self.nameLv[self.item.level]), ""))
                self:setItemName(self:getItemName():gsub(("%["..self.nameLv[self.item.level].."%] "), ""))
                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
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,352
Solutions
350
Reaction score
3,463
upgradesystem.lua (-- cant upgrade an item from set, anti dumb)
Code:
--PERFECT UPGRADE SYSTEM
UpgradeHandler = {
    nameLv = {
        [1] = "[R]",
        [2] = "[G]",
        [3] = "[B]",
    },
    completeNameLv = {
        [1] = "red",
        [2] = "green",
        [3] = "blue",
    },
    levels = {
          [1] = {80, false, false},
          [2] = {40, false, false},
          [3] = {20, false, false},
    },
    broadcast = 3,
    attributes = {
          ["attack"] = 3,
          ["defense"] = 2,
          ["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 = 20, removeable = true}}
    },
    isEquipment = function(self)
        local weaponType = self:getItemWeaponType()
        return ((weaponType > 0 and weaponType < 8) 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()
   -- this will return the level by the quality or 0 if it has no quality.
    self.item.level = 0
    for r, v in ipairs(self.nameLv) do
        if self:getItemName():find(v) then
            self.item.level = r
        end
    end
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(tool.range[1] and self.item.level < tool.range[1]) or (tool.range[2] and self.item.level >= tool.range[2]) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
        return "miss"
    end
    --
    -- cant upgrade an item from set, anti dumb
    -- print_r(self.item)
    local itemslot = getThingPosition(self.item.uid)
    print(itemslot.x, itemslot.y, itemslot.z)
    -- if (itemslot >= CONST_SLOT_FIRST) and (itemslot <= CONST_SLOT_LAST) then
    --     doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, "You can not upgrade your equipment! It can broken!")
    -- 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.completeNameLv[self.item.level + 1])))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, self.completeNameLv[self.item.level + 1]))
        end
        -- it says if the item's level is greater then 0 (meaning is level equal to 1 or more) if it is add 1 more
        -- if the current level equals 0 add 1 to it
        --self:setItemName(self.item.level > 0 and (self:getItemName():gsub(self.nameLv[self.item.level], ""))..self.nameLv[self.item.level + 1] or self:getItemName().." "..self.nameLv[1])
        self:setItemName(self.item.level > 0 and self.nameLv[self.item.level + 1]..(self:getItemName():gsub("%["..self.nameLv[self.item.level].."%]", "")) or self.nameLv[1].." "..self:getItemName())
        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
                -- this will remove any number with a + sign in front of it from the string
                --self:setItemName(self:getItemName():gsub((" "..self.nameLv[self.item.level]), ""))
                self:setItemName(self:getItemName():gsub(("%["..self.nameLv[self.item.level].."%] "), ""))
                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
Right.. but what script are you using to call this function? function UpgradeHandler:refine(uid, item)
 
OP
fyalhed

fyalhed

Member
Joined
Nov 18, 2017
Messages
155
Reaction score
20
Right.. but what script are you using to call this function? function UpgradeHandler:refine(uid, item)

<action itemid="8306" event="script" value="upgrade.lua"/>

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isCreature(itemEx.uid) then 
        return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    end

    local obj = UpgradeHandler:new(itemEx)
    if(obj == false) then
        return doPlayerSendCancel(cid, UpgradeHandler.message.notupgradeable)
    end

    local status = obj:refine(cid, item)
    if status == "success" then
        --doSendAnimatedText(toPosition, "Success!", COLOR_GREEN)
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
    elseif status == "fail" then
        --doSendAnimatedText(toPosition, "Fail!", COLOR_RED)
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    end
    return true
end
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,352
Solutions
350
Reaction score
3,463
<action itemid="8306" event="script" value="upgrade.lua"/>

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isCreature(itemEx.uid) then
        return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    end

    local obj = UpgradeHandler:new(itemEx)
    if(obj == false) then
        return doPlayerSendCancel(cid, UpgradeHandler.message.notupgradeable)
    end

    local status = obj:refine(cid, item)
    if status == "success" then
        --doSendAnimatedText(toPosition, "Success!", COLOR_GREEN)
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
    elseif status == "fail" then
        --doSendAnimatedText(toPosition, "Fail!", COLOR_RED)
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    end
    return true
end
Are you sure this line is right?
Lua:
local status = obj:refine(cid, item)
Should it not be itemEx?

Cuz item isn't the object being targeted, I don't think.

But anyway, you should be able to send fromPosition or toPosition directly.
Try printing those values.
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    print("fromPosition: x = " .. fromPosition.x .. ", y = " .. fromPosition.y .. ", z = " .. fromPosition.z .. "")
    print("toPosition: x = " .. toPosition.x .. ", y = " .. toPosition.y .. ", z = " .. toPosition.z .. "")
    if isCreature(itemEx.uid) then 
        return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    end
    
    local obj = UpgradeHandler:new(itemEx)
    if(obj == false) then
        return doPlayerSendCancel(cid, UpgradeHandler.message.notupgradeable)
    end
    
    local status = obj:refine(cid, item)
    if status == "success" then
        --doSendAnimatedText(toPosition, "Success!", COLOR_GREEN)
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
    elseif status == "fail" then
        --doSendAnimatedText(toPosition, "Fail!", COLOR_RED)
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    end
    return true
end
 
Solution
OP
fyalhed

fyalhed

Member
Joined
Nov 18, 2017
Messages
155
Reaction score
20
Are you sure this line is right?
Lua:
local status = obj:refine(cid, item)
Should it not be itemEx?

Cuz item isn't the object being targeted, I don't think.

But anyway, you should be able to send fromPosition or toPosition directly.
Try printing those values.
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    print("fromPosition: x = " .. fromPosition.x .. ", y = " .. fromPosition.y .. ", z = " .. fromPosition.z .. "")
    print("toPosition: x = " .. toPosition.x .. ", y = " .. toPosition.y .. ", z = " .. toPosition.z .. "")
    if isCreature(itemEx.uid) then
        return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    end
   
    local obj = UpgradeHandler:new(itemEx)
    if(obj == false) then
        return doPlayerSendCancel(cid, UpgradeHandler.message.notupgradeable)
    end
   
    local status = obj:refine(cid, item)
    if status == "success" then
        --doSendAnimatedText(toPosition, "Success!", COLOR_GREEN)
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
    elseif status == "fail" then
        --doSendAnimatedText(toPosition, "Fail!", COLOR_RED)
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    end
    return true
end

I couldn't done without u, thanks!
 
OP
fyalhed

fyalhed

Member
Joined
Nov 18, 2017
Messages
155
Reaction score
20
Nice!

I kinda want to see what the solution ending up being. xD
Just made in your base:

Code:
    local itemslot = toPosition.y
    if (itemslot >= CONST_SLOT_FIRST) and (itemslot <= CONST_SLOT_LAST) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, "You can not upgrade your equipment! It can broken!")
        return true
    end
 
Top