Jump to content

Set delay


Lordkrypton

Recommended Posts

You can do it with getTickCount()

Example:

local repairDelay = 30000 -- 30 seconds delay (in ms) 
local delayTick = false 
function repairFunction() 
    -- Check when the last repair was 
    if getTickCount() - delayTick < repairDelay then return end -- If it's less then repairDelay ms ago then abort 
    -- repair code 
     
    --set tick when repair happened 
    delayTick = getTickCount() 
end 

Not tested, but you get the point.

  • Like 2
Link to comment

Kariiim, it's for this function, in freeroam gameplay :

---------------------------

-- Repair vehicle

---------------------------

function repairVehicle()

local vehicle = getPedOccupiedVehicle(g_Me)

if vehicle then

server.fixVehicle(vehicle)

end

end

addCommandHandler('repair', repairVehicle)

addCommandHandler('rp', repairVehicle)

AfuSensi, thank you, i still try to add it, but i have bug.

Link to comment
Kariiim, it's for this function, in freeroam gameplay :

---------------------------

-- Repair vehicle

---------------------------

function repairVehicle()

local vehicle = getPedOccupiedVehicle(g_Me)

if vehicle then

server.fixVehicle(vehicle)

end

end

addCommandHandler('repair', repairVehicle)

addCommandHandler('rp', repairVehicle)

AfuSensi, thank you, i still try to add it, but i have bug.

(not tested)

I used timers this time, but same can be applied with getTickCount()

--------------------------- 
-- Repair vehicle 
--------------------------- 
local repairDelayTime = 30000 -- delay time in ms 
local repairTimer = false 
function repairVehicle() 
    if isTimer(repairTimer) then 
        local timeleft = math.ceil( getTimerDetails(repairTimer)/1000 ) -- Get seconds left from timer 
         
        if timeleft then 
            local secondString = " second" 
            if timeleft > 1 then secondString = " seconds" end 
  
            outputChatBox("Repair failed! Repair is possible again in "..tostring(timeleft)..secondString) 
            return false 
        end 
    end 
    local vehicle = getPedOccupiedVehicle(g_Me) 
    if vehicle then 
        server.fixVehicle(vehicle) 
        repairDelayTime = setTimer(function() repairTimer = false end,repairDelayTime,1) 
    end 
end 
addCommandHandler('repair', repairVehicle) 
addCommandHandler('rp', repairVehicle) 

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