Jump to content

Problem Timeleft


JuniorMelo

Recommended Posts

Hello

I have a problem in this script/b]

the time does not work :shock:

Error

gtp.png

addEventHandler( "onClientResourceStart", getRootElement(), 
function() 
     addEventHandler("onClientRender", getRootElement(), timestart) 
     if isTimer(timer) then killTimer(timer) end 
     timer = setTimer(function() 
          removeEventHandler("onClientRender", getRootElement(), timestart) 
     end,1000000,1) 
end) 
  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
  
GUIEditor_Window[1] = guiCreateWindow(0.2537,0.13,0.42,0.715,"Panel Test",true) 
guiSetAlpha(GUIEditor_Window[1],1) 
y = guiCreateLabel(25,33,307,30,"Time:",false,GUIEditor_Window[1]) 
guiLabelSetColor(y,0,255,0) 
guiSetText ( y, (tostring(convertMS(timeLeft)) or 'BUG')) 
function timestart() 
if isTimer(timer) then 
  local timeLeft = math.ceil(getTimerDetails(timer) / 1000) 
if guiGetVisible(GUIEditor_Window[1],true) then 
else 
   guiSetText(y,"Time :"..(tostring(convertMS(timeLeft)) or 'BUG')) 
          end 
    end 
end 
  
function convertMS( timeMs ) 
  
    local minutes   = math.floor( timeMs / 60 ) 
    local timeMs    = timeMs - minutes * 60; 
  
    local seconds   = math.floor( timeMs / 60 ) 
    local ms        = timeMs - seconds * 60; 
  
    return string.format( '%02d :%3d', minutes, ms ); 
end 
  
  

Edited by Guest
Link to comment

remove the Local from local timeLeft.

try this;

addEventHandler( "onClientResourceStart", getRootElement(getThisResource()), 
function() 
    addEventHandler("onClientRender", getRootElement(), timestart) 
    if isTimer(timer) then killTimer(timer) end 
        timer = setTimer(function() 
                            removeEventHandler("onClientRender", getRootElement(), timestart) 
                        end,1000000,1) 
end) 
  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
  
GUIEditor_Window[1] = guiCreateWindow(0.2537,0.13,0.42,0.715,"Panel Test",true) 
guiSetAlpha(GUIEditor_Window[1],1) 
y = guiCreateLabel(25,33,307,30,"Time:",false,GUIEditor_Window[1]) 
guiLabelSetColor(y,0,255,0) 
guiSetText ( y, (tostring(convertMS(timeLeft)) or 'BUG')) 
function timestart() 
    if isTimer(timer) then 
        timeLeft = math.ceil(getTimerDetails(timer) / 1000) 
    if not guiGetVisible(GUIEditor_Window[1],true) then 
       guiSetText(y,"Time :"..(tostring(convertMS(timeLeft)) or 'BUG')) 
    end 
    end 
end 
  
function convertMS( timeMs ) 
  
    local minutes   = math.floor( timeMs / 60 ) 
    local timeMs    = timeMs - minutes * 60; 
  
    local seconds   = math.floor( timeMs / 60 ) 
    local ms        = timeMs - seconds * 60; 
  
    return string.format( '%02d :%3d', minutes, ms ); 
end 
  

Link to comment
function timestart() 
     addEventHandler("onClientRender", getRootElement(), timestart) 
     if isTimer(timer) then killTimer(timer) end 
     timer = setTimer(function() 
          removeEventHandler("onClientRender", getRootElement(), timestart) 
     end,1000000,1) 
end 
addEventHandler( "onClientResourceStart", getRootElement(), timestart ) 

????

Link to comment
wait, where is the function timestart for that ? addEventHandler("onClientRender", getRootElement(), timestart)
function timestart() 
    if isTimer(timer) then 
        timeLeft = math.ceil(getTimerDetails(timer) / 1000) 
    if not guiGetVisible(GUIEditor_Window[1],true) then 
       guiSetText(y,"Time :"..(tostring(convertMS(timeLeft)) or 'BUG')) 
    end 
    end 
end 

Link to comment
  
  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
  
GUIEditor_Window[1] = guiCreateWindow(0.2537,0.13,0.42,0.715,"Panel Test",true) 
guiSetAlpha(GUIEditor_Window[1],1) 
y = guiCreateLabel(25,33,307,30,"Time:",false,GUIEditor_Window[1]) 
guiLabelSetColor(y,0,255,0) 
guiSetText ( y, (tostring(convertMS(timeLeft)) or 'BUG')) 
end 
  
function convertMS( timeMs ) 
  
    local minutes   = math.floor( timeMs / 60 ) 
    local timeMs    = timeMs - minutes * 60; 
  
    local seconds   = math.floor( timeMs / 60 ) 
    local ms        = timeMs - seconds * 60; 
  
    return string.format( '%02d :%3d', minutes, ms ); 
