Jump to content

Help,the vehicle nobody then setTimer respawn ?


crazyde21

Recommended Posts

this is what you mean?

function respawnVehicles() 
     outputChatBox("#FFFF00*Reiniciando vehiculos vacios en 30 segundos*", root, 255, 255, 255, true)     
    outputChatBox("#0040FF*Empty vehicles will be respawned in 30 seconds*", root, 255, 255, 255, true) 
    setTimer(function () 
    local vehicles = getElementsByType ( "vehicle" ) 
    outputChatBox("#0EF629*Vehiculos vacios han sido reiniciados*", root, 255, 255, 255, true) 
    outputChatBox("#00ccFf*Empty Vehicles has been respawned*", root, 255, 255, 255, true) 
    for k, vehicle in ipairs ( vehicles ) do 
        if isEmpty( vehicle ) then 
            respawnVehicle ( vehicle ) 
        end 
    end 
    end, 30000, 1) 
end 
setTimer(respawnVehicles, 100000, 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
  • Moderators
this is what you mean?
function respawnVehicles() 
     outputChatBox("#FFFF00*Reiniciando vehiculos vacios en 30 segundos*", root, 255, 255, 255, true)     
    outputChatBox("#0040FF*Empty vehicles will be respawned in 30 seconds*", root, 255, 255, 255, true) 
    setTimer(function () 
    local vehicles = getElementsByType ( "vehicle" ) 
    outputChatBox("#0EF629*Vehiculos vacios han sido reiniciados*", root, 255, 255, 255, true) 
    outputChatBox("#00ccFf*Empty Vehicles has been respawned*", root, 255, 255, 255, true) 
    for k, vehicle in ipairs ( vehicles ) do 
        if isEmpty( vehicle ) then 
            respawnVehicle ( vehicle ) 
        end 
    end 
    end, 30000, 1) 
end 
setTimer(respawnVehicles, 100000, 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 

Not really, when the last player of a vehicle just left it, the timer should be created to respawn that vehicle if nobody has entered in it after 1 minute:

function isVehicleEmpty( vehicle ) 
    if not isElement( vehicle ) or getElementType( vehicle ) ~= "vehicle" then 
        return true 
    end 
  
    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 
  
local RESPAWN_TIME = 1 --Time in minutes 
  
function watchForEmptyVehicle() 
    for k, veh in ipairs (getElementsByType("vehicle")) do 
        local respawnTimer = getElementData(veh, "respawnTimer") 
        local isEmpty = isVehicleEmpty(veh) 
        if isEmpty and not respawnTimer then 
            local respawnTimer = setTimer(respawnVehicle, RESPAWN_TIME*60*1000, 1, veh) 
            setElementData(veh, "respawnTimer", respawnTimer) 
        elseif not isEmpty and respawnTimer then 
            killTimer(respawnTimer) 
            setElementData(veh, "respawnTimer", false) 
        end 
    end 
end 
setTimer(watchForEmptyVehicle, 5000, 0) 

(I didn't use the events onPlayerVehicle(Exit/Enter) because I didn't know what would return isVehicleEmpty if someone carjack partially (just kicking the driver out) or completly (really stole the car). So I used a setTimer)

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