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

Solved Wall lever with reset timer issues on 1.1

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am trying to remove wall with lever & on timer reset, create walls back on tfs 1.1. My timer is resetting my lever, but not removing my walls. What am I doing wrong?


Code:
local wallPos = {
           [1] = {x=1012, y=782, z=10, stackpos=1},
           [2] = {x=1012, y=781, z=10, stackpos=1},
           [3] = {x=1019, y=776, z=10, stackpos=1},
           [4] = {x=1020, y=776, z=10, stackpos=1}
        }

        local time_ = 10 -- seconds

        function onUse(player, item, fromPosition, target, toPosition, isHotkey)
            local function reset()
                -- reset switch
                item:transform(1945)
                -- reset walls
                    Game.createItem(9118, 1, wallPos[1])
                    Game.createItem(9118, 1, wallPos[2])
                    Game.createItem(9119, 1, wallPos[3])
                    Game.createItem(9119, 1, wallPos[4])                  
                end

           -- check if lever is currently used
           if item.itemid == 1946 then
             player:sendTextMessage(MESSAGE_INFO_DESCR, "Switch is already active.")
             return false
           end
     
           -- transform lever, and add reset
           item:transform(1946)
           addEvent(reset, time_ * 1000)
     
           -- remove walls, send message
                   doRemoveItem(wallPos[1].uid,1)
                   doRemoveItem(wallPos[2].uid,1)
                   doRemoveItem(wallPos[3].uid,1)
                   doRemoveItem(wallPos[4].uid,1)
           player:sendTextMessage(MESSAGE_INFO_DESCR, "Reward Chamber is now open!")
           return true
        end
 
wallPos the table its index is a location but not an item

Code:
        local wallPos = {
            [1] = {x=1012, y=782, z=10, stackpos=1},
            [2] = {x=1012, y=781, z=10, stackpos=1},
            [3] = {x=1019, y=776, z=10, stackpos=1},
            [4] = {x=1020, y=776, z=10, stackpos=1}
        }

        local time_ = 10 -- seconds

        function onUse(player, item, fromPosition, target, toPosition, isHotkey)
            local function reset()
                -- reset switch
            item:transform(1945)
                -- reset walls
                    Game.createItem(9118, 1, wallPos[1])
                    Game.createItem(9118, 1, wallPos[2])
                    Game.createItem(9119, 1, wallPos[3])
                    Game.createItem(9119, 1, wallPos[4])                 
                end

           -- check if lever is currently used
            if item.itemid == 1946 then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Switch is already active.")
                return false
            end
    
            -- transform lever, and add reset
            item:transform(1946)
            addEvent(reset, time_ * 1000)
    
            -- remove walls, send message
            for i = 1, #wallPos do
                doRemoveItem(getThingfromPos(wallPos[i]).uid,1)
            end
           
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Reward Chamber is now open!")
            return true
        end
 
Thank you, I'm just trying to understand the code. I am extremely new to this format. Which I'm sure is flamingly obvious. It still doesn't remove the wall from the pos.
 
Thank you, I'm just trying to understand the code. I am extremely new to this format. Which I'm sure is flamingly obvious. It still doesn't remove the wall from the pos.
reload your server, like completely shut it down, then try the script again, remove the 1 from
doRemoveItem(getThingfromPos(wallPos).uid)
 
Explanation is in the code
Code:
        local wallPos = {
            [1] = {x=1012, y=782, z=10, stackpos=1},
            [2] = {x=1012, y=781, z=10, stackpos=1},
            [3] = {x=1019, y=776, z=10, stackpos=1},
            [4] = {x=1020, y=776, z=10, stackpos=1}
        }

        local time_ = 10 -- seconds

        function onUse(player, item, fromPosition, target, toPosition, isHotkey)
            local function reset()
                -- reset switch
            item:transform(1945)
                -- reset walls
                    Game.createItem(9118, 1, wallPos[1])
                    Game.createItem(9118, 1, wallPos[2])
                    Game.createItem(9119, 1, wallPos[3])
                    Game.createItem(9119, 1, wallPos[4])               
                end

           -- check if lever is currently used
            if item.itemid == 1946 then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Switch is already active.")
                return false
            end
  
            -- transform lever, and add reset
            item:transform(1946)
            addEvent(reset, time_ * 1000)
  
            -- remove walls, send message
            --[[
                1st getThingfromPos is called and passed a wallPos at the index of i, the item is return and then we ask for
                one of it's properties in this case its uid, we then pass that to doRemoveItem, which removes the item
            ]]
            for i = 1, #wallPos do
                doRemoveItem(getThingfromPos(wallPos[i]).uid)
            end
         
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Reward Chamber is now open!")
            return true
        end
 
Last edited:
Explanation is in the code
Code:
        local wallPos = {
            [1] = {x=1012, y=782, z=10, stackpos=1},
            [2] = {x=1012, y=781, z=10, stackpos=1},
            [3] = {x=1019, y=776, z=10, stackpos=1},
            [4] = {x=1020, y=776, z=10, stackpos=1}
        }

        local time_ = 10 -- seconds

        function onUse(player, item, fromPosition, target, toPosition, isHotkey)
            local function reset()
                -- reset switch
            item:transform(1945)
                -- reset walls
                    Game.createItem(9118, 1, wallPos[1])
                    Game.createItem(9118, 1, wallPos[2])
                    Game.createItem(9119, 1, wallPos[3])
                    Game.createItem(9119, 1, wallPos[4])              
                end

           -- check if lever is currently used
            if item.itemid == 1946 then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Switch is already active.")
                return false
            end
 
            -- transform lever, and add reset
            item:transform(1946)
            addEvent(reset, time_ * 1000)
 
            -- remove walls, send message
            --[[
                1st getThingfromPos is called and passed a wallPos at the index of i, the item is return and then we ask for
                one of it's properties in this case its uid, we then pass that to doRemoveItem, which removes the item
            ]]
            for i = 1, #wallPos do
                doRemoveItem(getThingfromPos(wallPos[i]).uid)
            end
        
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Reward Chamber is now open!")
            return true
        end
It removes every item on the position, even the tiles. The wall is removed but without that tile you can't walk through.
 
Back
Top