Jump to content

[Help] i created a code to make cars undamagable and its not working


ZeaD22

Recommended Posts

Hello , i wanted to make cars undamagable from the world's objects (when the car jumps and land)

i created this

addEventHandler("onClientVehicleCollision",getRootElement(),function (theHitElement)
if theHitElement == nil then 
	setVehicleDamageProof (source, true)
end
else
setVehicleDamageProof (source, false)
)

its not working and i need to know how can i treat parameters with if and what should i use '==' or '=' or whaat ??

Link to comment

You have a two errors over there: not closing the function scope and using else when there is no if-scope to else (you shouldn't close the if-statement before the else).

So simply move the end after the else scope, and remember to end the function as well.

addEventHandler("onClientVehicleCollision",getRootElement(),
	-- function scope starts
	function (theHitElement)
		-- if-statement scope starts
		if theHitElement == nil then
			setVehicleDamageProof (source, true)
		else
			setVehicleDamageProof (source, false)
		end
		-- if-statement scope ends
	end
	-- function scope ends
)

You can also do the same thing with less code:

addEventHandler( "onClientVehicleCollision", root,
  function( theHitElement )
    setVehicleDamageProof( source, not theHitElement )
  end
)

Do note, that doing any of this will make the vehicle damage proof to any damage from the world at any given time. So it'll not only be protected from jump damage, but also crashing into light poles and buildings and so on. Just so you know.

Edited by myonlake
  • Like 1
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...