Jump to content

if in car - car indestructable, leaves car - car des


Recommended Posts

You can do that in two ways.


The first way is the way you worded it - damage gets disabled or enabled when a player enters or exits the vehicle.

To do that, you need these events:

onPlayerVehicleEnter or onVehicleEnter - to detect when a player enters the vehicle

onPlayerVehicleExit or onVehicleExit - to detect when a player exits the vehicle

And this function to toggle the damage: setVehicleDamageProof

Also, it depends on whether it has to work just for the driver seat or all seats.

If you want it for the driver seat only, then you need to check if the seat parameter is 0 in vehicle enter/exit events.

If you want it for all seats, then in vehicle exit event you need to retrieve the list of players in the vehicle using getVehicleOccupants and check if it is empty - so the damage will only be enabled if there are no other players remaining in the vehicle.


The second way is to check every time the vehicle is damaged, and cancel the damage if it's occupied. This has to be done client-side because only client-side damage events can be cancelled.

You need this event to detect when the vehicle gets damaged: onClientVehicleDamage

And call this function from within that event to cancel the damage: cancelEvent

If you need it for the driver seat only, use getVehicleOccupant to check if there's a player in the seat 0.

For all seats, retrieve the list of players in the vehicle using getVehicleOccupants and check if it is non-empty.

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