Jump to content

How can ı reset the countdown ?


Recommended Posts

ı wrote something.everything works good.When the player goes to jail for the second time, time comes down and doesn't work.we can remove the jail time text with removeEventHandler when the player gets out of jail, but countdown is still working.and when the player goes to jail for the second time, a bug occurs in countdown.How can I restart the time as the player goes back to prison? I'm really stuck.can you help me please? thanks.

local start = getTickCount()
local countDown = 20
function render()
    local now = getTickCount()
    if now-start > 1000 then
        countDown = countDown-1
        start = getTickCount()
        if countDown < 1 then 
removeEventHandler("onClientRender",root,render) 
        end
    end
end 

function convertTime ( time ) 
    local min = math.floor ( time / 60 ) 
    local sec = ( time %60 )
    return string.format("%02d:%02d", min, sec) 
end 


addEvent ( "jailTime1", true )
addEventHandler ( "jailTime1", root,
	function ( )
	addEventHandler("onClientRender",root,render) 
	addEventHandler("onClientRender",root,jailText)
	       render()
		setTimer(function()
			removeEventHandler("onClientRender",root,jailText)
		end, 20000, 1)
	end
)
	
local screenW, screenH = guiGetScreenSize()
local refx,refy = 1920,1080

function jailText()
     dxDrawText("Time out of jail: "..convertTime(countDown).."",screenW*((refx/2+2)/refx),screenH*((refy/2+54)/refy),_,_, tocolor(0,0,0), screenH*(1.7/refy), "bankgothic", "center", "center", false, true, false, true, false)
	 dxDrawText("Time out of jail: "..convertTime(countDown).."",screenW*((refx/2)/refx),screenH*((refy/2+55)/refy),_,_, tocolor(200,200,200), screenH*(1.7/refy), "bankgothic", "center", "center", false, true, false, true, false)
     dxDrawText("Time out of jail: "..convertTime(countDown).."",screenW*((refx/2+2)/refx),screenH*((refy/2+94+2)/refy),_,_, tocolor(0,0,0), screenH*(0.9/refy), "bankgothic", "center", "center", false, true, false, true, false)
	 dxDrawText("Time out of jail: "..convertTime(countDown).."",screenW*((refx/2)/refx),screenH*((refy/2+95)/refy),_,_, tocolor(200,200,200), screenH*(0.9/refy), "bankgothic", "center", "center", false, true, false, true, false)
end

 

Link to comment

Hello SoManyTears,

in line 24 you have to...

addEvent ( "jailTime1", true )
addEventHandler ( "jailTime1", root,
  function ( )
    countDown = 20
    start = getTickCount()
    addEventHandler("onClientRender",root,render) 
    addEventHandler("onClientRender",root,jailText)
    render()
    setTimer(function()
        removeEventHandler("onClientRender",root,jailText)
      end, 20000, 1)
  end
)

... reset the timer variables countDown and start.

Other than that you could improve this script by starting a one-second timer for removing the jailText onClientRender event in line 9. Then the text would not be prematurely removed due to frame-time differences to the real clock. :) 

Edited by The_GTA
Link to comment
1 hour ago, SoManyTears said:

Hello The-Gta.Thanks for answer.ı dont know how to reset it. ı cant use resetTimer or killTimer for it.really ı have not any idea.ı am still stuck.

Have you replaced the "jailTime1" event handler with the code I posted? That is all that you have to do. :) 

  • Thanks 1
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...