ZeaD22 Posted January 14, 2017 Posted January 14, 2017 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 ??
myonlake Posted January 14, 2017 Posted January 14, 2017 (edited) 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 January 14, 2017 by myonlake 1 If I helped you, please click the like button on the right Thanks!
Moderators IIYAMA Posted January 18, 2017 Moderators Posted January 18, 2017 That event triggers probably too late. Use: https://wiki.multitheftauto.com/wiki/OnClientVehicleDamage cancelEvent() You should check if theAttacker can also be a vehicle. If there is no attacker > cancelEvent(). If there is an attacker > do nothing. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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