Jump to content

Counting.. Need help.


Panda

Recommended Posts

Hello Everyone,

i tried to make something, i mean the car spawn after 10 secs when i press on the button! I don't what to do to make it count from 10 to 0 Look what i did! I need help :/ Thanks.

function drawDisplay() 
            local message = "Your car will be spawned in"..tonumber(10).." seconds." 
            dxDrawText(message,2,2,resX + 2,102,tocolor(255,255,255,255),2,"default-bold","center","center",true,true,false) 
            dxDrawText(message,0,0,resX,100,tocolor(255,255,255,200),2,"default-bold","center","center",true,true,false) 
end 
  
function startDisplay(jTime) 
    addEventHandler("onClientRender",root,drawDisplay) 
end 
addEvent("hii",true) 
addEventHandler("hii", localPlayer, startDisplay) 

Link to comment

I still don't get it.. i tried it but it doesn't work.

I'm sure that there is a way to count from 10 to 0.

local message = "Your car will be spawned in"..tonumber(10).." seconds." 

:/

Well if there is not, can u help with the "getTimerDetails" ? :/ Thanks mate.

Link to comment

This is how i would do it (not tested by the way, but hopefully you'll get the general idea):

function drawDisplay() 
    if isTimer(theTimer) then -- Check if timer is running to prevent errors 
        local timeLeft = mstoSec(getTimerDetails(theTimer)) -- Get ms from timer and convert to seconds 
  
        local message = "Your car will be spawned in"..tostring(timeLeft).." seconds." 
        dxDrawText(message, ,2,2,resX + 2,102,tocolor(255,255,255,255),2,"default-bold","center","center",true,true,false) 
        dxDrawText(message, 0,0,resX,100,tocolor(255,255,255,200),2,"default-bold","center","center",true,true,false) 
    end 
end 
addEventHandler("onClientRender",root,drawDisplay) 
  
function startDisplay(jTime) 
    theTimer = setTimer(function() -- Set the timer 
        -- Write what timer has to execute here, or to a named function 
        end 
        ,10000,1) 
end 
addEvent("hii",true) 
addEventHandler("hii", localPlayer, startDisplay) 
  
function mstoSec(ms) 
    local ms = ms/1000 
    if string.find(tostring(ms),"%.") then 
        local seconds = string.match(tostring(ms),"%d+") 
        return seconds 
    else 
        return ms 
    end 
end 

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...