Fermantor
Active Member
tl;dr wanna create item where trigger item is located (not player:addItem). But laying on the ground floor with browse field open doesn't detect as parent:isTile(). How to fix?
Hello, I wanna add a feature that is more like RL tibia where when you create a new item, it isn't always is added to the player, but created where the script is triggered.
For example, you loot a shiny stone and use the pick on the stone in the corpse. Instead of adding the new item to the player, I want to add it to the monster, if there are slots free.
My first try of this function looks like this:
It works perfectly fine and detects if the item is laying on the ground or is inside a corpse/container, until I browse field the item on the ground. Then it won't detect the tile again, and thinks it is inside a container with 30 slots. How can I debug this?
Hello, I wanna add a feature that is more like RL tibia where when you create a new item, it isn't always is added to the player, but created where the script is triggered.
For example, you loot a shiny stone and use the pick on the stone in the corpse. Instead of adding the new item to the player, I want to add it to the monster, if there are slots free.
My first try of this function looks like this:
Lua:
function createItem(item, newitem, amount)
local parent = item:getParent()
local result
item:remove(1)
if parent:isTile() then -- check if item is laying on the ground
result = Game.createItem(newitem, amount and amount or 1, parent:getPosition()) --create new item on the ground
elseif parent:getEmptySlots() ~= 0 then -- item is in a container => check if there are slots free
result = parent:addItem(newitem, amount and amount or 1) -- add item to container
elseif parent:getTopParent():isPlayer() then -- no slots are free => check if container is from a player
result = parent:getTopParent():addItem(newitem, amount and amount or 1) -- add Player item
else -- container is full and owner not a player
result = Game.createItem(newitem, amount and amount or 1, parent:getPosition()) -- create item on the ground
end
return result
end
It works perfectly fine and detects if the item is laying on the ground or is inside a corpse/container, until I browse field the item on the ground. Then it won't detect the tile again, and thinks it is inside a container with 30 slots. How can I debug this?