Jump to content

respawn vehicles


orcun99

Recommended Posts

I'm using manuel respawn script but I need auto respawn vehicles

 

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
end
addCommandHandler("vh",respawnVehicleAdmin)
addEventHandler("respawnVehicle",getRootElement(),respawnVehicleAdmin)

 

 

 

 

 

I need every 5min auto respawn empty car

I'm using this resource : 

 

Edited by orcun99
Link to comment

You should make a timer using setTimer and then have that set to 1000 * 60 * 5 so it runs every 5 minutes.

In there you can basically just copy paste the code from the manual respawn script like so:

local vehicles = getElementsByType( "vehicle" )

for i, v in ipairs( vehicles ) do
	local _, occupant = next( getVehicleOccupants( v ) )

	if ( not occupant ) then
		respawnVehicle( v )
	end
end

 

Edited by myonlake
  • Like 1
Link to comment
4 hours ago, myonlake said:

You should make a timer using setTimer and then have that set to 1000 * 60 * 5 so it runs every 5 minutes.

In there you can basically just copy paste the code from the manual respawn script like so:


local vehicles = getElementsByType( "vehicle" )

for i, v in ipairs( vehicles ) do
	local _, occupant = next( getVehicleOccupants( v ) )

	if ( not occupant ) then
		respawnVehicle( v )
	end
end

 

okay I changed code but still don't work

 

don't like this?

 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
    local _, occupant = next( getVehicleOccupants( v ) )

    if ( not occupant ) then
        respawnVehicle( v )
    end
end
                end,sec * 1000 * 60 * 5 , 1 ,player    )
        --end
    end
end
addCommandHandler("vh",respawnVehicleAdmin)
addEventHandler("respawnVehicle",getRootElement(),respawnVehicleAdmin)

 

Edited by orcun99
Link to comment

No. You need to make a new timer. Completely separate from the other one.

addEventHandler( "onResourceStart", resourceRoot,
	function( )
		setTimer(
			function( ) 	-- Function to execute
			-- Put the code in here
			end,
			1000 * 60 * 5, 	-- Time in milliseconds (5 minutes)
			0 		-- Times to repeat (0 = forever)
		)
	end
)

 

Edited by myonlake
onResourceStart
  • Like 1
Link to comment
3 minutes ago, myonlake said:

No. You need to make a new timer. Completely separate from the other one.


setTimer(
	function( ) 	-- Function to execute
	-- Put the code in here
	end,
	1000 * 60 * 5, 	-- Time in milliseconds
	0 		-- Times to repeat
)

 

thank you very much bro works :)

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