• 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 1.2 - throw "open trap" from inventory

emil92b

Intermediate OT User
Joined
Aug 21, 2013
Messages
335
Solutions
13
Reaction score
135
Location
Sweden
im trying to make an open trap, close itself when thrown out of inventory

i have tried to do like this with onAddItem movement script, however it will then interfere with my onUse action script and close right after i open it, which i do not want.

Lua:
function onAddItem(item, tileitem, position)
    item:transform(item.itemid - 1) -- a closed trap
    return true
end

are there any other way to solve this, or what am i missing?
 
check if item position on the onAddItem is ground
Ugh. I tried like 50 different ways and couldn't figure out a way to do it like this.
Guess I'm dumb as a brick. xD

im trying to make an open trap, close itself when thrown out of inventory

i have tried to do like this with onAddItem movement script, however it will then interfere with my onUse action script and close right after i open it, which i do not want.

Lua:
function onAddItem(item, tileitem, position)
    item:transform(item.itemid - 1) -- a closed trap
    return true
end

are there any other way to solve this, or what am i missing?
Idk if this is the best way, but it works.

data/events/scripts/player.lua

replace
Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if hasEventCallback(EVENT_CALLBACK_ONMOVEITEM) then
        return EventCallback(EVENT_CALLBACK_ONMOVEITEM, self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    else
        return true
    end
end
with
Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if hasEventCallback(EVENT_CALLBACK_ONMOVEITEM) then
        -- moveable trap item (open)
        if item.itemid == 2579 then
            item:transform(item.itemid - 1) -- closed
            toPosition:sendMagicEffect(CONST_ME_POFF)
        end
        return EventCallback(EVENT_CALLBACK_ONMOVEITEM, self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    else
        return true
    end
end
 
check if item position on the onAddItem is ground
Lua:
function onAddItem(item, tileitem, position)
    local tile = Tile(item:getPosition())
    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground then
        return false
    end

    item:getPosition():sendMagicEffect(CONST_ME_POFF)
    item:transform(item.itemid - 1) -- a closed trap
    return true
end

like this?, i cant get it to work

@Xikini the "nostalrius" 1.2 distro which i am using don't have EventCallBack thingy implemented apparently : /, appreciate the effort tho
 
Last edited:
Lua:
function onAddItem(item, tileitem, position)
    local tile = Tile(item:getPosition())
    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground then
        return false
    end

    item:getPosition():sendMagicEffect(CONST_ME_POFF)
    item:transform(item.itemid - 1) -- a closed trap
    return true
end

like this?, i cant get it to work

@Xikini the "nostalrius" 1.2 distro which i am using don't have EventCallBack thingy implemented apparently : /, appreciate the effort tho
do you have a link to the distro?
 
Idk. lol
I've been wracking my brain for like an hour trying to think of a way to do this.

I just don't see how it's possible without having information about where the item came from.

A lot of functions have this issue, where they trigger After something has happened, but never have a function Before/while something is happening.

I think this is the latter.

Item tells us the item that was moved.
tileItem.. I swear is useless. I can't get it to print anything but 0 or table. By it's name, I assumed it was the tile we were putting the item on.. but I can't figure out a way to use it.
and finally..
position tells us the position that the item was added to, but not where it came from.

-- and your distro doesn't appear to have any of the onMoveItem or onThrow features in creaturescripts..

So I'm at a loss.
I don't personally think it's possible with what you have.

There's no way to determine the difference between creating/transforming/moving the item onto a tile.
As far as the script is concerned, they are all the exact same thing.
 
Back
Top