• 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 [RevScripts] Cooldown

bolachapanco

Member
Joined
Aug 5, 2023
Messages
30
Reaction score
5
Location
Brazil
Could you help me to put a time counter that shows how much time is left to summon the npc again.

Base Canary: https://github.com/opentibiabr/canary

Lua:
local refiller = Action()
local timeToDisapear = 120 * 1000
function refiller.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and  player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) or player:isPzLocked() then
        player:sendCancelMessage("You can't use this while in battle.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end
    
    
    local pid = player:getId()
    if HUNT_REFILLER[pid] and HUNT_REFILLER[pid].time > os.time() then
        player:sendCancelMessage("You need to wait before use this item again") -- 
        return true
    end

    if not HUNT_REFILLER[pid] then HUNT_REFILLER[pid] = {} end
        local position = player:getPosition()
        local npc = Game.createNpc('Hunt Refiller', position)
        HUNT_REFILLER[pid].time = os.time() + 15 * 60
        HUNT_REFILLER[pid].npc = npc:getId()
        
        addEvent(function()
            npc:remove()
        end, timeToDisapear)
        if npc then
            npc:setMasterPos(position)
            position:sendMagicEffect(CONST_ME_MAGIC_RED)
        end


    return true
end

refiller:id(19369) -- REPLACE HERE
refiller:register()
 
this should do the trick

Lua:
local refiller = Action()
local timeToDisapear = 120 * 1000
function refiller.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and  player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) or player:isPzLocked() then
        player:sendCancelMessage("You can't use this while in battle.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end
  
  
    local pid = player:getId()
    if HUNT_REFILLER[pid] and HUNT_REFILLER[pid].time > os.time() then
        player:sendCancelMessage("You need to wait "..(HUNT_REFILLER[pid].time - os.time()).." before use this item again")
        return true
    end

    if not HUNT_REFILLER[pid] then HUNT_REFILLER[pid] = {} end
        local position = player:getPosition()
        local npc = Game.createNpc('Hunt Refiller', position)
        HUNT_REFILLER[pid].time = os.time() + 15 * 60
        HUNT_REFILLER[pid].npc = npc:getId()
      
        addEvent(function()
            npc:remove()
        end, timeToDisapear)
        if npc then
            npc:setMasterPos(position)
            position:sendMagicEffect(CONST_ME_MAGIC_RED)
        end


    return true
end

refiller:id(19369) -- REPLACE HERE
refiller:register()

you can also add something like this to make it show more precisely the time left

Lua:
timeLeft = HUNT_REFILLER[pid].time-os.time()
 
local days = math.floor((timeLeft / 3600) / 24)
local hours = math.floor((timeLeft / 3600) % 24)
local minutes = math.floor((timeLeft / 60) % 60)
local seconds = (timeLeft % 3600) % 60

player:sendCancelMessage("You need to wait "..days.." days, "..hours.." hours, "..minutes.." minutes and "..seconds.." seconds before use this item again.")
 
Back
Top