Jump to content

[HELP]Spawn Vehicle Issue


Sawos

Recommended Posts

Hello Community, i would like to have some support here, the code works fine on this script which once the Vehicle damage is below "350", it gets Destroyed in a couple of seconds and then once the script calls this :  

setTimer( sec, 6000, 0 )

It doesn't spawn a single Vehicle as i wish to, it Spawns an infinate  Vehicles on the same place. i just need help to make it spawn Only One. 

Here is the full code : 

function sec () 
 local car = createVehicle ( 428, 2317.0588378906,2408.1867675781,10.8203125) 
 setElementData(car,"sec",true)   
 setVehicleDamageProof(car,true)
end
addEventHandler("onResourceStart", resourceRoot,sec)

function checkDamage(player)
	for _,vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do
	if getElementData(source,"sec") then else return end
	if getElementHealth(source) > 350 then
        setVehicleDamageProof(source,false)
        setVehicleEngineState(source,true) 
		
    else
        setVehicleDamageProof(source,true)
        setVehicleEngineState(source,false) 
		for i,player in pairs(getVehicleOccupants(source)) do
            setControlState(souce,"enter_exit",true)
		--setTimer(respawnVehicle, 6000, 1, source) 
		  
		   
		---------------------------------------------  
		x, y, z = getElementPosition(source)		
		   setTimer ( function()
		 bag = createPickup( x-6, y, z, 3, 1550 )
		 setElementCollisionsEnabled( bag, false )
		 end, 4000, 1)

       --------------------------------------------
		
		setTimer( destroyElement, 1000, 1, source) 		
		--setTimer( destroyElement, 50, 1, source) 
		setTimer( sec, 6000, 0 )
		

	end
    end
end
end
addEventHandler("onVehicleDamage",getRootElement(),checkDamage)

 

Link to comment

Well, I tought you would give me a lesson, but i will. 

If you leave it to "source" It won't make the player exits, cause the source element refers to the Vehicle not the player so without using The Loop to get the players it won't work, same thing with the Vehicle Loop without it, it won't dected any of the Vehicles at all :  

for i,player in pairs(getVehicleOccupants(source)) do
            setControlState(player,"enter_exit",true)

and The issue was never from this Loop, cause without the loop the SetControlState won't be working plus even without both of them the issue still the same. i've posted this so people could help me with an "usefull" reply with Codes. Other than that, i don't need any pointless Reply. i see ppl farming replies with non sense help. 

Thanks :) 

Edited by Saw^^
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...