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

RevScripts Lever by time

bolachapanco

Member
Joined
Aug 5, 2023
Messages
30
Reaction score
5
Location
Brazil
How to create a script that when pulling the lever for 4 player is moved to a coordinate and after one hour is moved again to another coordinate.

Lua:
local config = {
    hunt = {
        name = "Hunt Cloak",
        position = Position(31923, 32363, 7),
        maxHuntTime = 30 * 60
    },
    requiredLevel = 250,
    playerPositions = {
        {pos = Position(32348, 32362, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT},
        {pos = Position(32348, 32363, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT},
        {pos = Position(32348, 32364, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT},
        {pos = Position(32348, 32365, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT}
    },
    exit = Position(33621, 31427, 10),
    storage = Storage.HuntPay.HuntTimerCloack
}

local huntCloakLever = Action()
function huntCloakLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storageValue = getPlayerStorageValue(player, config.storage)
    if storageValue <= 0 then
        doTeleportThing(player, config.hunt.position)
        doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "You are participating in the hunt.")
       
        setPlayerStorageValue(player, config.storage, os.time() + config.hunt.maxHuntTime)
       
        addEvent(function()
            doTeleportThing(player, config.exit)
            doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "Your time for hunting has ended. You were teleported.")
            setPlayerStorageValue(player, config.storage, 0)
        end, config.hunt.maxHuntTime * 1000)
    else
        doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "You are already participating in the hunt.")
    end

    return true
end

huntCloakLever:position({x = 32348, y = 32361, z = 8})
huntCloakLever:register()

I tried this without success
 
You'll have to use AddEvent function, to make them tp back after 1 hour, the same way you teleport, just with some delay.
Just keep in mind that if players dies before the timer runs out, it will print some error on your console if you do nothing about.
 
Lua:
local config = {
    hunt = {
        name = "Hunt Cloak",
        position = Position(31923, 32363, 7),
        maxHuntTime = 60 * 60, 
        firstTeleportPosition = Position(12345, 67890, 7), 
        secondTeleportPosition = Position(54321, 98765, 7) 
    },
    requiredLevel = 250,
    playerPositions = {
        {pos = Position(32348, 32362, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT},
        {pos = Position(32348, 32363, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT},
        {pos = Position(32348, 32364, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT},
        {pos = Position(32348, 32365, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT}
    },
    exit = Position(33621, 31427, 10),
    storage = Storage.HuntPay.HuntTimerCloack
}

local huntCloakLever = Action()
function huntCloakLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storageValue = getPlayerStorageValue(player, config.storage)
    if storageValue <= 0 then
        doTeleportThing(player, config.hunt.position)
        doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "You are participating in the hunt.")
      
        setPlayerStorageValue(player, config.storage, os.time() + config.hunt.maxHuntTime)
      
        addEvent(function()
            local currentTime = os.time()
            local storageTime = getPlayerStorageValue(player, config.storage)
            if currentTime - storageTime >= config.hunt.maxHuntTime then
                local randomTeleport = math.random(1, 2)
                if randomTeleport == 1 then
                    doTeleportThing(player, config.hunt.firstTeleportPosition)
                else
                    doTeleportThing(player, config.hunt.secondTeleportPosition)
                end
                doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "Your time for hunting has ended. You were teleported.")
                setPlayerStorageValue(player, config.storage, 0)
            end
        end, config.hunt.maxHuntTime * 1000)  -- Check after one hour (in milliseconds)
    else
        doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "You are already participating in the hunt.")
    end

    return true
end

huntCloakLever:position({x = 32348, y = 32361, z = 8})
huntCloakLever:register()
 
I redid the script and now I have the situation that even when I die or leave the hunt I am teleported at the end of the stipulated time, how do I cancel the event if I leave or die in the hunt?

Lua:
local config = {
    leverPosition = Position(32348, 32361, 8),  -- Posição da alavanca
    playerPositions = {
        {pos = Position(32348, 32362, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT},
        {pos = Position(32348, 32363, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT},
        {pos = Position(32348, 32364, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT},
        {pos = Position(32348, 32365, 8), teleport = Position(31923, 32363, 7), effect = CONST_ME_TELEPORT}
    },
    maxStayTime = 1 * 60,
    exitPosition = Position(32369, 32241, 7)
}

local teleportLever = Action()

function teleportLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if toPosition.x == config.leverPosition.x and toPosition.y == config.leverPosition.y and toPosition.z == config.leverPosition.z then
        for _, posConfig in ipairs(config.playerPositions) do
            local playerPos = posConfig.pos
            local teleportPos = posConfig.teleport
            local player = Tile(playerPos):getTopCreature()
            
            if player and isPlayer(player) then
                doTeleportThing(player, teleportPos)
                doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "Your hunt has started, if you die you can't come back.")
                
                local stayTime = config.maxStayTime
                setPlayerStorageValue(player, Storage.StayTimer, os.time() + stayTime)
                
                addEvent(function()
                    local currentTime = os.time()
                    local storageTime = getPlayerStorageValue(player, Storage.StayTimer)
                    if currentTime >= storageTime then
                        doTeleportThing(player, config.exitPosition)
                        doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "Your hunting time is over")
                        setPlayerStorageValue(player, Storage.StayTimer, 0)
                    end
                end, stayTime * 1000)
            end
        end
        return true
    end
    return false
end

teleportLever:id(8911)
teleportLever:register()
 
I redid the script and now I have the situation that even when I die or leave the hunt I am teleported at the end of the stipulated time, how do I cancel the event if I leave or die in the hunt?

why do you use storage in your script?
 
Back
Top