Jump to content

function ()


Klesh

Recommended Posts

Hello, how i can set every time a function, for example i have a respawn vehicle script but i want to set it every 1 hour by itselft, setTimer dont work for it, added

  
addEventHandler("onResourceStart", getRootElement(getThisResource()),respawnVehicles) 
setTimer(1800000, 1, respawnVehicles) 

No works, only works when the resource starts.

Any recomendation?

Link to comment
local rElement = getRootElement() 
      
    function respawnVehicles(player) 
        outputChatBox("*In 60 seconds the system will returns the empty vehicles to the start.", rElement, 0, 220, 20, true) 
        setTimer(function (player) 
        local vehicles = getElementsByType ( "vehicle" ) 
        outputChatBox("*Empty Vehicles has been respawned.", rElement, 0, 220, 20, true) 
        outputDebugString(getPlayerName(player) .. " respawned vehicles.") 
        for k, vehicle in ipairs ( vehicles ) do 
            if isEmpty( vehicle ) then 
                    respawnVehicle ( vehicle ) 
                end 
            end 
        end,180000, 0) 
    end 
    addEventHandler("onResourceStart", getRootElement(getThisResource()), respawnVehicles) 
      
    function isEmpty( vehicle ) 
        local passengers = getVehicleMaxPassengers( vehicle ) 
        if type( passengers ) == 'number' then 
            for seat = 0, passengers do 
                if getVehicleOccupant( vehicle, seat ) then 
                    return false 
                end 
            end 
        end 
        return true 
    end 

Why dont work.

Link to comment
function respawnVehicles() 
    local vehicles = getElementsByType ( "vehicle" ) 
    outputChatBox("*Empty Vehicles has been respawned.", root, 0, 220, 20, true) 
    for k, vehicle in ipairs ( vehicles ) do 
        if isEmpty( vehicle ) then 
            respawnVehicle ( vehicle ) 
        end 
    end 
end 
setTimer(respawnVehicles, 180000, 0) 
  
function isEmpty( vehicle ) 
    local passengers = getVehicleMaxPassengers( vehicle ) 
    if (type( passengers ) == 'number') then 
        for seat = 0, passengers do 
            if getVehicleOccupant( vehicle, seat ) then 
                return false 
            end 
        end 
    end 
    return true 
end 

Link to comment

I meant this:

function respawnVehicles() 
    outputChatBox("*Empty vehicles will be respawned in 10 seconds.", root, 255, 255, 0) 
    setTimer(function () 
    local vehicles = getElementsByType ( "vehicle" ) 
    outputChatBox("*Empty Vehicles has been respawned.", root, 0, 220, 20, true) 
    for k, vehicle in ipairs ( vehicles ) do 
        if isEmpty( vehicle ) then 
            respawnVehicle ( vehicle ) 
        end 
    end 
    end, 10000, 1) 
end 
setTimer(respawnVehicles, 180000, 0) 
  
function isEmpty( vehicle ) 
    local passengers = getVehicleMaxPassengers( vehicle ) 
    if (type( passengers ) == 'number') then 
        for seat = 0, passengers do 
            if getVehicleOccupant( vehicle, seat ) then 
                return false 
            end 
        end 
    end 
    return true 
end 

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