• 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
156
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)
        doSendMagicEffect(toPosition, CONST_ME_POFF)...
I tried
Code:
    print(self.item.armor)
    local itemslot = getItemInfo(self.item.itemid).slotPosition
    print(itemslot)
    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

in a plate armor, it is printing the armor right, but not the slot...
why?
 
check your getItemInfo(self.item.itemid) function to see if it's even trying to return slot position?

What are u mean?
To print it?

Code:
    print(self.item.armor)
    print(getItemInfo(self.item.itemid))

it don't print anything
only 10 from plate armor armor
 
Yeah, I'm saying are those things defined in lua.

Is CONST_SLOT_ARMOR defined?

where is getItemInfo() defined and what is it supposed to return? does it work for anything?

Maybe try itanother way like...

If ItemType.usesSlot(self, CONST_SLOT_ARMOR) then ...

What version of TFS is this?
 
Yeah, I'm saying are those things defined in lua.

Is CONST_SLOT_ARMOR defined?

where is getItemInfo() defined and what is it supposed to return? does it work for anything?

Maybe try itanother way like...

If ItemType.usesSlot(self, CONST_SLOT_ARMOR) then ...

What version of TFS is this?

yes
CONST_SLOT_ARMOR

but that print prints nothing

i don't understand
 
Idk what to do now
Test the function in an extremely simplified environment, instead of inside your code, as it is now.

From memory, I believe the slot value it gives is really weird. Like boots are 176, or something like that.

Just setup a full equipment set in actions.xml, and use each one to find out what the value for each slot is.

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    print(getItemInfo(item.itemid).slotPosition)
    return true
end

Once you know the value's you need to check for, then you can easily modify your original code with the new parameters.
 
Test the function in an extremely simplified environment, instead of inside your code, as it is now.

From memory, I believe the slot value it gives is really weird. Like boots are 176, or something like that.

Just setup a full equipment set in actions.xml, and use each one to find out what the value for each slot is.

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    print(getItemInfo(item.itemid).slotPosition)
    return true
end

Once you know the value's you need to check for, then you can easily modify your original code with the new parameters.

There is no slotPosition i think so
I tried print_r on this script:
print_r(self.item)

prints:
Code:
  [vocationString] => 
  [showAttributes] => false
  [minRequiredLevel] => 0
  [wieldInfo] => 0
  [writeOnceItemId] => 0
  [movable] => true
  [level] => 0
  [hangable] => false
  [runeMagicLevel] => 0
  [allowPickupable] => false
  [defense] => 0
  [blockProjectile] => false
  [decayTime] => 0
  [blockPickupable] => false
  [usable] => false
  [fluidSource] => 0
  [combatType] => 0
  [rotateTo] => 0
  [slotPosition] => 568
  [extraAttack] => 0
  [decayTo] => -1
  [blockSolid] => false
  [vertical] => false
  [minRequiredMagicLevel] => 0
  [worth] => 0
  [showCharges] => false
  [shootRange] => 1
  [levelDoor] => 0
  [maxTextLength] => 0
  [maxItems] => 8
  [hasHeight] => false
  [uid] => 70001
  [replacable] => true
  [bedPartnerDirection] => 0
  [showDuration] => false
  [description] => 
  [hitChance] => -1
  [transformDeEquipTo] => 0
  [runeLevel] => 0
  [breakChance] => -1
  [weight] => 24
  [speed] => 0
  [transformUseTo] => table: 0x7fb908a650c0 {
                        [female] => 0
                        [male] => 0
                      }
  [pickupable] => true
  [abilities] => table: 0x7fb908a650c0 {
                   [preventDrop] => false
                   [manaShield] => false
                   [healthTicks] => 0
                   [elementType] => 0
                   [elementDamage] => 0
                   [healthGain] => 0
                   [conditionSuppressions] => 0
                   [preventLoss] => false
                   [regeneration] => false
                   [speed] => 0
                   [manaGain] => 0
                   [invisible] => false
                   [manaTicks] => 0
                 }
  [runeSpellName] => 
  [distRead] => false
  [stackable] => false
  [maxHitChance] => -1
  [attack] => 0
  [forceSerialize] => false
  [horizontal] => false
  [shootType] => 0
  [readable] => false
  [group] => 0
  [writable] => false
  [rotable] => false
  [floorChange] => table: 0x7fb908a650c0 {
                     [1] => false
                     [2] => false
                     [3] => false
                     [4] => false
                     [5] => false
                     [6] => false
                     [7] => false
                     [8] => false
                     [9] => false
                   }
  [stopTime] => false
  [transformEquipTo] => 0
  [showCount] => true
  [blockPathing] => false
  [attackSpeed] => 0
  [ammoType] => 0
  [alwaysOnTop] => false
  [lightColor] => 0
  [lightLevel] => 0
  [type] => 0
  [ammoAction] => 0
  [clientId] => 3561
  [wieldPosition] => 4
  [transformToFree] => 0
  [corpseType] => 0
  [extraDefense] => 0
  [alwaysOnTopOrder] => 0
  [magicEffect] => 255
  [armor] => 1
  [charges] => 0
  [plural] => jackets
  [name] => jacket
  [weaponType] => 0
  [article] => a
 
There is no slotPosition i think so
I tried print_r on this script:
print_r(self.item)

