jingzhi Posted March 31, 2015 Share Posted March 31, 2015 addEvent("buttonpressed",true) addEventHandler("buttonpressed",root, function(timerepair,occupiedmarker) repairtime = timerepair brokenveh = getElementData(occupiedmarker,"occupiedby") currenthealth = getElementHealth(brokenveh) keycheck = setTimer(check,60,0) usingmarker = occupiedmarker end ) function check() if getKeyState("1") == true then killTimer(keycheck) addEventHandler("onClientRender",getRootElement(),drawprogress) timepast = 0 elseif getKeyState("2") == true then killTimer(keycheck) setElementFrozen(localPlayer,false) end end function drawprogress() countdowntimer = setTimer(countdown,1000,0) colorchangetimer = setTimer(colorchange,100,0) local progress = math.floor((timepast / repairtime) * 500) dxDrawProgressBar(startpointx,startpointy,800,100,progress,tocolor(colorr,colorg,0),tocolor(160,160,160)) end function countdown() if timepast <= repairtime then timepast = timepast + 1 else finishrepair() end end function colorchange() colordiff = math.floor((255 / repairtime) / 2) colorr = 255 - colordiff colorg = 0 + colordiff end function finishrepair() killTimer(countdowntimer) killTimer(colorchangetimer) fixVehicle(brokenveh) removeEventHandler("onClientRender",root,drawprogress) setElementFrozen(localPlayer,false) setElementFrozen(brokenveh,false) setElementData(usingmarker,"availiable",true) setElementAlpha(usingmarker,0) setElementData(brokenveh,"repairedstatus",true) setElementData(brokenveh,"repairer",localPlayer) outputChatBox("Drive this vehicle to the original deliver point",255,255,0) end Hey guys I made this script, but there is some problem, when its running killTimer, it doesnt kill the timer and debugscript says "bad argument "killTimer" expected lua-timer element at argument 1" please help! thank you! Link to comment
jingzhi Posted March 31, 2015 Author Share Posted March 31, 2015 Use isTimer Can you please explain more? I didnt really understand Link to comment
JR10 Posted March 31, 2015 Share Posted March 31, 2015 When a timer is done it destroys itself, so killTimer ends spitting out errors. isTimer checks if a timer is still valid. Link to comment
jingzhi Posted April 1, 2015 Author Share Posted April 1, 2015 When a timer is done it destroys itself, so killTimer ends spitting out errors. isTimer checks if a timer is still valid. I see, thank you, but this timer is infinite, i must destroy it? Link to comment
jingzhi Posted April 1, 2015 Author Share Posted April 1, 2015 When a timer is done it destroys itself, so killTimer ends spitting out errors. isTimer checks if a timer is still valid. function(timerepair,occupiedmarker) repairtime = timerepair brokenveh = getElementData(occupiedmarker,"occupiedby") currenthealth = getElementHealth(brokenveh) keycheck = setTimer(check,60,0) usingmarker = occupiedmarker end ) function check() if getKeyState("1") == true then killTimer(keycheck) addEventHandler("onClientRender",getRootElement(),drawprogress) timepast = 0 elseif getKeyState("2") == true then killTimer(keycheck) setElementFrozen(localPlayer,false) end end function drawprogress() countdowntimer = setTimer(countdown,1000,0) colorchangetimer = setTimer(colorchange,100,0) local progress = math.floor((timepast / repairtime) * 500) dxDrawProgressBar(startpointx,startpointy,800,100,progress,tocolor(colorr,colorg,0),tocolor(160,160,160)) end function countdown() if timepast <= repairtime then timepast = timepast + 1 else finishrepair() end end function colorchange() colordiff = math.floor((255 / repairtime) / 2) colorr = 255 - colordiff colorg = 0 + colordiff end function finishrepair() if isTimer(countdowntimer) then killTimer(countdowntimer) end if isTimer(colorchangetimer) then killTimer(colorchangetimer) end fixVehicle(brokenveh) removeEventHandler("onClientRender",root,drawprogress) setElementFrozen(localPlayer,false) setElementFrozen(brokenveh,false) setElementData(usingmarker,"availiable",true) setElementAlpha(usingmarker,0) setElementData(brokenveh,"repairedstatus",true) setElementData(brokenveh,"repairer",localPlayer) outputChatBox("Drive this vehicle to the original deliver point",255,255,0) end I changed the script to this, but the timer doesnt stop, its keeps going non stop Link to comment
JR10 Posted April 1, 2015 Share Posted April 1, 2015 That's because you're setting the timer on each render. You only need to set it once. Move both timers somewhere else. Link to comment
jingzhi Posted April 14, 2015 Author Share Posted April 14, 2015 That's because you're setting the timer on each render. You only need to set it once. Move both timers somewhere else. Thank you, problem solved 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