MTA.Castiel Posted January 11, 2022 Share Posted January 11, 2022 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
The_GTA Posted January 12, 2022 Share Posted January 12, 2022 (edited) 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 January 12, 2022 by The_GTA 1 Link to comment
MTA.Castiel Posted January 12, 2022 Author Share Posted January 12, 2022 Ohh i see a killTimer, haven't seen that one coming. Well this works, thanks a lot The_GTA 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