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

Check top item

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
I have 2 items on same sqm,

how to check only one of them?

Lua:
function onStepIn(creature, item, position, fromPosition)
    local monster = creature:getMonster()  
    if not monster or monster:getName():lower() ~= 'the sinister hermit' then
        return true
    end
    item:remove() -- no working
end

tfs 1.2
 
Solution
Lua:
local function removeTopItem(position)
    local tile = Tile(position)
    if not tile then
        return false
    end

    local items = tile:getItems()
    if not items or #items < 1 then
        return false
    end

    if not items[#items]:remove() then
        return false
    end
    return true
end

I'm not sure if is items[#items]:remove() or items[1]:remove(). Try both.
use stackpos.

253 = top creature.
0 = ground
1-2-3-4+ = items on top of ground.
 
XML:

XML:
<movevent event="StepIn" itemid="1001" script="theSinisterHermit.lua" />


Lua:

Lua:
function onStepIn(creature, item, position, fromPosition)
  local monster = creature:getMonster()
  if not monster or monster:getType():getName():lower() ~= 'the sinister hermit' then
    return true
  end
  item:remove()
  return true
end


If you use as I showed, item will exists.
Use itemid instead position.
 
Your both trying to remove the ground.
You need to scan the position for items using a function or by looping through the stackpos until you find the item your looking for, and then remove it.
 
Lua:
local function removeTopItem(position)
    local tile = Tile(position)
    if not tile then
        return false
    end

    local items = tile:getItems()
    if not items or #items < 1 then
        return false
    end

    if not items[#items]:remove() then
        return false
    end
    return true
end

I'm not sure if is items[#items]:remove() or items[1]:remove(). Try both.
 
Solution
Back
Top