API ReferenceGE Extensionsflowgraphnodesvehicleai
Get AI Mode
- **Node Name:** `Get AI Mode`
Overview
- Node Name:
Get AI Mode - Category:
repeat_p_duration - File:
extensions/flowgraph/nodes/vehicle/ai/getAIMode.lua
Queries the current AI mode of a vehicle. Returns the mode string (e.g. "disabled", "random", "traffic", "manual", "stop", "span").
Pin Schema
Input Pins
| Pin | Type | Description |
|---|---|---|
vehId | number | ID of the vehicle. If empty, uses the player vehicle. |
Output Pins
| Pin | Type | Description |
|---|---|---|
aiMode | string | The current AI mode on the vehicle. |
Internals
Key Methods
| Method | Description |
|---|---|
work() | Queues a Lua command on the vehicle to retrieve the AI state, then outputs the cached mode. |
_executionStarted() | Resets returnedMode to nil. |
getCmd() | Builds the cross-VM command string that queries ai.getState().mode on the vehicle and sends the result back to GE via queueGameEngineLua. |
getAIMode(mode) | Callback invoked from the vehicle VM - caches the mode string in self.returnedMode. |
How It Works
- Each frame,
work()sends a Lua command to the vehicle viaveh:queueLuaCommand(). - On the vehicle side,
ai.getState().modeis read and forwarded back to the GE node viaqueueGameEngineLua. - The GE-side callback
getAIMode(mode)stores the result inself.returnedMode. - On the next
work()call the cached mode is output on theaiModepin.
Note: Because of the cross-VM round-trip, the output lags by one frame.
Usage Example
-- In a flowgraph:
-- [Get AI Mode (vehId=myVeh)] → aiMode → [String Compare] → "random" → [Branch]
-- The underlying vehicle-side query is equivalent to:
local mode = ai.getState().mode -- returns e.g. "disabled", "random", "traffic"Key Dependencies
ai.getState()- vehicle-side AI state accessorcore_flowgraphManager.getManagerGraphNode()- resolves the node for the GE callback
See Also
- AI Parameters (Flowgraph Node) - Related reference
- AI Arrive (Flowgraph Node) - Related reference
- AI Chase (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide