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

Showing cooldowns (storages) on OTC

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
580
Solutions
2
Reaction score
58
Location
México
Hello, Im trying to create a 8.6 cooldown bar based on opcodes. My server has some storages used as cooldowns
E.G:
Lua:
function onCastSpell(cid, var)
local Exura = 23067
  if exhaustion.check(cid, Exura) == false then
    exhaustion.set(cid,Exura, 2)
    return doCombat(cid, combat, var)
  else
    doPlayerSendCancel(cid, "Cooldown[" ..exhaustion.get(cid,Exura).."]")
  end
end

When player uses this spell he will get 2 seconds of Exura (storage: 23067).
Then client should show something like the image attached (its an example of wow cast bar, but should be reversed, instead of getting full, it is getting empty until time gets to 0 and fade the notification)

As image shows the cooldowns should be shown ascending depending of the remaining time


i was reading this: Trying to receive a storage value from Tfs > Otclient (https://otland.net/threads/trying-to-receive-a-storage-value-from-tfs-otclient.265046/)
But, to be honest i didnt understand a single thing and i failed. I already compiled my TFS 0.4 to accept opcodes and it worked with another simplier script.

Hope someone could help me to achieve this
 

Attachments

Preview : https://i.gyazo.com/8d4100ea1b736535c3b89bddcc2c8963.mp4

I think it's not the "reversed WoW Cast Bar", but may help :rolleyes:
This is my LUA to "countdown timer" , hope it can help you a little bit:
Lua:
local received_first_tick = false
local do_show = false
local ticks   = 0

function window_hide()
  window:hide()
  received_first_tick = false
  do_show             = false
end

function init()
    window = g_ui.loadUI('timeleft', modules.game_interface.getMapPanel())
    window:disableResize()  
    window:setup()
    window_hide()
    window:getChildById('minimizeButton'):destroy()
    window:getChildById('closeButton'):destroy()
          
    ProtocolGame.registerExtendedOpcode(GameServerOpcodes.TimeLeftWindow, function (protocol, opcode, buffer)
        ticks = tonumber(buffer) or 0
        do_show = true
        received_first_tick = true    
    end)
    runTimeleftThread()

    connect(g_game, 'onTextMessage', serverComunication)  
end

function terminate()
    window:destroy()
    ProtocolGame.unregisterExtendedOpcode(GameServerOpcodes.TimeLeftWindow, true)
    disconnect(g_game, 'onTextMessage', serverComunication)
end

function serverComunication(mode, text)
    if not g_game.isOnline() then
        return
    end

end

function quit()
    window_hide()   
end

function request_timeleft_window()
    local protocolGame = g_game.getProtocolGame()
    if protocolGame then
        protocolGame:sendExtendedOpcode(ClientOpcodes.RequestTimeLeftWindow)
    end
end

function onGameStart()
    window_hide()
    request_timeleft_window()
end

function seconds_to_clock(seconds)
    local seconds = tonumber(seconds)
    if seconds == 0 then
        return "00:00:00";
    end
    hours = string.format("%02.f", math.floor(seconds / 3600))
    mins  = string.format("%02.f", math.floor(seconds / 60 - (hours * 60)))
    secs  = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60))
    return hours .. ":" .. mins .. ":" .. secs
end

function runTimeleftThread()

    if not window then
      return
    end

    if do_show and received_first_tick then
        window:show()
        window:setPosition({ x = (g_window.getWidth() / 2) - 125, y = (g_window.getHeight() * 0.1) - 55})
        do_show = false
    end

    if window:isVisible() then
        local timeleftticks = window:getChildById('timeleftticks')
        if ticks > 0 then       
            timeleftticks:setText(seconds_to_clock(ticks))
        else               
            timeleftticks:setText('Time is over!')     
            scheduleEvent(window_hide, 2000)
        end
    end
    ticks = math.max(0, ticks - 1)
    scheduleEvent(runTimeleftThread, 1000)
end

@elnelson You need to review entire code and cut that piece you want :)
(specially the runTimeleftThread function and function for converting "seconds into clock" (seconds_to_clock))
 
Preview : https://i.gyazo.com/8d4100ea1b736535c3b89bddcc2c8963.mp4

This is my LUA to "countdown timer" , hope it can help you a little bit:
Lua:
local received_first_tick = false
local do_show = false
local ticks   = 0

function window_hide()
  window:hide()
  received_first_tick = false
  do_show             = false
