Mefisto_PL Posted November 18, 2012 Share Posted November 18, 2012 I have a problem.. I want to make timer.. When I use the command then create a count which is higher and higher and higher and when I use another command then it's stopped. In my version of code it can't be stopped.. screenX,screenY = guiGetScreenSize() function startTheClock () if not systemUpTime then systemUpTime = getTickCount () --Store the system tick count, this will be 0 for us end currentCount = getTickCount () dxDrawRectangle (screenX *.40, screenY * .09, 250, 50, tocolor(0,0,0,150)) dxDrawText ( currentCount - systemUpTime, screenX * .48, screenY * .1, screenX, screenY, tocolor(255,255,255), 2) addEventHandler ( "onClientRender", root, startTheClock ) end addCommandHandler("clock", startTheClock) In debugscript is error that onClientRender is already handled, but when I remove this handler it doesn't create a timer.. pls help.. Link to comment
manve1 Posted November 18, 2012 Share Posted November 18, 2012 (edited) screenX,screenY = guiGetScreenSize() function startTheClock () if not systemUpTime then systemUpTime = getTickCount () end currentCount = getTickCount () addEventHandler ( "onClientRender", root, function() dxDrawRectangle (screenX *.40, screenY * .09, 250, 50, tocolor(0,0,0,150)) dxDrawText ( currentCount - systemUpTime, screenX * .48, screenY * .1, screenX, screenY, tocolor(255,255,255), 2) end ) end addCommandHandler("clock", startTheClock) startTheClock() Edited November 18, 2012 by Guest Link to comment
Mefisto_PL Posted November 18, 2012 Author Share Posted November 18, 2012 Count hasn't started and how in your I could stop this timer ? Link to comment
manve1 Posted November 18, 2012 Share Posted November 18, 2012 (edited) to stop timer use killTimer EDIT: There is nothing wrong, i think Btw, here is an example for stopping timer: timerDie = setTimer( function() outputChatBox( 'Trololo', 255, 0, 255 ) end, 5000, 1 ) function KillTheTimer() killTimer( timerDie ) end addCommandHandler('killThatTimer', KillTheTimer) Edited November 18, 2012 by Guest Link to comment
Mefisto_PL Posted November 18, 2012 Author Share Posted November 18, 2012 It doesn't help me sorry.. ( I KNOW HOW TO USE KILLTIMER ) Link to comment
manve1 Posted November 18, 2012 Share Posted November 18, 2012 I know this function but how I must use it in your code? Not sure how to make it .. because there isn't a proper set timer, with : setTimer Link to comment
myonlake Posted November 18, 2012 Share Posted November 18, 2012 (edited) I do not understand your code at all. It should always return a zero value because you're minusing it from tick count and another tick count. There's no sense at all. This is one example how to make a timer clock. /clock = toggle the clock ticking /display = toggle the clock display Client-side local screenX, screenY = guiGetScreenSize() local second = 0 local display = false addCommandHandler("clock", function() if isTimer(clocktimer) then killTimer(clocktimer) else clocktimer = setTimer(function() second = second+1 end, 1000, 0) end end ) addCommandHandler("display", function(cmd) if display then removeEventHandler("onClientRender", root, displayClock) else addEventHandler("onClientRender", root, displayClock) end end ) function displayClock() dxDrawRectangle(screenX * 0.40, screenY * 0.09, 250, 50, tocolor(0,0,0,150)) dxDrawText(second, screenX * 0.48, screenY * 0.1, screenX, screenY, tocolor(255,255,255), 2) end Edited November 18, 2012 by Guest Link to comment
Mefisto_PL Posted November 18, 2012 Author Share Posted November 18, 2012 (edited) Working perfectly ! Thanks ! ///EDIT Debugscript when I want to remove display: onClientRender is already handled Edited November 18, 2012 by Guest Link to comment
myonlake Posted November 18, 2012 Share Posted November 18, 2012 Forgot one thing. Client-side local screenX, screenY = guiGetScreenSize() local second = 0 local display = false addCommandHandler("clock", function() if isTimer(clocktimer) then killTimer(clocktimer) else clocktimer = setTimer(function() second = second+1 end, 1000, 0) end end ) addCommandHandler("display", function(cmd) if display then removeEventHandler("onClientRender", root, displayClock) display = false else addEventHandler("onClientRender", root, displayClock) display = true end end ) function displayClock() dxDrawRectangle(screenX * 0.40, screenY * 0.09, 250, 50, tocolor(0,0,0,150)) dxDrawText(second, screenX * 0.48, screenY * 0.1, screenX, screenY, tocolor(255,255,255), 2) end Link to comment
Mefisto_PL Posted November 18, 2012 Author Share Posted November 18, 2012 Ok working, but how can I restart this timer? Link to comment
abu5lf Posted November 18, 2012 Share Posted November 18, 2012 https://wiki.multitheftauto.com/wiki/ResetTimer Link to comment
myonlake Posted November 18, 2012 Share Posted November 18, 2012 /resetclock to reset the ticker. Client-side local screenX, screenY = guiGetScreenSize() local second = 0 local display = false addCommandHandler("clock", function() if isTimer(clocktimer) then killTimer(clocktimer) else clocktimer = setTimer(function() second = second+1 end, 1000, 0) end end ) addCommandHandler("resetclock", function() second = 0 end ) addCommandHandler("display", function(cmd) if display then removeEventHandler("onClientRender", root, displayClock) display = false else addEventHandler("onClientRender", root, displayClock) display = true end end ) function displayClock() dxDrawRectangle(screenX * 0.40, screenY * 0.09, 250, 50, tocolor(0,0,0,150)) dxDrawText(second, screenX * 0.48, screenY * 0.1, screenX, screenY, tocolor(255,255,255), 2) end Link to comment
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