Skip to content
NivoDocs

Search documentation

Nivo Bridge

Custom systems

Connect a dispatch, notification, progress bar, target or inventory we do not support yet.

Running a dispatch, notification, progress bar, target or inventory that Nivo does not support out of the box? Connect it yourself in a few lines, without touching any escrowed code.

  1. Set the matching option in nv_bridge/config.lua to 'custom', e.g. Dispatch = 'custom'.
  2. Fill the function in the matching file in nv_bridge/custom/.
  3. Restart the Nivo scripts. The console line nv_bridge ...: dispatch=custom confirms it is used.

Every file ships with a working default (the built-in system), so nothing breaks while you are still writing your code.

Fileconfig.luaRuns on
custom/dispatch.luaDispatch = 'custom'server
custom/notify.luaNotify = 'custom'client (server notifications land here too)
custom/progress.luaProgress = 'custom'client
custom/target.luaTarget = 'custom'client
custom/inventory.luaInventory = 'custom'server

custom/dispatch.lua

-- Nivo Development | nv_bridge/custom/dispatch.lua  (server side)
-- Your own police dispatch. Used when config.lua has Dispatch = 'custom'.
--
-- send(alert) is called for every police alert of every Nivo script. alert = {
--     jobs     = { 'police', 'sheriff' },   -- who should get it
--     code     = '10-90',
--     title    = 'Drug sale',
--     message  = 'Suspicious hand-to-hand sale reported',
--     coords   = vector3(x, y, z),
--     priority = 'low' | 'medium' | 'high',
--     blip     = { sprite = 161, color = 1, scale = 1.0 },
--     src      = 12,                         -- server id of the suspect (can be nil)
-- }
-- Replace the body with the call of your dispatch resource. Until then it uses the built-in alert (notification + blip).
Bridge.Register('dispatch', 'custom', {
    send = function(alert)
        -- Example:
        -- exports['my_dispatch']:CreateCall({
        --     jobs = alert.jobs, code = alert.code, title = alert.title, text = alert.message,
        --     coords = alert.coords, priority = alert.priority,
        -- })

        Bridge.impl.dispatch.builtin.send(alert)
    end,
})

custom/notify.lua

-- Nivo Development | nv_bridge/custom/notify.lua  (client side)
-- Your own notifications. Used when config.lua has Notify = 'custom'. Server notifications of Nivo scripts end up here too.
--
-- notify(message, kind, title, duration)
--   kind     = 'inform' | 'success' | 'error' | 'warning'
--   title    = optional heading (string or nil)
--   duration = milliseconds (number or nil)
-- Replace the body with your notification resource. Until then it uses the GTA notification above the minimap.
Bridge.Register('notify', 'custom', {
    notify = function(message, kind, title, duration)
        -- Example:
        -- exports['my_notify']:Show({ text = message, type = kind, title = title, time = duration or 5000 })

        BeginTextCommandThefeedPost('STRING')
        AddTextComponentSubstringPlayerName(title and (title .. '~n~' .. message) or message)
        EndTextCommandThefeedPostTicker(false, true)
    end,
})

custom/progress.lua

-- Nivo Development | nv_bridge/custom/progress.lua  (client side)
-- Your own progress bar. Used when config.lua has Progress = 'custom'.
--
-- progress(data) must wait until the bar ends and return true when it finished, false when the player cancelled. data = {
--     duration   = 5000,                           -- milliseconds
--     label      = 'Packing drugs',
--     canCancel  = true,
--     anim       = { dict = 'mp_common', clip = 'givetake1_a', flag = 49 },   -- or nil
--     disable    = { move = true, car = true, combat = true },
-- }
-- Replace the body with your progress bar resource. Until then it uses the built-in bar.
Bridge.Register('progress', 'custom', {
    progress = function(data)
        -- Example for a resource with a callback:
        -- local p = promise.new()
        -- exports['my_progress']:Start(data.label, data.duration, function(cancelled) p:resolve(not cancelled) end)
        -- return Citizen.Await(p)

        return Bridge.impl.progress.builtin.progress(data)
    end,
})

custom/target.lua

-- Nivo Development | nv_bridge/custom/target.lua  (client side)
-- Your own target / interaction resource. Used when config.lua has Target = 'custom'.
--
-- Nivo scripts pass options in the ox_target format:
--   { name = 'nv_drugs-selling', label = 'Sell', icon = 'fa-solid fa-sack-dollar', distance = 2.0,
--     onSelect = function(data) end,  -- data = { entity = entity or nil, coords = vector3 }
--     canInteract = function(entity, distance, coords, name) return true end }
-- Implement the five functions with your resource. Until then they use the built-in [E] prompt.
local builtin = Bridge.impl.target.builtin

Bridge.Register('target', 'custom', {
    addLocalEntity = function(entity, options) return builtin.addLocalEntity(entity, options) end,
    removeLocalEntity = function(entity) return builtin.removeLocalEntity(entity) end,
    -- data = { coords = vector3, radius = 1.5, name = 'nv_lab_1', options = { ... } }; return an id for removeZone
    addSphereZone = function(data) return builtin.addSphereZone(data) end,
    removeZone = function(id) return builtin.removeZone(id) end,
    -- options shown on every NPC (not players)
    addGlobalPed = function(options) return builtin.addGlobalPed(options) end,
})

custom/inventory.lua

-- Nivo Development | nv_bridge/custom/inventory.lua  (server side)
-- Your own inventory. Used when config.lua has Inventory = 'custom'.
--
-- Implement the functions with your inventory's exports. Until then they use the framework's item functions
-- (works with any inventory, but without item metadata such as drug quality).
--   count(src, item)                          -> number
--   slots(src, item)                          -> { { slot = 1, count = 3, metadata = {} }, ... }
--   add(src, item, count, metadata, slot)     -> true | false
--   remove(src, item, count, metadata, slot)  -> true | false
--   canCarry(src, item, count)                -> true | false
local native = Bridge.impl.inventory.native

Bridge.Register('inventory', 'custom', {
    count = function(src, item) return native.count(src, item) end,
    slots = function(src, item) return native.slots(src, item) end,
    add = function(src, item, count, metadata, slot) return native.add(src, item, count, metadata, slot) end,
    remove = function(src, item, count, metadata, slot) return native.remove(src, item, count, metadata, slot) end,
    canCarry = function(src, item, count) return native.canCarry(src, item, count) end,
})

-- Storage inventories (used e.g. by drug labs). Remove the comment and implement when your inventory has stashes.
-- Bridge.Register('stash', 'custom', {
--     register = function(id, label, slots, weight) end,
--     add = function(id, item, count, metadata) return false end,
--     clear = function(id) end,
--     open = function(src, id) end,
--     guard = function(prefix, fn) end,  -- optional: only fn(src, id) == true may open stashes starting with prefix
-- })