Jump to content

Problem about timer


jingzhi

Recommended Posts

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
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
  • 2 weeks later...

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...