API ReferenceGE Extensionsflowgraphnodesvehicle
On Vehicle Switched
- **Node Name:** `On Vehicle Switched`
Overview
- Node Name:
On Vehicle Switched - Category:
logic - File:
extensions/flowgraph/nodes/vehicle/onVehicleSwitched.lua
Triggers when the player switches to a different vehicle. Outputs the old vehicle ID, new vehicle ID, and player ID.
Pin Schema
Input Pins
| Pin | Type | Description |
|---|---|---|
flow | flow | Inflow for this node |
Output Pins
| Pin | Type | Description |
|---|---|---|
flow | flow (impulse) | Fires once when the player switches vehicles |
oldID | number | ID of the previous vehicle |
newID | number | ID of the new vehicle |
player | number (hidden) | ID of the player who switched |
Internals
Key Methods
| Method | Description |
|---|---|
init() | Empty initialization |
_executionStarted() | Resets flag and info table |
onVehicleSwitched(oid, nid, player) | Hook - stores old ID, new ID, and player ID; sets flag |
work() | If flag is set, outputs all three values and fires impulse, then clears flag |
_afterTrigger() | Clears the flag for single-frame impulse |
How It Works
- The node subscribes to the
onVehicleSwitchedhook. - When the player switches vehicles, the hook receives the old vehicle ID, new vehicle ID, and player index.
- On the next
work()tick, all three output pins are populated and the flow impulse fires. - The flag is cleared to ensure single-frame impulse behavior.
Usage Example
-- In a flowgraph - detect vehicle switch and update UI:
-- [On Vehicle Switched] → (newID) → [Get Vehicle Data] → [Update HUD]
-- → (oldID) → [Cleanup Old Vehicle]
-- The engine hook signature:
-- onVehicleSwitched(oldVehicleId, newVehicleId, playerId)Key Dependencies
onVehicleSwitchedengine hook - fires when the active player vehicle changes
See Also
- Align for Coupling (Flowgraph Node) - Related reference
- Apply Velocity to Vehicle (Flowgraph Node) - Related reference
- Boost Vehicle (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide