• 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 [TFS 0.X] Door with cooldown between use

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hello everyone, everything good? I didn't find anything like it so I'm asking you: is there a way to put a cooldown on a door, where each player has a cooldown to open and cross it? I want each player to be able to access a certain room after "x" hours.
 
Put ActionId on door and tile.
Make sure the floor tile is 'past' the door.

Untitled.png

movements.xml
Lua:
local storageKey = 45001
local cooldown = 18000 -- in seconds (aka 5 hours)

function onStepIn(cid, item, position, fromPosition)
    local currentTime = os.time()
    if getCreatureStorage(cid, storageKey) > currentTime then
        return true
    end
    setCreatureStorage(cid, storageKey, currentTime + cooldown)
    return true
end
actions.xml
Lua:
local storageKey = 45001

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureStorage(cid, storageKey) > os.time() then
        return false
    end
    return true
end
 
Put ActionId on door and tile.
Make sure the floor tile is 'past' the door.

View attachment 70405

movements.xml
Lua:
local storageKey = 45001
local cooldown = 18000 -- in seconds (aka 5 hours)

function onStepIn(cid, item, position, fromPosition)
    local currentTime = os.time()
    if getCreatureStorage(cid, storageKey) > currentTime then
        return true
    end
    setCreatureStorage(cid, storageKey, currentTime + cooldown)
    return true
end
actions.xml
Lua:
local storageKey = 45001

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureStorage(cid, storageKey) > os.time() then
        return false
    end
    return true
end
Just a dumb question, same actionid for title and door?
 
Just a dumb question, same actionid for title and door?
Probably be better to use separate actionId's.

Or change the onUse script to check for the doors itemid. Then you can use the same actionId.

Lua:
local storageKey = 45001
local doorId = 1111

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == doorId then
        if getCreatureStorage(cid, storageKey) > os.time() then
            return false
        end
    end
    return true
end
 
Back
Top