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.
3.6K
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
File: Timer1_2.lua | 3.63kb | 144 lines.
 --[[
  Script made by Lee (Discord: l33_) - www.trainorcreations.com
  If you want to support my work, feel free to donate at https://trainorcreations.com/donate
  PS. Stop ripping off my work and selling it as your own.
 ]]--
if not storage.timers then
    storage.timers = {
        cText = 'This',
        cTime = '00:00',
        time = 1,
        timers = {
            ['20:35'] = { name = 'Cyclops', exec = false },
            ['7:01'] = { name = 'RareSpawn', exec = false  }
        }
    }
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

function changeIcon(change)
    if change then
        g_window.flash()
        g_window.setIcon('/images/greencircle')
    else
        g_window.setIcon('/images/clienticon')
    end
end

changeIcon(false)

UI.Separator()
UI.Label("Example Timers")
UI.Separator()
for i, timer in pairs(storage.timers.timers) do
    UI.Label(i .. ' - '.. timer.name)
end
UI.Separator()
macro(1000, "Timer Date", function()
    local date = os.date ("%H:%M")
    local da = storage.timers.timers[date]
    if da and not da.exec then
        -- INSERT YOUR FUNCTIONS HERE
        CaveBot.gotoLabel(da.name)
        changeIcon(true)
        -- INSERT YOUR FUNCTIONS HERE
        da.exec = true
    end
end)
UI.Label("Custom Label")
cText = UI.TextEdit(storage.timers.cText or "Time", function(widget, newText)
    storage.timers.cText = newText
end)
UI.Label("Custom Time")
cTime = UI.TextEdit(storage.timers.cTime or "00:00", function(widget, newText)
    storage.timers.cTime = newText
end)
UI.Button("Add", function()
    local tmp = cTime:getText()
    storage.timers.timers[tmp] = { name = cText:getText(), exec = false }
end)
UI.Separator()
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")
        changeIcon(true)
        -- 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)
File: Timer1_1.lua | 2.24kb | 92 lines.
 --[[
  Script made by Lee (Discord: l33_) - www.trainorcreations.com
  If you want to support my work, feel free to donate at https://trainorcreations.com/donate
  PS. Stop ripping off my work and selling it as your own.
 ]]--
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)
File: TimerFix.lua | 459b | 20 lines.
 --[[
  Script made by Lee (Discord: l33_) - www.trainorcreations.com
  If you want to support my work, feel free to donate at https://trainorcreations.com/donate
  PS. Stop ripping off my work and selling it as your own.
 ]]--
-- 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 Mar 2022
Ads