Jump to content

Resetting timer/s on player wasted


MTA.Castiel

Recommended Posts

So below is a working vehicle repair code i've managed to put together and repairs the damaged vehicle every minute as intended but i just cant seem to reset the timer when the player is wasted. If anyone has an idea, would be much appreciated ?

 

 

local repairDelayTime = 60000
local repairTimer = false

function repairVehicle()

        local vehicle = getPedOccupiedVehicle(localPlayer) 

        if isPedDead(localPlayer) and isPedInVehicle(localPlayer) then 
            return 
        end

        if isTimer(repairTimer) then
            local timeleft = math.ceil(getTimerDetails(repairTimer)/1000)
         
            if timeleft then
        local 2ndString = " second to repair."

        if timeleft > 1 then 2ndString = " seconds to repair." 
        end

        if isPedInVehicle(localPlayer) then
        outputChatBox("Time left: "..tostring(timeleft)..2ndString, 255, 255, 255, true)
        end
        return false
        end
        end

        local vehicle = getPedOccupiedVehicle(localPlayer)

        if vehicle then 

            server.fixVehicle(vehicle)
        outputChatBox("Vehicle fixed.", 255, 255, 255, true)

        repairTimer = setTimer( function() repairTimer = false end, repairDelayTime, 1)
    end
end
addCommandHandler('fix', repairVehicle)

 

--added this in attempt to reset the timer but doesnt really work

function resetTimer()

repairTimer = false

end

addEventHandler("onClientPlayerWasted", root, resetTimer)

Link to comment

Hello MTA.Castiel,

you are missing a call to killTimer inside of your custom "resetTimer" function to clean up the possibly running timer, like so...

function resetTimer()
    if (repairTimer) then
        killTimer(repairTimer)
        repairTimer = false
    end
end

Also, please refrain from overwriting official MTA functions with your own ones.

Edited by The_GTA
  • 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...