• 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 TFS1.5 Thais Lighthouse Quest Support

dyl12189

New Member
Joined
Nov 4, 2023
Messages
13
Reaction score
1
I am trying to have the staircase appear when someone is standing on the stone tile switch.
1700284091359.png

Currently my code is:

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    --Step on tile to open stairwell
    if item.actionid == 1000 then
        local stairtile = Tile(Position({x = 32225, y = 32282, z = 9}))
            if item.itemid == 425 then
                stairtile:getItemById(424):transform(3219)
                --item:transform(1946)
            else
                stairtile:getItemById(3219):transform(424)
                --item:transform(1945)
            end
    end
    return true
end
Post automatically merged:

I figured out what I was doing wrong. Was in the actions folder instead of movements.
 
Last edited:
Solution
I realized you figured it out after I already wrote this, so I'll post it anyway, maybe someone can learn something from it or you can improve your script somehow.

We want to use a MoveEvent instead of an Action for this, since we want something to happen when we step on something, instead of when we click something, which is the case for an Action.

data/scripts
Lua:
local groundId = 424
local stairId = 3219
local stairPosition = Position(32225, 32282, 9) -- Position where the stairs will spawn
local tilePosition = Position(1000, 1000, 7) -- Position of the tile we want to stand on

---------------------------------------------------------------------------

local stepin = MoveEvent()

function stepin.onStepIn(player, item...
I realized you figured it out after I already wrote this, so I'll post it anyway, maybe someone can learn something from it or you can improve your script somehow.

We want to use a MoveEvent instead of an Action for this, since we want something to happen when we step on something, instead of when we click something, which is the case for an Action.

data/scripts
Lua:
local groundId = 424
local stairId = 3219
local stairPosition = Position(32225, 32282, 9) -- Position where the stairs will spawn
local tilePosition = Position(1000, 1000, 7) -- Position of the tile we want to stand on

---------------------------------------------------------------------------

local stepin = MoveEvent()

function stepin.onStepIn(player, item, position, fromPosition)
    -- If the creature on the tile is not a player, we won't spawn the stairs
    if not player:isPlayer() then return true end

    local groundTile = Tile(stairPosition)
    local ground = groundTile and groundTile:getItemById(groundId)

    if ground then
        ground:transform(stairId)
    end
    return true
end

stepin:position(tilePosition)
stepin:type("stepin")
stepin:register()

---------------------------------------------------------------------------

local stepout = MoveEvent()

function stepout.onStepOut(player, item, position, fromPosition)
    if not player:isPlayer() then return true end

    -- If there is still another player on the tile we won't remove the stairs
    for _, tilePlayer in pairs(Tile(tilePosition):getCreatures()) do
        if tilePlayer and tilePlayer:isPlayer() then
            return true
        end
    end

    local stairTile = Tile(stairPosition)
    local stairs = stairTile and stairTile:getItemById(stairId)

    if stairs then
        stairs:transform(groundId)
    end
    return true
end

stepout:position(tilePosition)
stepout:type("stepout")
stepout:register()
 
Last edited:
Solution
Thank you for your reply @Heroid !

Maybe you can also help me with the next part of the quest, spawn the teleporter when hitting the next switch.

Here is my full code so far:

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    --first lever to open the ladder
    if item.actionid == 50023 then
        local laddertile = Tile(Position({x = 32225, y = 32276, z = 8}))
            if item.itemid == 1945 then
                laddertile:getItemById(9021):transform(369)
                item:transform(1946)
            else
                laddertile:getItemById(369):transform(9021)
                item:transform(1945)
            end
    --second lever to open the portal to cyclops
    elseif item.actionid == 50024 then
        local portaltile = Tile(Position({x = 32232, y = 32276, z = 9}))
        if item.itemid == 1945 then
            if portaltile:getItemById(1387) then
                portaltile:getItemById(1387):remove()
            else
                local portal = Game.createItem(1387, 1, {x = 32232, y = 32276, z = 9})
                if portal then
                    portal:setActionId(50026)
                end
                item:transform(1946)
            end
        else
            if portaltile:getItemById(1387) then
                portaltile:getItemById(1387):remove()
                item:transform(1945)
            end
        end
    end
    return true
end

The first half works in changing the muddy floor to a ladder but I can't get the teleporter to spawn in.
 
Thank you for your reply @Heroid !

Maybe you can also help me with the next part of the quest, spawn the teleporter when hitting the next switch.

Here is my full code so far:

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    --first lever to open the ladder
    if item.actionid == 50023 then
        local laddertile = Tile(Position({x = 32225, y = 32276, z = 8}))
            if item.itemid == 1945 then
                laddertile:getItemById(9021):transform(369)
                item:transform(1946)
            else
                laddertile:getItemById(369):transform(9021)
                item:transform(1945)
            end
    --second lever to open the portal to cyclops
    elseif item.actionid == 50024 then
        local portaltile = Tile(Position({x = 32232, y = 32276, z = 9}))
        if item.itemid == 1945 then
            if portaltile:getItemById(1387) then
                portaltile:getItemById(1387):remove()
            else
                local portal = Game.createItem(1387, 1, {x = 32232, y = 32276, z = 9})
                if portal then
                    portal:setActionId(50026)
                end
                item:transform(1946)
            end
        else
            if portaltile:getItemById(1387) then
                portaltile:getItemById(1387):remove()
                item:transform(1945)
            end
        end
    end
    return true
end

The first half works in changing the muddy floor to a ladder but I can't get the teleporter to spawn in.
1 issue or request per thread, if this thread is solved. Create a different thread for your other request.
 
Back
Top