Exports
Player
Client

Client

Local player. These calls do not take a server id.

GetPlayerData

Parameters

None.

Returns

table|nil — same shape as server GetPlayer, or nil before the character exists.

Example

local me = Bridge.GetPlayerData()
 
if not me then
    return
end
 
print(me.identifier)
print(me.job.name, me.job.grade, me.job.onDuty)
print(me.gang.name)

IsPlayerLoaded

Parameters

None.

Returns

boolean

Example

CreateThread(function()
    while not Bridge.IsPlayerLoaded() do
        Wait(200)
    end
 
    local me = Bridge.GetPlayerData()
    print(me.name, me.job.label)
end)

GetIdentifier

Parameters

None.

Returns

string|nil — vRP and standalone return nil.

Example

local identifier = Bridge.GetIdentifier()
 
if identifier then
    print(identifier)
end

GetPlayerJob

Parameters

None.

Returns

table — { name, grade, label, gradeLabel, onDuty }.

Example

local job = Bridge.GetPlayerJob()
 
if job.name == 'ambulance' and job.onDuty then
    Bridge.ShowText('On duty')
end

GetPlayerGang

Parameters

None.

Returns

table — same shape as the job. name is none when there is no gang. vRP has no gang.

Example

local gang = Bridge.GetPlayerGang()
 
if gang.name ~= 'none' then
    print(gang.label, gang.gradeLabel)
end

GetPlayerMoney

Parameters

  • account string — optional. cash is the default. ESX maps it to the money account. vRP returns 0.

Returns

number

Example

local cash = Bridge.GetPlayerMoney('cash')
local bank = Bridge.GetPlayerMoney('bank')
 
if cash < 50 then
    Bridge.Notify({ description = 'Not enough cash', kind = 'error' })
end

GetPlayerMetadata

Reads the local metadata table. Changing metadata stays on the server.

Parameters

  • key string

Returns

any

Example

local hunger = Bridge.GetPlayerMetadata('hunger')
 
if type(hunger) == 'number' then
    print(('hunger %s'):format(hunger))
end

GetCharacter

Parameters

None.

Returns

table|nil — { firstName, lastName, phone, gender, dateOfBirth }. Phone is nil on ox and ND. vRP returns nil.

Example

local character = Bridge.GetCharacter()
 
if character then
    print(character.firstName, character.lastName)
end

IsBoss

Parameters

None.

Returns

boolean — false on ND and vRP.

Example

if Bridge.IsBoss() then
    Bridge.OpenBossMenu()
end

TriggerCallback

Asks the server callback registered with RegisterCallback. The result arrives in handler.

Parameters

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

Returns

boolean — true when the request was sent.

Example

Bridge.TriggerCallback('garage:price', function(price)
    print(price)
end, plate)

AwaitCallback

Same request as TriggerCallback, but it yields and returns the server's values.

Parameters

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

Returns

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

Example

local price = Bridge.AwaitCallback('garage:price', 3000, plate)

RegisterClientCallback

The handler runs on this client when the server calls TriggerClientCallback or AwaitClientCallback. Call reply once with the values the server should receive.

Parameters

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

Returns

boolean

Example

Bridge.RegisterClientCallback('garage:nearest', function(reply, radius)
    local vehicle = Bridge.GetClosestVehicle(nil, radius)
    reply(vehicle ~= 0 and Bridge.GetPlate(vehicle) or nil)
end)

GetClosestPlayer

Parameters

  • coords vector3 — optional. Defaults to the local player.
  • radius number — optional. Defaults to 5.0.

Returns

number|nil, number|nil — server id and distance. Both are nil when nobody is inside the radius.

Example

local playerId, distance = Bridge.GetClosestPlayer(nil, 3.0)
 
if playerId then
    print(playerId, distance)
end

GetNearbyPlayers

Parameters

  • coords vector3 — optional
  • radius number — optional. Defaults to 5.0.

Returns

table — list of { id, distance }. id is a server id.

Example

local nearby = Bridge.GetNearbyPlayers(nil, 8.0)
 
for i = 1, #nearby do
    print(nearby[i].id, nearby[i].distance)
end

GetClosestPed

Skips the local player and other players.

Parameters

  • coords vector3 — optional
  • radius number — optional. Defaults to 5.0.

Returns

number, number|nil — ped entity, or 0 when none is in range, and the distance.

Example

local ped = Bridge.GetClosestPed(nil, 4.0)
 
if ped ~= 0 then
    print(ped)
end

GetClosestObject

Parameters

  • coords vector3 — optional
  • radius number — optional. Defaults to 5.0.

Returns

number, number|nil — object entity, or 0 when none is in range, and the distance.

Example

local object = Bridge.GetClosestObject(GetEntityCoords(PlayerPedId()), 2.0)
 
if object ~= 0 then
    print(object)
end

OnPlayerReady

Parameters

  • handler function — called with no server id

Returns

boolean

Example

Bridge.OnPlayerReady(function()
    local me = Bridge.GetPlayerData()
    print(me and me.job.name or 'unemployed')
end)
Join Our Discord