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

Lua doRemoveItem() with stackable items

ohman

Member
Joined
Oct 24, 2008
Messages
287
Reaction score
5
Location
Sweden
Hello!

I'm experiencing an issue where the doRemoveItem() function doesn't work properly during an onMoveItem event in certain scenarios. This problem occurs when stackable items are thrown, leading to various unexpected issues.

I've attempted to replace doRemoveItem(item.uid) with the following alternatives, but none of them seem to function correctly:

  • doRemoveItem(item.uid) -- This deletes all items in the stack.
  • doRemoveItem(item.uid, count) -- When I throw 2 items, 4 items disappear from the bag, and 2 end up on the ground.
  • doRemoveItem(item.uid, item.type) -- This also deletes all items in the stack.
Any suggestions for resolving these issues would be greatly appreciated!

destoyItems.lua (inside data/scripts)
Lua:
local ec = EventCallback

ec.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if fromPosition.x == CONTAINER_POSITION and toPosition.x ~= CONTAINER_POSITION then
            doRemoveItem(item.uid)
            return RETURNVALUE_NOERROR
    end
    return RETURNVALUE_NOERROR
end

ec:register()
 
Only a quick thought but ... most likely because you are returning RETURNVALUE_NOERROR, so the interalMoveItem will continue and the item may have been removed but still exists which is why you are getting weird behaviour.

I think the best option here is to use onItemMoved, and remove the item there instead.
 
Back
Top