> For the complete documentation index, see [llms.txt](https://brunx-mods.gitbook.io/brunx-mods-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brunx-mods.gitbook.io/brunx-mods-docs/products/scripts/brunx-bridge/code-examples.md).

# Code Examples

Copy these into your own resource and adapt them. They work on every supported framework.

## Job-locked command

{% code title="server.lua" %}

```lua
local Bridge = exports['brnx_bridge']:GetBridge()

RegisterCommand('armory', function(source)
    if not Bridge.HasJob(source, { police = true, sheriff = { minGrade = 1, dutyOnly = true } }) then
        return Bridge.Notify(source, {
            title = 'Access denied',
            description = 'You are not allowed to use the armory.',
            type = 'error'
        })
    end

    TriggerClientEvent('armory:open', source)
end, false)
```

{% endcode %}

## Selling an item

{% code title="server.lua" %}

```lua
local Bridge = exports['brnx_bridge']:GetBridge()

local PRICE = 150

RegisterNetEvent('fishing:sell', function()
    local src = source

    if not Bridge.RemoveItem(src, 'fish', 1) then
        return Bridge.Notify(src, 'You have no fish to sell.', 'error')
    end

    Bridge.AddMoney(src, 'cash', PRICE, 'Sold fish')
    Bridge.Notify(src, ('You sold a fish for $%s.'):format(PRICE), 'success')
end)
```

{% endcode %}

## Buying with a weight check

{% code title="server.lua" %}

```lua
local Bridge = exports['brnx_bridge']:GetBridge()

RegisterNetEvent('shop:buyWater', function()
    local src = source

    if not Bridge.CanCarryItem(src, 'water', 1) then
        return Bridge.Notify(src, 'Your pockets are full.', 'error')
    end

    if not Bridge.RemoveMoney(src, 'cash', 10, 'Bought water') then
        return Bridge.Notify(src, 'Not enough cash.', 'error')
    end

    Bridge.AddItem(src, 'water', 1)
end)
```

{% endcode %}

## Paying a fine into the police budget

{% code title="server.lua" %}

```lua
local Bridge = exports['brnx_bridge']:GetBridge()

RegisterNetEvent('police:payFine', function(amount)
    local src = source
    amount = tonumber(amount) or 0
    if amount <= 0 then return end

    if Bridge.RemoveMoney(src, 'bank', amount, 'Fine') then
        Bridge.Society.AddMoney('police', amount, 'Fine paid')
        Bridge.Notify(src, ('You paid a fine of $%s.'):format(amount), 'inform')
    end
end)
```

{% endcode %}

## Alerting every on-duty officer

{% code title="server.lua" %}

```lua
local Bridge = exports['brnx_bridge']:GetBridge()

local function alertPolice(message)
    for _, officer in ipairs(Bridge.GetPlayersByJob({ police = { dutyOnly = true } })) do
        Bridge.Notify(officer, { title = 'Dispatch', description = message, type = 'warning' })
    end
end
```

{% endcode %}

## Target zone with a progress bar

{% code title="client.lua" %}

```lua
local Bridge = exports['brnx_bridge']:GetBridge()

Bridge.Target.AddBoxZone('crafting_bench', {
    coords = vec3(1087.3, -2001.2, 30.9),
    size = vec3(2.0, 1.0, 2.0),
    rotation = 50.0,
    options = {
        {
            label = 'Craft lockpick',
            icon = 'fa-solid fa-screwdriver',
            items = 'metalscrap',
            onSelect = function()
                local done = Bridge.Progress({
                    duration = 8000,
                    label = 'Crafting lockpick...',
                    anim = { dict = 'mini@repair', clip = 'fixing_a_ped' }
                })

                if done then
                    TriggerServerEvent('crafting:lockpick')
                end
            end
        }
    }
})
```

{% endcode %}