prints:
Code:
  [vocationString] =>
  [showAttributes] => false
  [minRequiredLevel] => 0
  [wieldInfo] => 0
  [writeOnceItemId] => 0
  [movable] => true
  [level] => 0
  [hangable] => false
  [runeMagicLevel] => 0
  [allowPickupable] => false
  [defense] => 0
  [blockProjectile] => false
  [decayTime] => 0
  [blockPickupable] => false
  [usable] => false
  [fluidSource] => 0
  [combatType] => 0
  [rotateTo] => 0
  [slotPosition] => 568
  [extraAttack] => 0
  [decayTo] => -1
  [blockSolid] => false
  [vertical] => false
  [minRequiredMagicLevel] => 0
  [worth] => 0
  [showCharges] => false
  [shootRange] => 1
  [levelDoor] => 0
  [maxTextLength] => 0
  [maxItems] => 8
  [hasHeight] => false
  [uid] => 70001
  [replacable] => true
  [bedPartnerDirection] => 0
  [showDuration] => false
  [description] =>
  [hitChance] => -1
  [transformDeEquipTo] => 0
  [runeLevel] => 0
  [breakChance] => -1
  [weight] => 24
  [speed] => 0
  [transformUseTo] => table: 0x7fb908a650c0 {
                        [female] => 0
                        [male] => 0
                      }
  [pickupable] => true
  [abilities] => table: 0x7fb908a650c0 {
                   [preventDrop] => false
                   [manaShield] => false
                   [healthTicks] => 0
                   [elementType] => 0
                   [elementDamage] => 0
                   [healthGain] => 0
                   [conditionSuppressions] => 0
                   [preventLoss] => false
                   [regeneration] => false
                   [speed] => 0
                   [manaGain] => 0
                   [invisible] => false
                   [manaTicks] => 0
                 }
  [runeSpellName] =>
  [distRead] => false
  [stackable] => false
  [maxHitChance] => -1
  [attack] => 0
  [forceSerialize] => false
  [horizontal] => false
  [shootType] => 0
  [readable] => false
  [group] => 0
  [writable] => false
  [rotable] => false
  [floorChange] => table: 0x7fb908a650c0 {
                     [1] => false
                     [2] => false
                     [3] => false
                     [4] => false
                     [5] => false
                     [6] => false
                     [7] => false
                     [8] => false
                     [9] => false
                   }
  [stopTime] => false
  [transformEquipTo] => 0
  [showCount] => true
  [blockPathing] => false
  [attackSpeed] => 0
  [ammoType] => 0
  [alwaysOnTop] => false
  [lightColor] => 0
  [lightLevel] => 0
  [type] => 0
  [ammoAction] => 0
  [clientId] => 3561
  [wieldPosition] => 4
  [transformToFree] => 0
  [corpseType] => 0
  [extraDefense] => 0
  [alwaysOnTopOrder] => 0
  [magicEffect] => 255
  [armor] => 1
  [charges] => 0
  [plural] => jackets
  [name] => jacket
  [weaponType] => 0
  [article] => a
Lua:
  [slotPosition] => 568
 
Its printing 568 on plate armor equipeds and 568 on plate armor in backpack
yeah, so that itemid can be equipped in the armor slot. armor slot is 568.

getItemInfo get's the default info of an itemid, not the current info of a item.
 
Do u know a way to detect if item is equiped?
You can check the item's position.
If it's in the inventory, x should be a really high number.
If it's equipped, the y value should be 1 thru 10. 11+ means it's inside a container somewhere
 
You can check the item's position.
If it's in the inventory, x should be a really high number.
If it's equipped, the y value should be 1 thru 10. 11+ means it's inside a container somewhere

How?

I tried:
Code:
print(getThingFromPos(self.item))

return
Code:
[23:16:49.648] [Error - Action Interface] 
[23:16:49.648] data/actions/scripts/upgrade.lua:onUse
[23:16:49.648] Description: 
[23:16:49.648] (luaGetThingFromPos) Tile not found


[23:16:59.364] [Error - Action Interface] 
[23:16:59.364] data/actions/scripts/upgrade.lua:onUse
[23:16:59.364] Description: 
[23:16:59.364] (luaGetThingFromPos) Tile not found


[23:17:06.345] [Error - Action Interface] 
[23:17:06.345] data/actions/scripts/upgrade.lua:onUse
[23:17:06.345] Description: 
[23:17:06.345] (luaGetThingFromPos) Tile not found
 
How?

I tried:
Code:
print(getThingFromPos(self.item))

return
Code:
[23:16:49.648] [Error - Action Interface]
[23:16:49.648] data/actions/scripts/upgrade.lua:onUse
[23:16:49.648] Description:
[23:16:49.648] (luaGetThingFromPos) Tile not found


[23:16:59.364] [Error - Action Interface]
[23:16:59.364] data/actions/scripts/upgrade.lua:onUse
[23:16:59.364] Description:
[23:16:59.364] (luaGetThingFromPos) Tile not found


[23:17:06.345] [Error - Action Interface]
[23:17:06.345] data/actions/scripts/upgrade.lua:onUse
[23:17:06.345] Description:
[23:17:06.345] (luaGetThingFromPos) Tile not found
Lua:
getThingPosition(uid)
 
Back
Top