• 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 script assistance.

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am having difficulty figuring out how to add a check. if the wall "9119" is missing, then cannot use item again within the 5 second timer. This issue is when the item 2080, piano, is used after the wall is removed. It then moves to the next item in the stack pos 3. Which is an archway. The script as a whole works, aside from this one flaw.

Code:
-- If door is open, then can not reuse again while open.
                if  blah then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Door is already active.")
                return false
            end

Code:
  local storage = 15001
  local wallPos = {
            [1] = {x=1024, y=929, z=9, stackpos=3}
        }

        local time_ = 5 -- 5 seconds

        function onUse(player, item, fromPosition, target, toPosition, isHotkey)
            local function reset()
                -- reset walls
                    Game.createItem(9119, 1, wallPos[1])
                end
          
                -- check if player has storage
            if player:getStorageValue(storage) < 1 then
               player:sendTextMessage(MESSAGE_INFO_DESCR, "You must complete Catacombs Quest!")
                doSendMagicEffect(pos, CONST_ME_POOF)
                return false
            else

            -- If door is open, then can not reuse again while open.
                if  blah then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Door is already active.")
                return false
            end
         end

            --  add reset
            addEvent(reset, time_ * 1000)

            -- remove walls, send message
            for i = 1, #wallPos do
            item:getPosition():sendMagicEffect(CONST_ME_SOUND_BLUE)
                doRemoveItem(getThingfromPos(wallPos[i]).uid)
            end
      
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Hurry, the wall is closing!")
            return true
        end

I know I can obviously do this:
Code:
  local storage = 15001
  local wallPos = {
            [1] = {x=1024, y=929, z=9, stackpos=3}
        }

        local time_ = 5 -- 5 seconds

        function onUse(player, item, fromPosition, target, toPosition, isHotkey)
            local function reset()
                 -- reset switch
            item:transform(2080)
                -- reset walls
                    Game.createItem(9119, 1, wallPos[1])
                end
               
                -- check if lever is currently used
            if player:getStorageValue(storage) < 1 then
               player:sendTextMessage(MESSAGE_INFO_DESCR, "You must complete Catacombs Quest!")
                doSendMagicEffect(pos, CONST_ME_POOF)
                return false
             end
            -- If door is open, then can not reuse again while open.
             if item.itemid == 2082 then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Door is already active.")
                return false
                end

            -- add reset
            item:transform(2082)
            addEvent(reset, time_ * 1000)
  
            -- remove walls, send message
            for i = 1, #wallPos do
            item:getPosition():sendMagicEffect(CONST_ME_SOUND_BLUE)
                doRemoveItem(getThingfromPos(wallPos[i]).uid)
            end
           
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Hurry, the wall is closing!")
            return true
        end
 
Last edited:
You can achieve this by checking the if the itemid of 9119 isn't at the position.
Code:
local waitStorage = 15002
local wall = Tile(wallPos):getItemById(9119)

if not wall then
    player:setStorageValue(waitStorage, os.time() + time_))
    return true
end


You can check the storage of the player using a function like this:
Code:
local waiting = player:getStorageValue(waitStorage)
if waiting > os.time() then
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You can\'t use this yet.')
    return true
end

Or you can also use this to show the exact time the player need to wait using a function lets call it "timeString".
Code:
local waiting = player:getStorageValue(waitStorage)
if waiting > os.time() then
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You can\'t use this for another ' .. timeString(waiting - os.time()) .. '.')
    return true
end

You need the function aswell:
Code:
local function timeString(s)
    local hours = math.floor(s / (60 * 60))
    local minutes = math.floor(s / 60 % 60)
    local seconds = s % 60

    local t = {}
    if hours > 0 then
        table.insert(t, hours .. ' hour' .. (hours == 1 and '' or 's'))
    end
    if minutes > 0 then
        table.insert(t, minutes .. ' minute' .. (minutes == 1 and '' or 's'))
    end
    if seconds > 0 then
        table.insert(t, seconds .. ' second' .. (seconds == 1 and '' or 's'))
    end

    local str = ''
    for i = 1, #t do
        str = str .. t[i]
        str = str .. (i < #t - 1 and ', ' or i == #t - 1 and ' and ' or '')
    end
    return str
end
 
@HalfAway, thank you. I will try this later. It's not a dire emergency, more of an enquire. I am making an effort to learn, with the help of the community of course. Be it slow. Progress nonetheless.
 
Back
Top