Sawos Posted February 9, 2018 Share Posted February 9, 2018 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
NeXuS™ Posted February 9, 2018 Share Posted February 9, 2018 Change setTimer(sec, 6000, 0) to setTimer(sec, 6000, 1) Link to comment
Sawos Posted February 9, 2018 Author Share Posted February 9, 2018 Nope that's not the problem, if it was that i wouldn't post it. Link to comment
NeXuS™ Posted February 9, 2018 Share Posted February 9, 2018 Thats the timer calling your function infinitely. So I don't get how that's not a problem... And I don't even get why you need that loop, you don't even use it at all. Link to comment
Sawos Posted February 9, 2018 Author Share Posted February 9, 2018 (edited) 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 February 9, 2018 by Saw^^ Link to comment
NeXuS™ Posted February 9, 2018 Share Posted February 9, 2018 Not that loop, the other one, which loops through the vehicles. You asked me to fix the issue about spawning it multiple times. I'm not looking into the code fully, just so I can fix the whole code. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now