Exports
Player
Server

Server

These calls take a server id. Job and gang tables are { name, grade, label, gradeLabel, onDuty }.

A framework with no matching function returns false or nil.

GetPlayer

Reads the loaded character.

Parameters

  • source number — server id

Returns

table|nil — { source, identifier, name, job, gang }, or nil when that player is not loaded.

Example

local player = Bridge.GetPlayer(source)
 
if not player then
    return
end
 
print(player.name, player.job.name, player.job.grade)

GetPlayers

Lists every loaded character.

Parameters

None.

Returns

number[] — server ids.

Example

for _, playerId in ipairs(Bridge.GetPlayers()) do
    local player = Bridge.GetPlayer(playerId)
    print(playerId, player and player.name)
end

GetIdentifier

Parameters

  • source number — server id

Returns

string|nil — the character id. Standalone uses the license.

Example

local identifier = Bridge.GetIdentifier(source)
 
if not identifier then
    return
end
 
MySQL.update('UPDATE rentals SET owner = ? WHERE id = ?', { identifier, rentalId })

GetPlayerByIdentifier

Finds an online player from that identifier.

Parameters

  • identifier string — the same value GetIdentifier returns

Returns

number|nil — server id, or nil when that character is offline.

Example

local target = Bridge.GetPlayerByIdentifier('ABC12345')
 
if not target then
    return
end
 
Bridge.AddPlayerMoney(target, 'bank', 500, 'refund')

GetPlayerByPhone

Finds an online player from a phone number.

Parameters

  • number string — phone number

Returns

number|nil — server id. ESX, ox, ND, and vRP return nil.

Example

local target = Bridge.GetPlayerByPhone('555-0100')
 
if not target then
    return
end
 
Bridge.Notify(target, { description = 'Incoming call', kind = 'info' })

GetPlayerJob

Parameters

  • source number — server id

Returns

table — { name, grade, label, gradeLabel, onDuty }. Unemployed when the framework has no job.

Example

local job = Bridge.GetPlayerJob(source)
 
if job.name ~= 'police' or not job.onDuty then
    return
end

SetPlayerJob

Sets the primary job.

Parameters

  • source number — server id
  • name string — job name that already exists on that framework
  • grade number — grade or rank. Defaults to 0. ND defaults a missing rank to 1.

Returns

boolean

Example

local hired = Bridge.SetPlayerJob(source, 'police', 2)
 
if not hired then
    return
end
 
local job = Bridge.GetPlayerJob(source)
print(job.label, job.gradeLabel)

GetPlayerGang

Parameters

  • source number — server id

Returns

table — same shape as a job. name is none when that framework has no gang. vRP has no gang.

Example

local gang = Bridge.GetPlayerGang(source)
 
if gang.name == 'none' then
    return
end
 
print(gang.name, gang.grade)

SetPlayerGang

Parameters

  • source number — server id
  • name string — gang name
  • grade number — grade. Defaults to 0.

Returns

boolean — false on ESX, ND, and vRP.

Example

if not Bridge.SetPlayerGang(source, 'ballas', 1) then
    return
end
 
print(Bridge.GetPlayerGang(source).name)

SetJobDuty

Parameters

  • source number — server id
  • onDuty boolean

Returns

boolean — false on ox and ND, which have no duty flag.

Example

Bridge.SetJobDuty(source, true)
 
local job = Bridge.GetPlayerJob(source)
print(job.onDuty)

GetPlayersByJob

Parameters

  • job string — job name
  • onDuty boolean — optional. When true, only players marked on duty are returned.

Returns

number[] — server ids.

Example

local officers = Bridge.GetPlayersByJob('police', true)
 
for i = 1, #officers do
    Bridge.Notify(officers[i], { description = 'Backup requested', kind = 'info' })
end

GetDutyCount

Counts players on duty for a job.

Parameters

  • job string — job name

Returns

number — ND has no duty flag, so the count is every player with that job.

Example

local onDuty = Bridge.GetDutyCount('police')
 
if onDuty < 1 then
    return
end
 
print(onDuty)

GetPlayerMoney

Parameters

  • source number — server id
  • account string — optional. cash is the default. ESX maps cash to the money account. ox cash is the money item. vRP and standalone return 0.

Returns

number

Example

local bank = Bridge.GetPlayerMoney(source, 'bank')
local cash = Bridge.GetPlayerMoney(source, 'cash')
 
print(bank, cash)

AddPlayerMoney

reason is optional. When it is omitted the bridge sends n_bridge. vRP accepts the argument and ignores it.

Parameters

  • source number — server id
  • account string — optional when the next argument is the amount. AddPlayerMoney(source, 500, 'paycheck') adds cash.
  • amount number
  • reason string — optional

Returns

boolean

Example

if not Bridge.AddPlayerMoney(source, 'bank', 250, 'paycheck') then
    return
end
 
print(Bridge.GetPlayerMoney(source, 'bank'))

