forgottenserver
forgottenserver copied to clipboard
ItemType(item):getSlotPosition() returns the same value (48) for all slot positions
Before creating an issue, please ensure:
- [x] This is a bug in the software that resides in this repository, and not a support matter (use https://otland.net/forums/support.16/ for support)
- [x] This issue is reproducible without changes to the code in this repository
Steps to reproduce (include any configuration/script required to reproduce)
- Equip at least your character equipment slots (head and feet).
- Check the script below
local slotItem = player:getSlotItem(CONST_SLOT_FEET)
if slotItem then
local slotPos = ItemType(slotItem):getSlotPosition()
print("Slot position (feet): ", slotPos) -- prints the value 48
slotItem = player:getSlotItem(CONST_SLOT_HEAD)
if slotItem then
slotPos = ItemType(slotItem):getSlotPosition()
print("Slot position (head): ", slotPos) -- also prints 48
end
end
Expected behaviour
It should print the appropriate value for each specific equipment slot.
Actual behaviour
It prints the same value (48) for all equipment slots.
Environment
the forgotten server 1.3
It's because you're constructing an ItemType object with a userdata value instead of item id or name.
You should receive the following results when it's constructed properly:
Slot position (feet): 176
Slot position (head): 49
@ninjalulz anyway it should work when making an itemtype with a userdata.
I could sense I was making something wrong and you just showed me that hehe, thanks for explaining.
I thought I had searched in the sources already so I thought I could use a Item to construct an ItemType but then I checked the sources now that you explained me and found: // ItemType(id or name)
.
Should I close this?
@ninjalulz Is it a valid (possible) idea what @andersonfaaria mentioned?
Mistakes of mine like these makes this looks more like a support matter 💃 lol, I should be closing this?
@ninjalulz I have a question, the item class inherit the methods for itemType? if so, @raymondtfr could use slotItem:getType():getSlotPosition(); If not, he could use ItemType(slotItem:getId());
But again, the TFS should accept userdata for ItemType and MonsterType. It's a simple if thing and makes it more consistent.
In my opinion, you shouldn't be able to construct an ItemType with an Item userdata. The method item:getType() makes more sense for OO.
But it should be returning nil if the ItemType doesn't exist.
The question is: Do we have a Way of doing item:getType()? The function getType is from itemType, not from item. Item has a way of inheriting ItemType's methods?
No, itemType:getType() returns a number: https://github.com/otland/forgottenserver/blob/master/src/items.h#L45
item:getType() returns the ItemType of the item: https://github.com/otland/forgottenserver/blob/master/data/lib/core/item.lua#L1
I cant check the code right now. I'm on the cell phone. I was only assuming they were the same because of what I saw in the luascript.cpp
I really don't understand the question, but this is a simple way to get all the slot id's along with the item id's of everything you have equipped.
--[[
1 - helmet
2 - necklace slot
3 - backpack, bag
4 - armor
5 - right hand
6 - left hand
7 - legs
8 - boots
9 - ring slot
10 - ammo slot
]]
function Player:getSlottedItems()
local equipment, item, itemid = {}, 0, 0
for slot = 1, 10 do
item = self:getSlotItem(slot)
itemid = pushThing(item).itemid
if itemid and itemid ~= 0 then
equipment[slot] = itemid
end
end
return equipment
end