JuniorMelo Posted August 12, 2013 Posted August 12, 2013 (edited) Hello I have a problem in this script/b] the time does not work Error 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 August 12, 2013 by Guest
JuniorMelo Posted August 12, 2013 Author Posted August 12, 2013 Where's "timeLeft" ? if isTimer(timer) then local timeLeft = math.ceil(getTimerDetails(timer) / 1000)
tosfera Posted August 12, 2013 Posted August 12, 2013 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
tosfera Posted August 12, 2013 Posted August 12, 2013 I'll give it a go. Whats the script supposed to do, start a timer when the resource starts and print it out to the screen?
golanu21 Posted August 12, 2013 Posted August 12, 2013 (edited) deleted Edited August 12, 2013 by Guest
tosfera Posted August 12, 2013 Posted August 12, 2013 Thats impossible, this wont be accepted; addEventHandler( "onClientResourceStart", getRootElement(), function timestart()
golanu21 Posted August 12, 2013 Posted August 12, 2013 Thats impossible, this wont be accepted; addEventHandler( "onClientResourceStart", getRootElement(), function timestart() holy.... I have not seen that.Thanx
JuniorMelo Posted August 12, 2013 Author Posted August 12, 2013 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 ) ????
golanu21 Posted August 12, 2013 Posted August 12, 2013 try it but i think is same with your first script
JuniorMelo Posted August 12, 2013 Author Posted August 12, 2013 try it but i think is same with your first script Yes no worked '--'
golanu21 Posted August 12, 2013 Posted August 12, 2013 wait, where is the function timestart for that ? addEventHandler("onClientRender", getRootElement(), timestart)
JuniorMelo Posted August 12, 2013 Author Posted August 12, 2013 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
golanu21 Posted August 12, 2013 Posted August 12, 2013 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)
tosfera Posted August 12, 2013 Posted August 12, 2013 Melo, explain me. What does the function has to do? You want to see your time left? Why in a GUI? Why dont you just create a label on your screen that keeps updating?
golanu21 Posted August 12, 2013 Posted August 12, 2013 Melo, explain me. What does the function has to do? You want to see your time left? Why in a GUI? Why dont you just create a label on your screen that keeps updating? +1, or a dxDrawText
JuniorMelo Posted August 12, 2013 Author Posted August 12, 2013 I can not put "dxDrawText" because I'm going to use the function guiGetVisible
golanu21 Posted August 12, 2013 Posted August 12, 2013 yea but you can dxDrawText, without create the gui window
tosfera Posted August 12, 2013 Posted August 12, 2013 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
JuniorMelo Posted August 12, 2013 Author Posted August 12, 2013 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 thank you
denny199 Posted August 13, 2013 Posted August 13, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now