• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Put item on table to open secret stairs

Gofrion

Rookgaard RPG
Premium User
Joined
May 1, 2017
Messages
223
Solutions
1
Reaction score
99
Location
/home/tfs/
Hello everyone, could someone explain to me how to create a script that is responsible for removing a given id after throwing a book on the table. (throw special book on table to open secret stairs/remove any wall or push specific item to 1 sqm right?

Big ++ for any help
 
Solution
F
Something like this.... (untested)
LUA:
local bookId = 1950 -- book id
local bookPos = Position(1000, 1000, 7) -- book position

-- the item, such as a bookcase or whatever you want to move
local itemConfig = {
    id = 1036, -- id
    fromPos = Position(1000, 1000, 7), -- from position
    toPos = Position(1000, 1000, 7) -- to position
}

local event = EventCallback
function event.onItemMoved(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)

    if item:getId() ~= bookId or (toPosition ~= bookPos and fromPosition ~= bookPos) then
        return true
    end
 
    if toPosition ~= bookPos then
        itemConfig.fromPos, itemConfig.toPos = itemConfig.toPos, itemConfig.fromPos
    end
 
    local tile =...
Something like this.... (untested)
LUA:
local bookId = 1950 -- book id
local bookPos = Position(1000, 1000, 7) -- book position

-- the item, such as a bookcase or whatever you want to move
local itemConfig = {
    id = 1036, -- id
    fromPos = Position(1000, 1000, 7), -- from position
    toPos = Position(1000, 1000, 7) -- to position
}

local event = EventCallback
function event.onItemMoved(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)

    if item:getId() ~= bookId or (toPosition ~= bookPos and fromPosition ~= bookPos) then
        return true
    end
 
    if toPosition ~= bookPos then
        itemConfig.fromPos, itemConfig.toPos = itemConfig.toPos, itemConfig.fromPos
    end
 
    local tile = Tile(itemConfig.fromPos)
    if not tile then
        return true
    end
 
    local moveItem = tile:getItemById(itemConfig.id)
    if not moveItem then
        return true
    end
 
    local targetTile = Tile(itemConfig.toPos)
    if targetTile:hasFlag(TILESTATE_BLOCKSOLID) then
        return true
    end
 
    if moveItem:moveTo(itemConfig.toPos) ~= RETURNVALUE_NOERROR then
        moveItem:remove()
        Game.createItem(itemConfig.id, 1, itemConfig.toPos)
    end
 
end

event:register()
 
Solution
Something like this.... (untested)
LUA:
local bookId = 1950 -- book id
local bookPos = Position(1000, 1000, 7) -- book position

-- the item, such as a bookcase or whatever you want to move
local itemConfig = {
    id = 1036, -- id
    fromPos = Position(1000, 1000, 7), -- from position
    toPos = Position(1000, 1000, 7) -- to position
}

local event = EventCallback
function event.onItemMoved(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)

    if item:getId() ~= bookId or (toPosition ~= bookPos and fromPosition ~= bookPos) then
        return true
    end
 
    if toPosition ~= bookPos then
        itemConfig.fromPos, itemConfig.toPos = itemConfig.toPos, itemConfig.fromPos
    end
 
    local tile = Tile(itemConfig.fromPos)
    if not tile then
        return true
    end
 
    local moveItem = tile:getItemById(itemConfig.id)
    if not moveItem then
        return true
    end
 
    local targetTile = Tile(itemConfig.toPos)
    if targetTile:hasFlag(TILESTATE_BLOCKSOLID) then
        return true
    end
 
    if moveItem:moveTo(itemConfig.toPos) ~= RETURNVALUE_NOERROR then
        moveItem:remove()
        Game.createItem(itemConfig.id, 1, itemConfig.toPos)
    end
 
end

event:register()
You are a GOD. Everything works, thanks boss for your time!
 
Back
Top