Server-side Exports
dr-bridge also provides various server-side exports that you can call from other server scripts. Below is a detailed breakdown of all the available server-side exports, including input formats, return
Core Exports
GetPlayer(source)Description: Returns the player's data for the specified source.
Input:
source(number): The player's ID (typically passed assource).
Output: Returns a table containing the player's data:
{ identifier = string, -- Unique player identifier (e.g., citizenid or steam ID). source = number, -- Player's source ID. name = { firstname = string, lastname = string, }, job = { name = string, -- Job name (e.g., "police"). label = string, -- Job label (e.g., "Police Officer"). payment = number, -- Job salary. onduty = boolean, -- Whether the player is currently on duty (true/false). Always `true` on ESX by default. isboss = boolean, -- Whether the player is a boss (true/false). grade = { name = string, -- Grade name (e.g., "sergeant"). level = number, -- Grade level (e.g., 2). }, }, gang = table | nil, -- Gang info, if used. Same structure as `job`. money = { cash = number, -- Player's cash money. bank = number, -- Player's bank balance. }, metadata = table, -- Additional metadata (e.g., hunger, thirst, custom flags). items = table, -- Player's inventory items. }
GetJob(source)Description: Returns the player's job information for the specified source.
Input:
source(number): The player's ID.
Output: Returns a table containing:
{ name = string, -- Job name (e.g., "police"). grade = string, -- Job grade (e.g., "officer"). }
SetJob(source, job, grade)Description: Sets the player's job and grade.
Input:
source(number): The player's ID.job(string): The job name (e.g.,"police").grade(string): The job grade (e.g.,"officer").
Output: None (sets the player's job).
GetMoney(source, account)Description: Retrieves the player's balance for a specific account (e.g.,
"cash","bank").Input:
source(number): The player's ID.account(string): The account type (e.g.,"cash","bank").
Output: Returns a number representing the balance.
AddMoney(source, amount, account)Description: Adds money to the player's specified account.
Input:
source(number): The player's ID.amount(number): The amount to add.account(string): The account type (e.g.,"cash","bank").
Output: None (adds the specified amount).
RemoveMoney(source, amount, account)Description: Removes money from the player's specified account.
Input:
source(number): The player's ID.amount(number): The amount to remove.account(string): The account type (e.g.,"cash","bank").
Output: None (removes the specified amount).
AddItem(source, item, count, slot, metadata)Description: Adds an item to the player's inventory.
Input:
source(number): The player's ID.item(string): The item name (e.g.,"water").count(number): The quantity of the item.slot(number, optional): The inventory slot (default is1).metadata(table, optional): Any additional item metadata.
Output: None (adds the item to the player's inventory).
RemoveItem(source, item, count, slot)Description: Removes an item from the player's inventory.
Input:
source(number): The player's ID.item(string): The item name (e.g.,"water").count(number): The quantity to remove.slot(number, optional): The inventory slot (default is1).
Output: None (removes the item from the player's inventory).
HasItem(source, item, count)Description: Checks if the player has a specific item with a given quantity.
Input:
source(number): The player's ID.item(string): The item name (e.g.,"water").count(number, optional): The quantity to check. Default is1.
Output: Returns boolean (
trueif the player has the item,falseotherwise).
RegisterCallback(name, handler)Description: Registers a server callback that can be triggered from the client. Compatible with both QBCore and ESX throughdr-bridge.Input:
name(string): The name of the callback (must match what the client triggers).handler(function): A function that handles the callback logic. It receives:source(number): The player's server ID who triggered the callback.cb(function): A function you must call with the result to return to the client....(any): Any additional arguments passed from the client.
Output: None (registers the callback).
Example:
exports['dr-bridge']:RegisterCallback('my:getMoney', function(source, cb) local money = 1000 cb(money) end)RegisterCommand(name, help, args, cb, permission)Description: Registers a server command compatible with both QBCore and ESX. Internally uses
QBCore.Commands.Add()orESX.RegisterCommand()depending on the framework. Automatically handles permission checks using the framework’s built-in system.Input:
name(string): Command name.help(string, optional): Help text for the command.args(table, optional): Argument definitions (used mainly in QBCore).cb(function): Handler function receiving:source(number): The player's server ID.args(table): Arguments passed from the player.
permission(string, optional): Framework-specific group/role name required to use the command (e.g.,"admin"). If not set, command is available to all users.
Output: None (registers the command).
Example:
exports['dr-bridge']:RegisterCommand('revive', 'Revive yourself', {}, function(source, args) -- Revive logic here end, 'admin') -- Only accessible to players with the "admin" gRegisterUsableItem(itemName, callback)Description: Registers a usable item compatible with both QBCore and ESX. Internally uses
QBCore.Functions.CreateUseableItem()orESX.RegisterUsableItem()depending on the framework. Automatically waits for framework initialization if it hasn't completed yet.Input:
itemName(string): The name of the item to register (e.g.,"bandage").callback(function): A function that is called when the player uses the item. Receives:source(number): The server ID of the player who used the item.
Output: None (registers the item use callback internally in the framework).
Example:
exports['dr-bridge']:RegisterUsableItem('bandage', function(source) local player = Bridge.GetPlayer(source) print(('Player %s used a bandage'):format(player.identifier)) end)
Extras
GetIdentifiers(source)Description: Returns the player's identifiers (e.g., Steam, license, Discord, IP).
Input:
source(number): The player's ID.
Output: Returns a table containing:
GetPlayerName(source)Description: Returns the player's name for the specified source.
Input:
source(number): The player's ID.
Output: Returns a string representing the player's name.
SendDiscordLog(webhook, title, message, color)Description: Sends a log message to a Discord webhook.
Input:
webhook(string): The Discord webhook URL.title(string): The title of the log message.message(string): The content of the log message.color(number, optional): The color code for the embed (default is16777215).
Output: None (sends the message to the Discord webhook).
GetOnlineCount()Description: Returns the number of online players.
Input: None.
Output: Returns a number representing the online player count.
SendChatMessage(source, message, prefix)Description: Sends a chat message to the specified player.
Input:
source(number): The player's ID.message(string): The message to send.prefix(string, optional): The prefix for the message (default is"[Bridge]").
Output: None (sends the message to the chat).
LogToConsole(title, message)Description: Logs a message to the server console.
Input:
title(string): The title of the log message.message(string): The content of the log message.
Output: None (logs the message to the console).
Shared Utils
DebugPrint(message)Description: Prints a debug message to the console if debug mode is enabled.
Input:
message(string): The message to print.
Output: None (prints the message to the console).
TableHasValue(table, value)Description: Checks if a table contains a specific value.
Input:
table(table): The table to search in.value(any): The value to search for.
Output: Returns boolean (
trueif the value exists,falseotherwise).
DeepCopy(table)Description: Creates a deep copy of a table.
Input:
table(table): The table to copy.
Output: Returns a new table that is a deep copy of the input table.
Round(number, decimals)Description: Rounds a number to a specified number of decimal places.
Input:
number(number): The number to round.decimals(number, optional): The number of decimal places to round to. Default is0.
Output: Returns a number (rounded value).
IsTable(value)Description: Checks if the given value is a table.
Input:
value(any): The value to check.
Output: Returns boolean (
trueif the value is a table,falseotherwise).
WaitForCondition(condition)Description: Waits until a specified condition is met.
Input:
condition(function): The condition to check (should returntruewhen met).
Output: None (waits for the condition).
Last updated