Server
This is where all the magic works, below is the documentation of every function from bridge module.
IsPlayerAllowedToOpenMenu
This function determines if player that is trying to open admin menu should be added to database as an administrator. If it returns true
player can open admin menu, but he can't do anything because he has no permissions set.
---@param targetId number
---@return boolean
IsPlayerAllowedToOpenMenu = function(targetId)
local xPlayer = ESX.GetPlayerFromId(targetId)
if IsPlayerAceAllowed(targetId, 'lc_adminmenu.open') then
return true
end
for i = 1, #allowed_groups do
if xPlayer.group == allowed_groups[i] then
return true
end
end
return false
end
GetPermissionGroup
---@param targetId number
---@return string
GetPermissionGroup = function(targetId)
local xPlayer = ESX.GetPlayerFromId(targetId)
for i = 1, #allowed_groups do
local group = allowed_groups[i]
if xPlayer.group == group then
return group
end
end
return 'user'
end
GetAvatar
---@param targetId number
---@return string
GetAvatar = function(targetId)
return GetDiscordAvatarFromId(targetId)
end
GetBridgeIdentifier
If your framework has character-specific identifiers, you can put it here. (char1:xxxxx etc.)
---@param targetId number
---@return string
GetBridgeIdentifier = function(targetId)
local xPlayer = ESX.GetPlayerFromId(targetId)
return xPlayer?.identifier
end
GetGlobalIdentifier
Rockstar license, you can change it to IP if you host an sv_lan server.
---@param targetId number
---@return string
GetGlobalIdentifier = function(targetId)
return GetPlayerIdentifierByType(targetId, 'license')
end
GetIdentifiers
---@param targetId number
---@return string[]
GetIdentifiers = function(targetId)
local identifiers = GetPlayerIdentifiers(targetId)
for i = 1, #identifiers do
if identifiers[i]:find('ip') or identifiers[i]:find('license2') then
identifiers[i] = nil
end
end
return identifiers
end
GetPlayerCard
---@class PlayerCard
---@field player_id number
---@field unique_id? string | number
---@field player_name string
---@field character_name? string
---@param targetId number
---@return PlayerCard
GetPlayerCard = function(targetId)
local xPlayer = ESX.GetPlayerFromId(targetId)
return {
player_id = targetId,
unique_id = 'yay',
player_name = GetPlayerName(targetId),
character_name = xPlayer.name
}
end
GetOwnedVehicles
---@class Vehicle
---@field plate string
---@field label string
---@param sourceId number
---@return Vehicle[]
GetOwnedVehicles = function(sourceId, identifier)
local result = MySQL.query.await('SELECT plate, vehicle from `owned_vehicles` WHERE `owner` = ?', { identifier })
local formatted = lib.callback.await('lc_admin:getVehicleLabels', sourceId, result)
return formatted
end
GetAccounts
---@class Account
---@field name string
---@field money number
---@field label string
---@field icon 'bank' | 'dollar_sign' | 'cash' | 'coins' | 'cent'
---@param targetId string
---@return Account[]
GetAccounts = function(targetId)
local xPlayer = ESX.GetPlayerFromId(targetId)
return {
{
name = 'bank',
money = xPlayer.getAccount('bank').money,
label = 'Bank',
icon = 'bank'
},
{
name = 'money',
money = xPlayer.getAccount('money').money,
label = 'Cash',
icon = 'cash'
},
{
name = 'black_money',
money = xPlayer.getAccount('black_money').money,
label = 'Dirty Cash',
icon = 'dollar_sign'
},
}
end
GetAccountMoney
---@param targetId number
---@param account_name string
---@return number
GetAccountMoney = function(targetId, account_name)
local xPlayer = ESX.GetPlayerFromId(targetId)
return xPlayer.getAccount(account_name)?.money or 0
end
SetAccountMoney
---@param targetId number
---@param account_name string
---@param money number
SetAccountMoney = function(targetId, account_name, money)
local xPlayer = ESX.GetPlayerFromId(targetId)
xPlayer.setAccountMoney(account_name, money == '' and 0 or tonumber(money))
end
GetCharacterInfo
---@class Tooltip
---@field label string
---@field value string
---@class InfoField
---@field label string
---@field value string
---@field tooltip? Tooltip
---@param targetId number
---@return InfoField[]
GetCharacterInfo = function(targetId)
local xPlayer = ESX.GetPlayerFromId(targetId)
return {
{
label = 'Name',
value = xPlayer.name
},
{
label = 'Employment',
value = xPlayer.job.label,
tooltip = {
{
label = 'Name',
value = xPlayer.job.name
},
{
label = 'Grade label',
value = xPlayer.job.grade_label .. ' (' .. xPlayer.job.grade .. ')'
},
{
label = 'Salary',
value = '$' .. xPlayer.job.grade_salary
}
}
},
{
label = 'Date Of Birth',
value = xPlayer.variables.dateofbirth
},
{
label = 'Height',
value = xPlayer.variables.height .. 'cm'
},
{
label = 'Owned vehicles',
value = MySQL.scalar.await('SELECT COUNT(*) from `owned_vehicles` WHERE owner = ?', { xPlayer.identifier })
}
}
end
DeleteVehicle
---@param src string Admin's server ID
---@param targetId number
---@param plate string
DeleteVehicle = function(src, targetId, plate)
MySQL.query.await('DELETE FROM `owned_vehicles` WHERE plate = ?', { plate })
end
IsPlateTaken
---@param plate string
---@return boolean
IsPlateTaken = function(plate)
return MySQL.scalar.await('SELECT plate FROM `owned_vehicles` WHERE plate = ?', { plate }) ~= nil
end
AddVehicle
---@param src string Admin's server ID
---@param targetId number
---@param plate string
---@param vehicle string
AddVehicle = function(src, targetId, plate, vehicle)
local xPlayer = ESX.GetPlayerFromId(targetId)
MySQL.insert.await('INSERT INTO `owned_vehicles` (owner, plate, vehicle) VALUES (?, ?, ?)', { xPlayer.identifier, plate, vehicle })
end
GetCharacterInfoToEdit
param
is just name that is used later to save character edit
---@class EditField
---@param label string
---@param value string | number
---@param param string
---@param targetId number
---@return EditField
GetCharacterInfoToEdit = function(targetId)
local xPlayer = ESX.GetPlayerFromId(targetId)
return {
{
label = 'First name',
value = xPlayer.variables.firstName,
param = 'firstName'
},
{
label = 'Last name',
value = xPlayer.variables.lastName,
param = 'lastName'
},
{
label = 'Height',
value = xPlayer.variables.height,
param = 'height'
},
{
label = 'Date Of Birth (DD/MM/YYYY)',
value = xPlayer.variables.dateofbirth,
param = 'dob'
},
{
label = 'Job',
value = xPlayer.job.name,
param = 'job'
},
{
label = 'Grade',
value = xPlayer.job.grade,
param = 'grade'
}
}
end
ValidateCharacterEdit
If this function returns false, the administrator will be notified that he entered invalid data.
---@param adminId number
---@param targetId number
---@param params { [string]: string | number }
ValidateCharacterEdit = function(adminId, targetId, params)
local check = true
if not ESX.DoesJobExist(params.job, params.grade) then
check = false
end
if not string.match(params.dob, '^%d%d/%d%d/%d%d%d%d$') then
check = false
end
return check
end
SaveCharacterEdit
---@param targetId number
---@param params { [string]: string | number }
SaveCharacterEdit = function(targetId, params)
local xPlayer = ESX.GetPlayerFromId(targetId)
xPlayer.setName(params.firstName .. ' ' .. params.lastName)
xPlayer.set('firstName', params.firstName)
xPlayer.set('lastName', params.lastName)
xPlayer.set('height', params.height)
xPlayer.set('dateofbirth', params.dob)
xPlayer.setJob(params.job, params.grade)
local identifier = getIdentifier(targetId)
if identifier then
MySQL.update('UPDATE users SET firstname = :firstName, lastname = :lastName, height = :height, dateofbirth = :dob WHERE identifier = :identifier', {
firstName = params.firstName,
lastName = params.lastName,
height = params.height,
dob = params.dob,
identifier = identifier
})
end
end
GetLicensesList
---@class License
---@field type string
---@field label string
---@return License[]
GetLicensesList = function()
return MySQL.query.await('SELECT * FROM `licenses` ORDER BY `label` ASC')
end
GetUserLicenses
src - ID of administrator that is trying to check player's licenses.
identifier - Target identifier received from Bridge.GetBridgeIdentifier function.
lc_admin:formatLicense
callback checks if any of user's license types are in the list from Bridge.GetLicensesList function, and then sets theactive
property to true or false.
---@param src number
---@param identifier string
GetUserLicenses = function(src, identifier)
local licenses = MySQL.query.await('SELECT type FROM `user_licenses` WHERE owner = ?', { identifier })
local userLicenses = lib.callback.await('lc_admin:formatLicenses', src, licenses)
return userLicenses
end
ToggleUserLicense
---@param targetId number
---@param type string
---@param active boolean
ToggleUserLicense = function(targetId, type, active)
local xPlayer = ESX.GetPlayerFromId(targetId)
local identifier = xPlayer.identifier
if active then
MySQL.query.await('INSERT INTO `user_licenses` (type, owner) VALUES (?, ?)', { type, identifier })
else
MySQL.query.await('DELETE FROM `user_licenses` WHERE type = ? AND owner = ?', { type, identifier })
end
end
SuccessNotify
---@param targetId number
---@param title? string
---@param description? string
---@param duration? number
---@param id? string
SuccessNotify = function(targetId, title, description, duration, id)
local data = {
position = 'top',
style = {
width = 'fit-content',
backgroundColor = '#000000',
borderRadius = '0.5rem',
color = '#ffffff',
['.description'] = {
color = '#cccccc'
}
},
icon = 'check',
iconColor = '#3fad00'
}
data.title = title or nil
data.description = description or nil
data.id = id or nil
data.duration = duration or nil
TriggerClientEvent('ox_lib:notify', targetId, data)
end
InfoNotify
---@param targetId number
---@param title? string
---@param description? string
---@param id? string
InfoNotify = function(targetId, title, description, id)
local data = {
position = 'top',
style = {
width = 'fit-content',
backgroundColor = '#000000',
borderRadius = '0.5rem',
color = '#ffffff',
['.description'] = {
color = '#cccccc'
}
},
icon = 'info',
iconColor = '#4287f5'
}
data.title = title or nil
data.description = description or nil
data.id = id or nil
TriggerClientEvent('ox_lib:notify', targetId, data)
end
FailNotify
---@param targetId number
---@param title? string
---@param description? string
---@param id? string
FailNotify = function(targetId, title, description, id)
local data = {
position = 'top',
style = {
width = 'fit-content',
backgroundColor = '#000000',
borderRadius = '0.5rem',
color = '#ffffff',
['.description'] = {
color = '#cccccc'
}
},
icon = 'ban',
iconColor = '#C53030'
}
data.title = title or nil
data.description = description or nil
data.id = id or nil
TriggerClientEvent('ox_lib:notify', targetId, data)
end
Last updated