AI Core

ai-fuel for developers

How to read and set fuel with ai-fuel running, its state bags and its internal events.

ai-fuel has no exports. The fuel of a vehicle is the fuel entity state bag (0-100), kept by the server.

Read and set fuel with the lib's fuel.get(vehicle) and fuel.set(vehicle, level) (server; fuel.get also on the client). They go through ai-core's fuel layer (in Lua, call its exports GetVehicleFuel and SetVehicleFuel on ai-core), which reads and writes the fuel bag while ai-fuel runs and talks to the other fuel script when the server runs one instead. Your script then works with any fuel script.

Reading and setting fuel

import { fuel } from "@aicore-fivem/lib/server";

// Fill a vehicle the player just paid for at a custom station.
export function fillUp(vehicle: number): void {
  const before = fuel.get(vehicle);
  fuel.set(vehicle, 100);
  console.log(`fuel ${before} -> 100`);
}

Do not write the fuel bag from a client: the server refuses client writes (strict state bag mode), and ai-fuel takes only lower values from the driver's client anyway.

State bags

BagOnTypeMeaning
fuelvehicle entitynumberFuel 0-100. Set by the server. ai-vehicles seeds it when it spawns an owned vehicle.
aiFuelNozzleplayer{ x, y, z, netId } | undefinedThe pump whose nozzle the player holds (x, y, z), and the network id of the vehicle it is plugged into (netId, null while in the hand). Every client near uses it to draw the nozzle and hose.
Lua (client)
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local level = Entity(vehicle).state.fuel -- number 0-100, or nil before the first set

Events

These are ai-fuel's own client-to-server events. They are listed so you can recognize them in logs; do not call them from other scripts.

NameKindWhat it does
ai-fuel:consumeclient event(netId, fuel): the driver reports a lower level. Rated 2 per second; only lower values are taken.
ai-fuel:takeNozzleclient callback(x, y, z): take a pump's nozzle. Rated 1 per second.
ai-fuel:plugclient callback(netId | null): plug the nozzle into a vehicle, or take it out. Rated 2 per second.
ai-fuel:returnNozzleclient eventHang the nozzle back up. Rated 1 per second.
ai-fuel:refuelclient callbackRuns the progress bar, charges and fills the tank.

On this page