Your browser does not support JavaScript or its disabled!
Please turn it on, or be aware that some features on this website will not work correctly.
276
In-game timers #66
Self Explanatory
If you get a global 'os' (a nil value error). This is because you are using an old game_bot file.
Check the second file down below for the fix
2.24kb | 92 lines.
if not storage.timers then  storage.timers = {  time = 1 } end

local widgetTC = setupUI([[
Panel
  size: 14 14
  anchors.bottom: parent.bottom
  anchors.left: parent.left
  Label
    id: lblTimer
    color: green
    font: verdana-11px-rounded
    height: 12
    background-color: #00000040
    opacity: 0.87
    text-auto-resize: true
    !text: tr('00:00:00')

]], modules.game_interface.getMapPanel())
local endTime = 1

local doFormatTime = function(v)
    local hours = string.format("%02.f", math.floor(v / 3600))
    local mins = string.format("%02.f", math.floor(v / 60 - (hours * 60)))
    local seconds = string.format("%02.f", math.floor(math.mod(v, 60)))
    return hours .. ":" .. mins .. ":" .. seconds
end

tmrMacro = macro(1000, "Timer", function(widget)
    if os.time() >= endTime then
        widgetTC.lblTimer:setText('00:00:00')

        -- INSERT YOUR FUNCTIONS HERE
        playSound("/sounds/Player_Attack.ogg")
        g_game.talk("timer end")
        -- INSERT YOUR FUNCTIONS HERE

        widget:setOff()
        return
    end
    widgetTC.lblTimer:setText(doFormatTime(os.difftime(endTime, os.time())))
end)

UI.Label("Custom Timer")
UI.TextEdit(storage.timers.time or 1, function(widget, newText)
    storage.timers.time = tonumber(newText)
end)
UI.Separator()
-- Examples
UI.Button("Custom Hour", function()
    endTime = os.time() + storage.timers.time * 3600
    tmrMacro:setOn()
end)
UI.Button("Custom Minute", function()
    endTime = os.time() + storage.timers.time * 60
    tmrMacro:setOn()
end)
UI.Button("Custom Seconds", function()
    endTime = os.time() + storage.timers.time
    tmrMacro:setOn()
end)
UI.Separator()
tmrMacro:setOff()

--------------
-- Examples --
--------------
UI.Label("Example Buttons")

UI.Button("5 Hours", function()
    endTime = os.time() + 5 * 3600
    tmrMacro:setOn()
end)

UI.Button("1 Hour", function()
    endTime = os.time() + 1 * 3600
    tmrMacro:setOn()
end)
UI.Button("30mins", function()
    endTime = os.time() + 1800
    tmrMacro:setOn()

end)
UI.Button("1min", function()
    endTime = os.time() + 1 * 60
    tmrMacro:setOn()

end)

UI.Button("5 seconds", function()
    endTime = os.time() + 5
    tmrMacro:setOn()
end)
459b | 20 lines.
-- fix for global 'os' (a nil value error)

--find this
context.pcall = pcall
context.load = function(str) return assert(load(str, nil, nil, context)) end


-- make it look like this.

context.pcall = pcall
-- insert this context.os
context.os = {
  time = os.time,
  date = os.date,
  difftime = os.difftime,
  date = os.date,
  clock = os.clock
}
-- insert this
context.load = function(str) return assert(load(str, nil, nil, context)) end

29 Nov 2021