Jump to content

vehicle respawn


orcun99

Recommended Posts

addEvent("respawnVehicle",true)
function respawnVehicleAdmin(player,sec)
    if tonumber(sec) then
            setTimer(function(player)
                local vehicles = getElementsByType("vehicle")
                for i,v in ipairs(vehicles) do
                        if not getVehicleOccupant(v,0) and not getVehicleOccupant(v,1) and not getVehicleOccupant(v,2) and not getVehicleOccupant(v,3) then
                            respawnVehicle (v)
                        end
                    end
                end,sec * 1000 , 1 ,player    )
    end
end
addEventHandler("respawnVehicle",getRootElement(),respawnVehicleAdmin)

 

this code is working but I wanna auto respawn in every 5min

some one can edit pls?

Link to comment

The event must be called every five minutes.

Or setTimer ()

 

function autoRespawn() --  changed the name because it was misleading
    local vehicles = getElementsByType("vehicle")
    for i,v in ipairs(vehicles) do
        if not getVehicleOccupant(v,0) and not getVehicleOccupant(v,1) and not getVehicleOccupant(v,2) and not getVehicleOccupant(v,3) then
            respawnVehicle (v)
        end
    end
end
setTimer(autoRespawn, 5000, 0) -- timer that runs every 5 mins all the time.

If you want to keep the admin function, you'll have to get it into this one or just leave the last one and add this.

@orcun99

Edited by Gourmet.
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...