RemovePlayerMoney

Fails when the balance is lower than amount. reason follows the same rules as add.

Parameters

  • source number — server id
  • account string — optional. Same shorthand as add.
  • amount number
  • reason string — optional

Returns

boolean

Example

if not Bridge.RemovePlayerMoney(source, 'cash', 100, 'shop') then
    Bridge.Notify(source, { description = 'Not enough cash', kind = 'error' })
    return
end

SetPlayerMoney

Sets the balance to an exact amount. ND returns false. vRP ignores reason.

Parameters

  • source number — server id
  • account string — cash or bank. A bare amount is cash: SetPlayerMoney(source, 500, 'fine').
  • amount number — zero or higher
  • reason string — optional

Returns

boolean

Example

Bridge.SetPlayerMoney(source, 'bank', 500, 'fine')
print(Bridge.GetPlayerMoney(source, 'bank'))

GetPlayerMetadata

Parameters

  • source number — server id
  • key string

Returns

any — the stored value, or nil.

Example

local hunger = Bridge.GetPlayerMetadata(source, 'hunger')
 
if type(hunger) == 'number' and hunger < 20 then
    Bridge.Notify(source, { description = 'You are hungry', kind = 'warning' })
end

SetPlayerMetadata

Parameters

  • source number — server id
  • key string
  • value any

Returns

boolean

Example

if Bridge.SetPlayerMetadata(source, 'hunger', 80) then
    print(Bridge.GetPlayerMetadata(source, 'hunger'))
end

HasPermission

Parameters

  • source number — server id
  • permission string — group or ACE name

Returns

boolean — standalone checks ACE only.

Example

if not Bridge.HasPermission(source, 'admin') then
    return
end
 
Bridge.SetPlayerJob(source, 'police', 4)

GetCharacter

Parameters

  • source number — server id

Returns

table|nil — { firstName, lastName, phone, gender, dateOfBirth }. Phone is nil on ox and ND. vRP has no date of birth or gender.

Example

local character = Bridge.GetCharacter(source)
 
if not character then
    return
end
 
print(character.firstName, character.phone)

IsBoss

Parameters

  • source number — server id

Returns

boolean — false on ND and vRP, which have no boss flag. ox is true only when that grade is named boss or marked as the group owner.

Example

if not Bridge.IsBoss(source) then
    Bridge.Notify(source, { description = 'Bosses only', kind = 'error' })
    return
end

HasGroup

Parameters

  • source number — server id
  • filter string|string[]|table — a job, gang, or character id; a list of those; or { police = 2 } for a minimum grade

Returns

boolean

Example

if Bridge.HasGroup(source, 'police') then
    Bridge.Notify(source, { description = 'Police only', kind = 'info' })
end
 
if Bridge.HasGroup(source, { police = 2 }) then
    print('sergeant or higher')
end

GetJobs

Parameters

None.

Returns

table — list of { name, label, grades }. Each grade is { grade, name, label, isBoss }. ND and vRP return an empty list.

Example

local jobs = Bridge.GetJobs()
 
for i = 1, #jobs do
    print(jobs[i].name, jobs[i].label)
end

GetGangs

Parameters

None.

Returns

table — same shape as GetJobs. ESX, ND, and vRP return an empty list. vRP has no gang.

Example

local gangs = Bridge.GetGangs()
 
for i = 1, #gangs do
    print(gangs[i].name)
end

RegisterCallback

The handler runs on the server. Call reply once with the values the client should receive.

Parameters

  • name string
  • handler function — handler(source, reply, ...)

Returns

boolean

Example

Bridge.RegisterCallback('garage:price', function(source, reply, plate)
    reply(500)
end)

TriggerClientCallback

Asks one player's client for a callback registered there with RegisterClientCallback. The result arrives in handler. If the player drops first, handler runs with no values.

Parameters

  • name string
  • target number — server id
  • handler function — receives the values the client passed to reply
  • ... — extra arguments forwarded to the client handler

Returns

boolean — true when the request was sent.

Example

Bridge.TriggerClientCallback('garage:nearest', source, function(plate)
    print(plate)
end, 10.0)

AwaitClientCallback

Same request as TriggerClientCallback, but it yields and returns the client's values.

Parameters

  • name string
  • target number — server id
  • timeout number — ms, optional. Defaults to 5000.
  • ... — extra arguments forwarded to the client handler

Returns

... — the values the client passed to reply, or nothing on timeout.

Example

local plate = Bridge.AwaitClientCallback('garage:nearest', source, 3000, 10.0)
 
if plate then
    print(plate)
end

OnPlayerReady

Runs for characters who are already loaded, and for each character that loads later.

Parameters

  • handler function — called as handler(source)

Returns

boolean — true when the handler was stored.

Example

Bridge.OnPlayerReady(function(playerId)
    local player = Bridge.GetPlayer(playerId)
    print(('loaded %s'):format(player and player.name or playerId))
end)
Join Our Discord