Jump to content

[HELP] countdown


djharbi2

Recommended Posts

Just create a variable that represents the timer in seconds (since thats the smallest time you'd want to show) so if you'd want a timer of 10 min you'd have:

timer = 600

You'd draw that timer variable as a dxtext on render and decrement the timer by 1. You'd want to convert the 600s to min and seconds tho but thats just some simple math.

Link to comment
1 minute ago, ViRuZGamiing said:

Just create a variable that represents the timer in seconds (since thats the smallest time you'd want to show) so if you'd want a timer of 10 min you'd have:

timer = 600

You'd draw that timer variable as a dxtext on render and decrement the timer by 1. You'd want to convert the 600s to min and seconds tho but thats just some simple math.

do you make an example

Link to comment

Client:

local sx, sy = guiGetScreenSize()

function renderText()
    dxDrawText(timeText, sx/2, sy/2, 0, 0, tocolor(255, 255, 255), 2, "default-bold")
end

function updateTime()
    if isTimer(timer) then
        timeText = formatTime(getTimerDetails(timer))
    end
end

addCommandHandler("timer", function(cmd, min)
    if tonumber(min) then
        if not isTimer(timer) then
            local time = tonumber(min) * 60000
            timer = setTimer(function()
                removeEventHandler("onClientRender", getRootElement(), renderText)
            end, time, 1)
            setTimer(updateTime, 1000, 0)
            timeText = formatTime(getTimerDetails(timer))
            addEventHandler("onClientRender", getRootElement(), renderText)
        end
    else
        outputChatBox("SYNTAX: /timer [minutes]")
    end
end)

function formatTime(ms)
    local totalseconds = math.floor(ms / 1000)
    local ms = ms % 1000
    local seconds = totalseconds % 60
    local minutes = math.floor(totalseconds / 60) % 60
    return string.format("%02d:%02d", minutes, seconds)
end

 

Edited by Keiichi1
  • Like 2
Link to comment
8 hours ago, Keiichi1 said:

Client:


local sx, sy = guiGetScreenSize()

function renderText()
    dxDrawText(timeText, sx/2, sy/2, 0, 0, tocolor(255, 255, 255), 2, "default-bold")
end

function updateTime()
    if isTimer(timer) then
        timeText = formatTime(getTimerDetails(timer))
    end
end

addCommandHandler("timer", function(cmd, min)
    if tonumber(min) then
        if not isTimer(timer) then
            local time = tonumber(min) * 60000
            timer = setTimer(function()
                removeEventHandler("onClientRender", getRootElement(), renderText)
            end, time, 1)
            setTimer(updateTime, 1000, 0)
            timeText = formatTime(getTimerDetails(timer))
            addEventHandler("onClientRender", getRootElement(), renderText)
        end
    else
        outputChatBox("SYNTAX: /timer [minutes]")
    end
end)

function formatTime(ms)
    local totalseconds = math.floor(ms / 1000)
    local ms = ms % 1000
    local seconds = totalseconds % 60
    local minutes = math.floor(totalseconds / 60) % 60
    return string.format("%02d:%02d", minutes, seconds)
end

 

thanks bro

Link to comment
  • Discord Moderators
function formatTime(ms)
    local totalseconds = math.floor(ms / 1000)
    return string.format("%.2i:%.2i", math.floor(totalseconds / 60) % 60, totalseconds % 60)
end

 

Edited by Pirulax
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...