Jump to content

10min Round Length Timer


xXSurviverXx

Recommended Posts

Hey all i know how to make a timer but

i need the timer to display how much time is left on the screen

this is the code im using to display the time left in --:--

dxDrawText(tostring (timer),sWidth-0,sHeight-600,sWidth-347,sHeight-0,tocolor(225,225,225,1000),1.3,"Diploma","right","top",false,false,false) -- Timer 
  

Link to comment
function getTimeLeft(timer) 
  if isTimer(timer) then 
    local ms = getTimerDetails(timer) 
    local m = math.floor(ms/60000) 
    local s = math.floor((ms-m*60000)/1000) 
    if m < 10 then m = "0"..m end 
    if s < 10 then s = "0"..s end 
    return m..":"..s 
  else return "--:--" end 
end 

also "sWidth-0" is useless, max alpha is 255 (tocolor(225,225,225,255)) and font name is "diploma", not "Diploma" (though it maybe not case-sensitive)

Link to comment

i know ur trying to help, but this is like the first script im working on for mta and its hard

timer = setTimer(getTimeLeft,600000,1) 
function getTimeLeft(timer) 
    dxDrawText(getTimeLeft(timer),sWidth-0,sHeight-600,sWidth-347,sHeight-0,tocolor(225,225,225,1000),1.3,"Diploma","right","top",false,false,false) -- Timer 
if isTimer(timer) then 
local ms = getTimerDetails(timer) 
local m = math.floor(ms/60000) 
local s = math.floor((ms-m*60000)/1000) 
if m < 10 then m = "0"..m end 
if s < 10 then s = "0"..s end 
return m..":"..s 
else return "--:--" end 
end 
  

and if you cant help with that, i have TeamViewer ill pm you the id and pass

Link to comment

oh my god

timer = setTimer(outputChatBox, 600000, 1, "Time's up!") 
  
function getTimeLeft(timer) 
  if isTimer(timer) then 
    local ms = getTimerDetails(timer) 
    local m = math.floor(ms/60000) 
    local s = math.floor((ms-m*60000)/1000) 
    if m < 10 then m = "0"..m end 
    if s < 10 then s = "0"..s end 
    return m..":"..s 
  else return "--:--" end 
end   
  
addEventHandler("onClientRender", getRootElement(),  
function() 
  dxDrawText(getTimeLeft(timer),sWidth-0,sHeight-600,sWidth-347,sHeight-0,tocolor(225,225,225,255),1.3,"diploma","right","top",false,false,false) -- Timer 
end) 

Link to comment

well then you need to make main timer server-side, and on client join send to him the time that's left, and start his timer for dx display with that value.

server:

timer = setTimer(function() 
  -- something to do when timer stops maybe 
end, 600000, 1) 
  
addEvent("requestTimeLeft", true)  
addEventHandler("requestTimeLeft", getRootElement(),  
function() 
  local ms = 0 
  if isTimer(timer) then  
    ms = getTimerDetails(timer)  
  end  
  triggerClientEvent(source, "serverStartsTimer", getRootElement(), ms)   
end) 

client:

timer = false 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),  
function() 
  triggerServerEvent("requestTimeLeft", getLocalPlayer()) -- asking the server how much time left on client resource start 
end) 
  
addEvent("serverStartsTimer", true) 
addEventHandler("serverStartsTimer", getRootElement(), -- reply from the server with time left 
function(ms) 
  timer = setTimer(outputChatBox, ms, 1, "Time's up!") -- setting the timer with time we got from server 
end) 
  
function getTimeLeft(timer) 
  if isTimer(timer) then 
    local ms = getTimerDetails(timer) 
    local m = math.floor(ms/60000) 
    local s = math.floor((ms-m*60000)/1000) 
    if m < 10 then m = "0"..m end 
    if s < 10 then s = "0"..s end 
    return m..":"..s 
  else return "--:--" end 
end   
  
addEventHandler("onClientRender", getRootElement(), 
function() 
  if timer then  -- to check if timer started 
    dxDrawText(getTimeLeft(timer),sWidth-0,sHeight-600,sWidth-347,sHeight-0,tocolor(225,225,225,255),1.3,"diploma","right","top",false,false,false) -- Timer 
  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...