Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Introduced in

Version:1.70

Description

Description:

Acts as an event handler that runs, when the player exits or loses control of the vehicle they are in, when the function is called.

The function fires runs, when any of the following events happens:

  • Player exits vehicle.
  • Player or vehicle death / respawn / deletion.
  • Player team switch / drone use / and so on.
  • Player or vehicle is attached to another object.

The following events can optionally be added to the previous list (see the optionalEvents parameter):

  • "positionChanged" - Changing seat within the vehicle.
  • "switchCamera" - Camera is changed, using the switchCamera script command.
  • "map" - RTE / C2 map is opened.
  • Any Key Action (see VBS Key Actions).

If the player is on foot, the functions function runs when the player enters a vehicle. The event handler removes itself automatically, once it runs. For example, the function can be used to abort a special player-only effect script that is associated with a specific vehicle.

Syntax

Syntax:[player, code, data, optionalEvents] call fn_vbs_onPlayerVehicleChange
Parameters:
  • player: Object - The player to monitor for vehicle control.
  • code: Code - The code to run, when the player exits / loses control of the vehicle. The array _this is available in the code, and contains the following elements:
    • player: Object - The player.
    • vehicle: Object - The vehicle.
    • data: Array - Any extra data that is passed to the code (using the data argument).
  • data: Array - Data that can be passed to the code section.
  • optionalEvents: Array of String - Optional events that should trigger the event handler. The strings can be in any order.
Return Value:Number - The index used in the alternative syntax, to remove this event handler (-1 is returned, if no event handler is added).

Alternative Syntax

Syntax:eventIndex call fn_vbs_onPlayerVehicleChange
Parameters:
  • eventIndex : Number - Event index returned by the standard syntax, when declaring the function. Calling the function only with eventIndex removes the results of the last function call.

Note: Passing -1 removes all the added instances of this function. The function must be removed on the same client it was added on.

Return Value:

Number - Indicates whether the event was successfully removed. Can be either:

  • 1 if the event handler is successfully removed.
  • -1 if the event handler does not exist at the specified index.

Warning

When using functions in VBS versions older than 3.4, certain limitations and requirements should be kept in mind - the main ones being that capitalization of the function name is crucial, and that #include "\vbs2\headers\function_library.hpp" has to be included in every script that utilizes it. More Category VBS Scripting Functions.

Examples

Examples:
_index = [player, {hint "Change in status"}, []] call fn_vbs_onPlayerVehicleChange

Additional Information

See also: onVehicleCreated
Multiplayer: 
Problems: 

Notes