end

function init()
    window = g_ui.loadUI('timeleft', modules.game_interface.getMapPanel())
    window:disableResize()  
    window:setup()
    window_hide()
    window:getChildById('minimizeButton'):destroy()
    window:getChildById('closeButton'):destroy()
          
    ProtocolGame.registerExtendedOpcode(GameServerOpcodes.TimeLeftWindow, function (protocol, opcode, buffer)
        ticks = tonumber(buffer) or 0
        do_show = true
        received_first_tick = true    
    end)
    runTimeleftThread()

    connect(g_game, 'onTextMessage', serverComunication)  
end

function terminate()
    window:destroy()
    ProtocolGame.unregisterExtendedOpcode(GameServerOpcodes.TimeLeftWindow, true)
    disconnect(g_game, 'onTextMessage', serverComunication)
end

function serverComunication(mode, text)
    if not g_game.isOnline() then
        return
    end

end

function quit()
    window_hide()   
end

function request_timeleft_window()
    local protocolGame = g_game.getProtocolGame()
    if protocolGame then
        protocolGame:sendExtendedOpcode(ClientOpcodes.RequestTimeLeftWindow)
    end
end

function onGameStart()
    window_hide()
    request_timeleft_window()
end

function seconds_to_clock(seconds)
    local seconds = tonumber(seconds)
    if seconds == 0 then
        return "00:00:00";
    end
    hours = string.format("%02.f", math.floor(seconds / 3600))
    mins  = string.format("%02.f", math.floor(seconds / 60 - (hours * 60)))
    secs  = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60))
    return hours .. ":" .. mins .. ":" .. secs
end

function runTimeleftThread()

    if not window then
      return
    end

    if do_show and received_first_tick then
        window:show()
        window:setPosition({ x = (g_window.getWidth() / 2) - 125, y = (g_window.getHeight() * 0.1) - 55})
        do_show = false
    end

    if window:isVisible() then
        local timeleftticks = window:getChildById('timeleftticks')
        if ticks > 0 then       
            timeleftticks:setText(seconds_to_clock(ticks))
        else               
            timeleftticks:setText('Time is over!')     
            scheduleEvent(window_hide, 2000)
        end
    end
    ticks = math.max(0, ticks - 1)
    scheduleEvent(runTimeleftThread, 1000)
end

@elnelson You need to review entire code and cut that piece you want :) (specially the runTimeleftThread function and function for converting "seconds into clock" (seconds_to_clock))
Thanl you very much dude I will take a look now!,

Edit: where should i put this? as a module with lua extension?
 
Yeah it's just piece of my "game_timeleft" module.
I just pasted here .lua file because I guess it can help some people with doing "countdown time" or something like that in OTC.
As I said in my post, you should just review and understand this code, use your brain and change it a little bit, so you can maybe implement it into your idea of cooldowns or something. :p
I'll just shared it (that includes few functions) that might be useful of doing your cooldowns thing.
 
Yeah it's just piece of my "game_timeleft" module.
I just pasted here .lua file because I guess it can help some people with doing "countdown time" or something like that in OTC.
As I said in my post, you should just review and understand this code, use your brain and change it a little bit, so you can maybe implement it into your idea of cooldowns or something. :p
I'll just shared it (that includes few functions) that might be useful of doing your cooldowns thing.
Hello, i tried to create a new module to test out your script but i encountered some errors,

The first error was in the init function, most of windows: functionsdoesnt work properly, (see image 1)
i commented the errors the terminal showed me and i got until this error and i really dont know what to do now (image 2)

Could you give me a hand?
 

Attachments

To be honest - if you wan't to make "cooldown bars" like in WoW, you need to start with looking for "progress bars", I saw that @oen432 done good progress bar , I saw few other threads (just googled it : "progress bar otland".
And then.. you need to combine two things - "progress bars" and cooldown timer (for example, this one that I sent you above) into one thing.

It's requires some time to do but you always learning if you atleast try do something by yourself...

Just do it! Stop giving up, yesterday you said tommorow. You should get to the point where anyone else quits and you're not gonna stop there.
Make your dreams come true!
Nothing is impossible!
Go what are you waiting for!
 
Tbf, you can just take cooldowns module from OTC, edit OTUI so it won't be just icons but icon + bar + some lables. Only few changes in Lua code would be required. For someone that already worked with modules, this should take 15min tops.
 
Back
Top