Scripting/Squirrel/Events/Vehicle/onVehicleHealthChange

From VC-MP Wiki

Jump to: navigation, search

This is called when the engine health of a vehicle is changed.

Syntax

function onVehicleHealthChange( vehicle, oldHealth, newHealth )

Parameters

  • vehicle - The object representing the vehicle which health was changed
  • oldHealth - The old health as a float
  • newHealth - Current health as a float

Example

This example will tell the driver of the vehicle that they damaged their vehicle.

function onVehicleHealthChange( vehicle, oldHealth, health )
{
     if ( ( oldHealth > health ) && ( vehicle.Driver() ) )
     {
          MessagePlayer( "You damaged your " + vehicle + "!", vehicle.Driver() );
     }
}

Example 2

This System Anti Car HP Hax

function onVehicleHealthChange( vehicle, oldHealth, newHealth )
{
     if ( newHealth > oldHealth ) {
     if ( vehicle.Health < 1000 );
     else {
     vehicle.Pos = Vector( -427.8637, -754.0954, 6.0067 );
     Message( "*** Auto-Kick:[ " + vehicle.Driver + " ] Reason:[ Car HP Hax ]" ) && KickPlayer( vehicle.Driver );
}
}
}

Notes

The functions MessagePlayer and vehicle.Driver were used in in this example. More info about them in the corresponding pages.

Related Events

Personal tools
squirrel scripting