# Using the Bridge

The NOVA Bridge (`nova_bridge`) provides compatibility with existing ESX, QBCore, vRPex, and Creative scripts.

## What Does the Bridge Do?

The bridge intercepts calls to other framework APIs and translates them to NOVA's native API. This means you can use most existing scripts without modification.

## Installation

```bash
git clone https://github.com/Buddhapt/nova-bridge.git nova_bridge
```

Add to `server.cfg` (after nova\_core):

```cfg
ensure nova_core
ensure nova_bridge
```

## Configuration

Edit `nova_bridge/config.lua`:

```lua
Config = {}

-- Which framework to emulate
-- Options: 'esx', 'qb', 'vrpex', 'creative'
Config.Framework = 'esx'
```

## ESX Compatibility

When `Config.Framework = 'esx'`, the bridge provides:

```lua
-- These ESX calls will work automatically:
local ESX = exports['es_extended']:getSharedObject()

-- Player functions
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.getMoney()
xPlayer.getJob()
xPlayer.addMoney(amount)
xPlayer.removeMoney(amount)
xPlayer.addInventoryItem(item, count)
xPlayer.removeInventoryItem(item, count)

-- Events
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
```

### Supported ESX Functions

| ESX Function                                                | Status                   |
| ----------------------------------------------------------- | ------------------------ |
| `GetPlayerFromId`                                           | ✅ Full                   |
| `GetPlayers`                                                | ✅ Full                   |
| `getMoney` / `addMoney` / `removeMoney`                     | ✅ Full                   |
| `getJob` / `setJob`                                         | ✅ Full                   |
| `getInventory` / `addInventoryItem` / `removeInventoryItem` | ✅ Full                   |
| `getGroup`                                                  | ✅ Full                   |
| `ShowNotification`                                          | ✅ Mapped to nova\_notify |

## QBCore Compatibility

When `Config.Framework = 'qb'`:

```lua
-- These QBCore calls will work automatically:
local QBCore = exports['qb-core']:GetCoreObject()

local Player = QBCore.Functions.GetPlayer(source)
Player.PlayerData.money.cash
Player.PlayerData.job
Player.Functions.AddMoney('cash', amount)
Player.Functions.RemoveMoney('cash', amount)
```

### Supported QBCore Functions

| QBCore Function            | Status |
| -------------------------- | ------ |
| `GetPlayer`                | ✅ Full |
| `GetPlayers`               | ✅ Full |
| `AddMoney` / `RemoveMoney` | ✅ Full |
| `GetMoney`                 | ✅ Full |
| `SetJob`                   | ✅ Full |
| `AddItem` / `RemoveItem`   | ✅ Full |
| `HasItem`                  | ✅ Full |

## vRPex Compatibility

When `Config.Framework = 'vrpex'`:

```lua
-- vRPex calls will be translated
local vRP = {}
Citizen.CreateThread(function()
    vRP = exports['vrp']:getInterface()
end)

vRP.getUserId({source})
vRP.getMoney({user_id})
vRP.giveMoney({user_id, amount})
```

## Creative Compatibility

When `Config.Framework = 'creative'`:

```lua
-- Creative framework calls will be translated
local API = exports['creative_api']
API:GetPlayerMoney(source)
API:AddPlayerMoney(source, amount)
```

## Limitations

::: warning The bridge covers the most common API calls (\~80% of scripts). Some edge cases may require manual adaptation:

* Custom framework events specific to a particular script
* Direct database queries that reference framework-specific table structures
* UI elements that are tightly coupled to a specific framework :::

## Running Both

You can technically run nova\_bridge alongside ESX/QBCore scripts, but for best results:

1. Start with `Config.Framework = 'esx'` (most common)
2. Test your existing scripts one by one
3. Gradually replace them with NOVA-native versions
