Vehicle

This page describes the vehicle API

Get vehicles

vehicleList()

Retrieves all online vehicle IDs.

Details
Example

Remarks

Arguments

Type

Description

Returns

Vehicle IDs collection.

// TODO

Spawn

vehicleSpawn(string, vec3, float)

Spawns the vehicle at a specified position and heading direction.

Details
Example

Remarks

You can use the following listing for vehicle model names.

Arguments

Type

Description

string

Model name

vec3

Position

float

Heading direction

Returns

Vehicle ID if spawned, -1 if failed.

oak.cmd('car', async (pid, model) {
const m = parseInt(model)
if (m === NaN) {
return oak.chatSend(pid, "[error] provided argument should be a valid number")
}
oak.chatSend(pid, "[info] spawning vehicle model ${vehicleModels[m][0]}")
let pos = await oak.playerPositionGet(pid)
let heading = await oak.playerHeadingGet(pid)
if (adjustPos === true) {
let dir = await oak.playerDirectionGet(pid)
pos = pos.map((p, i) => p + dir[i] * 1.5)
heading -= 90.0
}
oak.vehicleSpawn(vehicleModels[m][1], pos, heading)
})

Despawn

vehicleDespawn(vehicle)

Despawns a vehicle

Details
Example

Remarks

Arguments

Type

Description

vehicle

Vehicle ID

Returns

0 if successful, -1 if failed.

// TODO

Invalid

vehicleInvalid(vehicle)

Checkes whether the vehicle ID is invalid.

Details
Example

Remarks

Arguments

Type

Description

vehicle

Vehicle ID

Returns

1 if invalid, 0 if valid otherwise.

// TODO

Repair

vehicleRepair(vehicle)

Repairs the vehicle.

Details
Example

Remarks

Arguments

Type

Description

vehicle

Vehicle ID

Returns

0 if successful, -1 if failed.

// TODO

Set position

vehiclePositionSet(vehicle, vec3)

Sets the vehicle position.

Details
Example

Remarks

Arguments

Type

Description

vehicle

Vehicle ID

vec3

Vehicle Position

Returns

0 if successful, -1 if failed.

// TODO

Set direction

vehicleDirectionSet(vehicle, vec3)

Sets the vehicle forward direction vector.

Details
Example

Remarks

Arguments

Type

Description

vehicle

Vehicle ID

vec3

Vehicle Direction

Returns

0 if successful, -1 if failed.

// TODO

Set heading

vehicleHeadingSet(vehicle, float)

Sets the vehicle heading angle.

Details
Example

Remarks

Uses a ±180 degree format.

Arguments

Type

Description

vehicle

Vehicle ID

float

±180 degree angle

Returns

0 if successful, -1 if failed

// TODO

Set fuel

vehicleFuelSet(vehicle, float)

Set vehicle fuel level

Details
Example

Remarks

Arguments

Type

Description

vehicle

Vehicle ID

float

Fuel level

Returns

0 if successful, -1 if failed

// TODO

Set transparency

vehicleTransparencySet(vehicle, float)

Set vehicle transparency value

Details
Example

Remarks

0-1 range.

Arguments

Type

Description

vehicle

Vehicle ID

float

transparency value

Returns

0 if successful, -1 if failed

// TODO

Set lock

vehicleLockSet(vehicle, int)

Locks/Unlocks the vehicle

Details
Example

Remarks

0 for unlock, 1 for lock.

Arguments

Type

Description

vehicle

Vehicle ID

int

Lock State

Returns

0 if successful, -1 if failed

oak.cmd('lock', async (pid, state) => {
const veh = await oak.vehiclePlayerInside(pid)
if (await oak.vehicleInvalid(veh)) return;
state = parseInt(state)
stateMsg = (state === 0) ? "unlocked" : "locked"
oak.chatSend(pid, `Vehicle is now ${stateMsg}!`)
oak.vehicleLockSet(veh, state)
})

Get position

vehiclePositionGet(vehicle)

Gets the vehicle position.

Details
Example

Remarks

Arguments

Type

Description

vehicle

Vehicle ID

Returns

Returns vehicle position

// TODO

Get direction

vehicleDirectionGet(vehicle)

Gets the vehicle direction.

Details
Example

Remarks

Arguments

Type

Description

vehicle

Vehicle ID

Returns

Returns vehicle direction

// TODO

Get heading

vehicleHeadingGet(vehicle)

Retrieves the vehicle's heading angle.

Details
Example

Remarks

Uses a ±180 degree format.

Arguments

Type

Description

vehicle

Vehicle ID

Returns

float heading angle

// TODO

Get fuel

vehicleFuelGet(vehicle)

Retrieves the vehicle's fuel level.

Details
Example

Remarks

Arguments

Type

Description

vehicle

Vehicle ID

Returns

float fuel level

// TODO

Get transparency

vehicleTransparencyGet(vehicle)

Retrieves the vehicle's transparency value.

Details
Example

Remarks

0-1 range.

Arguments

Type

Description

vehicle

Vehicle ID

Returns

float transparency value

// TODO

Get lock

vehicleLockGet(vehicle)

Retrieves the vehicle's lock state.

Details
Example

Remarks

0 for unlocked, 1 for locked.

Arguments

Type

Description

vehicle

Vehicle ID

Returns

int lock state

// TODO

Visibility

There are several visibility options you can set for the vehicle:

Name

Description

VISIBILITY_ICON

Vehicle's blip visibility on the map

VISIBILITY_RADAR

Vehicle's marker visibility on the radar

VISIBILITY_COLLISION

Vehicle's collision state

VISIBILITY_MODEL

Vehicle's transparency state

Get visibility

vehicleVisibilityGet(vehicle, visibility_type)

Retrieves the current vehicle's visibility.

Details
Example

Remarks

None.

Arguments

Type

Description

vehicle

Vehicle ID

visibility_type

Visibility option

Returns

int vehicle visibility option value

// TODO

Set visibility

vehicleVisibilitySet(vehicle, visibility_type, int)

Sets the current vehicle's visibility setting.

Details
Example

Remarks

None.

Arguments

Type

Description

vehicle

Vehicle ID

visibility_type

Visibility option

int

Visibility state

Returns

0 if successful

// TODO