> For the complete documentation index, see [llms.txt](https://devmosaic.gitbook.io/devmosaic/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devmosaic.gitbook.io/devmosaic/resources/devmosaic-ox-fuel-rework/exports-and-events.md).

# Exports And Events

Hook payment and money checks, and the events the resource fires.

### Payment

Replace how the pump takes money. Server side.

```lua
exports.ox_fuel:setPaymentMethod(function(playerId, price)
    -- return true if the player paid, or nil / false if they could not
    return exports.ox_inventory:RemoveItem(playerId, 'money', price)
end)
```

Return a truthy value to let the sale complete. Return nothing and the pump shows `CHECK PAYMENT` and nothing is dispensed.

Pass `nil` to restore the default behaviour, which takes a `money` item through whichever inventory the bridge detected. Override this when your server uses something the bridge does not cover - a bank balance, a differently named cash item, or a custom economy. The example above uses ox\_inventory only as an illustration.

### Money Check

Replace how the client decides whether a player can afford to start. Client side.

```lua
exports.ox_fuel:setMoneyCheck(function()
    return exports.ox_inventory:GetItemCount('money')
end)
```

This only controls what the pump screen offers. The actual charge still goes through `setPaymentMethod` on the server, so this is a display and gating hook, not a security boundary.

The default reads a `money` item through the bridge, so you only need this if you overrode payment as well.

{% hint style="warning" %}
Set both, not one. `setMoneyCheck` decides what the player is offered; `setPaymentMethod` decides what actually happens. If they disagree, players get told they can afford a fill that then fails.
{% endhint %}

### Events

| Event                   | Side   | Fired when                              |
| ----------------------- | ------ | --------------------------------------- |
| `ox_fuel:pay`           | Server | A pump sale is settled.                 |
| `ox_fuel:fuelCan`       | Server | A petrol can is bought or refilled.     |
| `ox_fuel:updateFuelCan` | Server | A vehicle is fuelled from a can.        |
| `ox_fuel:setFuel`       | Server | A vehicle's fuel level is written back. |

### How Sales Are Secured

When a player takes a nozzle the server issues a session token and locks that nozzle. The lock is keyed on routing bucket, pump model and position, so the same pump in two different buckets is two separate locks.

A sale is only accepted if the session exists, the token matches, the vehicle network id matches, the session is in the filling stage, and it has not already been settled. Anything else is rejected.

Sessions are released when the player drops, changes routing bucket, walks more than 30 metres from the pump, or stops reporting for 20 seconds.

### Fuel Level Storage

Fuel is stored on the vehicle's state bag under `fuel`, replicated to all clients:

```lua
local level = Entity(vehicle).state.fuel
```

This is unchanged from stock `ox_fuel`, so anything already reading it keeps working.