end 
  
function timestart() 
    if isTimer(timer) then 
        timeLeft = math.ceil(getTimerDetails(timer) / 1000) 
    end 
    if not guiGetVisible(GUIEditor_Window[1],true) then 
       guiSetText(y,"Time :"..(tostring(convertMS(timeLeft)) or 'BUG')) 
    end 
    end 
  
addEventHandler( "onClientResourceStart", getRootElement(getThisResource()), 
function() 
    addEventHandler("onClientRender", getRootElement(), timestart) 
    if isTimer(timer) then killTimer(timer) end 
        timer = setTimer(function() 
                            removeEventHandler("onClientRender", getRootElement(), timestart) 
                        end,1000000,1) 
end) 
  

Link to comment

just try this, is this what you want?

addEventHandler( "onClientResourceStart", getRootElement(), 
function() 
     addEventHandler("onClientPreRender", getRootElement(), timestart) 
     if isTimer(timer) then killTimer(timer) end 
     timer = setTimer(function() 
          removeEventHandler("onClientPreRender", getRootElement(), timestart) 
     end,1000000,1) 
end) 
  
function timestart() 
    guiSetText(label, "Time: "); 
    label = guiCreateLabel(0.0, 0.95, 0.1, 0.1, "Time: ".. convertMS(math.ceil(getTimerDetails(timer) / 1000)), true); 
end 
  
  
function convertMS( timeMs ) 
  
    local minutes   = math.floor( timeMs / 60 ) 
    local timeMs    = timeMs - minutes * 60; 
  
    local seconds   = math.floor( timeMs / 60 ) 
    local ms        = timeMs - seconds * 60; 
  
    return string.format( '%02d :%3d', minutes, ms ); 
end 

Link to comment
just try this, is this what you want?
addEventHandler( "onClientResourceStart", getRootElement(), 
function() 
     addEventHandler("onClientPreRender", getRootElement(), timestart) 
     if isTimer(timer) then killTimer(timer) end 
     timer = setTimer(function() 
          removeEventHandler("onClientPreRender", getRootElement(), timestart) 
     end,1000000,1) 
end) 
  
function timestart() 
    guiSetText(label, "Time: "); 
    label = guiCreateLabel(0.0, 0.95, 0.1, 0.1, "Time: ".. convertMS(math.ceil(getTimerDetails(timer) / 1000)), true); 
end 
  
  
function convertMS( timeMs ) 
  
    local minutes   = math.floor( timeMs / 60 ) 
    local timeMs    = timeMs - minutes * 60; 
  
    local seconds   = math.floor( timeMs / 60 ) 
    local ms        = timeMs - seconds * 60; 
  
    return string.format( '%02d :%3d', minutes, ms ); 
end 

Yes :mrgreen::mrgreen::mrgreen::mrgreen:

thank you :D

Link to comment
just try this, is this what you want?
addEventHandler( "onClientResourceStart", getRootElement(), 
function() 
     addEventHandler("onClientPreRender", getRootElement(), timestart) 
     if isTimer(timer) then killTimer(timer) end 
     timer = setTimer(function() 
          removeEventHandler("onClientPreRender", getRootElement(), timestart) 
     end,1000000,1) 
end) 
  
function timestart() 
    guiSetText(label, "Time: "); 
    label = guiCreateLabel(0.0, 0.95, 0.1, 0.1, "Time: ".. convertMS(math.ceil(getTimerDetails(timer) / 1000)), true); 
end 
  
  
function convertMS( timeMs ) 
  
    local minutes   = math.floor( timeMs / 60 ) 
    local timeMs    = timeMs - minutes * 60; 
  
    local seconds   = math.floor( timeMs / 60 ) 
    local ms        = timeMs - seconds * 60; 
  
    return string.format( '%02d :%3d', minutes, ms ); 
end 

This is wrong.

You are creating every frame a label...

Use this:

addEventHandler( "onClientResourceStart", getRootElement(), 
function() 
 label = guiCreateLabel(0.0, 0.95, 0.1, 0.1, "Time: ", true); 
     addEventHandler("onClientRender", getRootElement(), timestart) 
     if isTimer(timer) then killTimer(timer) end 
     timer = setTimer(function() 
          removeEventHandler("onClientRender", getRootElement(), timestart) 
     end,1000000,1) 
end) 
  
function timestart() 
    guiSetText(label, "Time: " ..convertMS(math.ceil(getTimerDetails(timer) / 1000)) ) 
end 
  
  
function convertMS( timeMs ) 
  
    local minutes   = math.floor( timeMs / 60 ) 
    local timeMs    = timeMs - minutes * 60; 
  
    local seconds   = math.floor( timeMs / 60 ) 
    local ms        = timeMs - seconds * 60; 
  
    return string.format( '%02d :%3d', minutes, ms ); 
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...