2025-04-15 03:00:44 -04:00
---@diagnostic disable: duplicate-set-field
2025-01-08 06:33:31 -05:00
if GetResourceState ( 'es_extended' ) ~= 'started' then return end
2025-05-18 23:45:37 -04:00
2025-01-08 06:33:31 -05:00
2025-08-31 18:41:12 +01:00
ESX = exports.es_extended : getSharedObject ()
2025-01-08 06:33:31 -05:00
2025-05-09 19:06:50 -05:00
Framework = Framework or {}
2025-01-08 06:33:31 -05:00
2025-07-09 22:17:24 -04:00
local cachedItemList = nil
2025-08-31 18:41:12 +01:00
--- @description This will return the name of the framework in use
--- @return string
2025-01-31 19:23:47 -05:00
Framework.GetFrameworkName = function ()
2025-12-23 19:27:27 -05:00
--print("This is deprecated, please use Framework.GetResourceName() instead.")
2025-12-14 16:22:35 -05:00
return Framework.GetResourceName ()
2025-01-31 19:23:47 -05:00
end
2025-12-14 16:22:35 -05:00
---@description This will get the name of the in use resource.
--- @return string
2025-09-10 12:27:12 -04:00
Framework.GetResourceName = function ()
return 'es_extended'
end
2025-12-14 16:22:35 -05:00
---@description This is an internal function, its here to attempt to emulate qbs shared items mainly, do not use this outside of bridge.
2025-07-09 22:08:44 -04:00
Framework.ItemList = function ()
2025-07-09 22:17:24 -04:00
if cachedItemList then return cachedItemList end
2025-07-09 22:08:44 -04:00
local items = ESX.Items
local repackedTable = {}
for k , v in pairs ( items ) do
if v.label then
repackedTable [ k ] = {
name = k ,
label = v.label ,
weight = v.weight ,
type = "item" ,
image = k .. ".png" ,
unique = false ,
useable = true ,
shouldClose = true ,
description = 'No description provided.' ,
}
end
end
2025-07-09 22:17:24 -04:00
cachedItemList = { Items = repackedTable or {} }
return cachedItemList
2025-07-09 22:08:44 -04:00
end
2025-12-14 16:22:35 -05:00
---@description This will return if the player is an admin in the framework.
---@param src number
---@return boolean
2025-06-01 23:12:32 -04:00
Framework.GetIsFrameworkAdmin = function ( src )
if not src then return false end
local xPlayer = Framework.GetPlayer ( src )
if not xPlayer then return false end
local group = xPlayer.getGroup ()
if group == 'admin' or group == 'superadmin' then return true end
return false
end
2025-12-14 16:22:35 -05:00
---@description Returns the player date of birth.
--- @param src number
2025-08-31 18:41:12 +01:00
--- @return string|nil
2025-02-26 01:34:47 -05:00
Framework.GetPlayerDob = function ( src )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-03-03 02:05:53 -05:00
if not xPlayer then return end
2025-02-26 01:34:47 -05:00
local dob = xPlayer.get ( "dateofbirth" )
return dob
end
2026-08-17 03:49:37 -07:00
Framework.GetPlayerDobByIdentifier = function ( citizenid )
local xPlayer = Framework.GetPlayerByIdentifier ( citizenid )
if xPlayer then
return xPlayer.get ( "dateofbirth" )
end
local result = MySQL.single . await ( "SELECT dateofbirth FROM users WHERE identifier = @identifier" , {[ "@identifier" ] = citizenid })
return result and result.dateofbirth or nil
end
2025-08-31 18:41:12 +01:00
--- @description Returns the player data of the specified source in the framework defualt format
--- @param src any
--- @return table | nil
2025-05-09 23:06:01 -03:00
Framework.GetPlayer = function ( src )
local xPlayer = ESX.GetPlayerFromId ( src )
if not xPlayer then return end
return xPlayer
end
2026-02-08 02:10:14 -07:00
---@description Returns the player data of the specified identifier in the framework defualt format.
---@param citizenid string
---@return table | nil
Framework.GetPlayerByIdentifier = function ( citizenid )
local player = ESX.GetPlayerFromIdentifier ( citizenid )
if not player then return end
return player
end
---@description This will return the player source of the specified citizen ID.
---@param citizenid string
---@return number | nil
Framework.GetPlayerSource = function ( citizenid )
local player = Framework.GetPlayerByIdentifier ( citizenid )
if not player then return end
return player.source
end
2025-08-31 18:41:12 +01:00
--- @description Returns the citizen ID of the player.
--- @param src number
--- @return string | nil returns the citizen ID of the player if it exists
2025-01-08 06:33:31 -05:00
Framework.GetPlayerIdentifier = function ( src )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-03-03 02:05:53 -05:00
if not xPlayer then return end
2025-01-08 06:33:31 -05:00
return xPlayer.getIdentifier ()
end
2025-08-31 18:41:12 +01:00
--- @description This will return the jobs registered in the framework in a table.
--- @return table in the format "{name = jobName, label = jobLabel, grade = {name = gradeName, level = gradeLevel}}"
2025-03-10 01:17:18 -04:00
Framework.GetFrameworkJobs = function ()
return ESX.GetJobs ()
end
2025-08-31 18:41:12 +01:00
--- @description This will return the first and last name of the player.
--- @return string|nil, string|nil returns the first and last name of the player
2025-01-08 06:33:31 -05:00
Framework.GetPlayerName = function ( src )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-03-03 02:05:53 -05:00
if not xPlayer then return end
2025-01-08 06:33:31 -05:00
return xPlayer.variables . firstName , xPlayer.variables . lastName
end
2026-08-17 03:49:37 -07:00
Framework.GetPlayerNameByIdentifier = function ( citizenid )
local xPlayer = Framework.GetPlayerByIdentifier ( citizenid )
if xPlayer then
return xPlayer.variables . firstName , xPlayer.variables . lastName
end
local result = MySQL.single . await ( "SELECT firstname, lastname FROM users WHERE identifier = @identifier" , {[ "@identifier" ] = citizenid })
return result and result.firstname or nil , result and result.lastname or nil
end
2025-12-14 16:22:35 -05:00
---@description This will return a table of all logged in players
2025-08-31 18:41:12 +01:00
--- @return table
2025-04-14 01:16:06 -04:00
Framework.GetPlayers = function ()
local players = ESX.GetExtendedPlayers ()
local playerList = {}
for _ , xPlayer in pairs ( players ) do
table.insert ( playerList , xPlayer.source )
end
return playerList
end
2025-12-14 16:22:35 -05:00
---@description Returns a table of items matching the specified name and if passed metadata from the player's inventory.
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param item string
2025-12-14 16:22:35 -05:00
--- @param metadata table
--- @return table {name, count, metadata, slot}
Framework.GetItem = function ( src , item , metadata )
print ( "ESX does not support item metadata searches, please ensure you are using a supported inventory system or that you have the correct start order." )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return {} end
2025-03-03 02:05:53 -05:00
local playerItems = xPlayer.getInventory ()
2025-01-08 06:33:31 -05:00
local repackedTable = {}
for _ , v in pairs ( playerItems ) do
if v.name == item then
table.insert ( repackedTable , {
name = v.name ,
count = v.count ,
2025-12-14 16:22:35 -05:00
metadata = {}, -- ESX does not support item metadata
slot = 0 , -- ESX does not support item slots
2025-01-08 06:33:31 -05:00
})
end
end
return repackedTable
end
2025-12-14 16:22:35 -05:00
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
2025-08-31 18:41:12 +01:00
--- @param item string
2025-12-14 16:22:35 -05:00
--- @return table {name, label, stack, weight, description, image}
Framework.GetItemInfo = function ( item )
local items = Framework.ItemList ()
if not items [ item ] then return {} end
return { name = item , label = items [ item ]. label , stack = false , weight = items [ item ]. weight , description = items [ item ]. description , image = items [ item ]. image }
end
---@description This will return the count of the item in the players inventory, if not found will return 0.
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
---@param src number
---@param item string
---@param metadata table (optional)
---@return number
Framework.GetItemCount = function ( src , item , metadata )
if metadata then
print ( "ESX does not support item metadata searches, please ensure you are using a supported inventory system or that you have the correct start order." )
end
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return 0 end
2025-01-08 06:33:31 -05:00
return xPlayer.getInventoryItem ( item ). count
end
2025-12-14 16:22:35 -05:00
---@description This will return a boolean if the player has the item.
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param item string
2025-12-14 16:22:35 -05:00
--- @return boolean
2025-03-07 04:08:40 -05:00
Framework.HasItem = function ( src , item )
local getCount = Framework.GetItemCount ( src , item , nil )
return getCount > 0
end
2025-12-14 16:22:35 -05:00
---@description Returns the entire inventory of the player as a table.
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
---@param src number
---@return table {name, count, metadata, slot}
2025-01-08 06:33:31 -05:00
Framework.GetPlayerInventory = function ( src )
2025-12-14 16:22:35 -05:00
print ( "ESX does not support item metadata or slots, please ensure you are using a supported inventory system or that you have the correct start order." )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return {} end
2025-03-03 02:05:53 -05:00
local playerItems = xPlayer.getInventory ()
2025-01-08 06:33:31 -05:00
local repackedTable = {}
for _ , v in pairs ( playerItems ) do
2025-05-09 22:27:48 -03:00
if v.count > 0 then
table.insert ( repackedTable , {
name = v.name ,
count = v.count ,
2025-12-14 16:22:35 -05:00
metadata = {}, -- ESX does not support item metadata
slot = 0 , -- ESX does not support item slots
2025-05-09 22:27:48 -03:00
})
end
2025-01-08 06:33:31 -05:00
end
return repackedTable
end
2025-12-14 16:22:35 -05:00
---@description This will return the item data for the specified slot.
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
--- @param src number
--- @param slot number
--- @return table {name, label, weight, count, metadata, slot, stack, description}
Framework.GetItemBySlot = function ( src , slot )
print ( "ESX does not support item slots, please ensure you are using a supported inventory system or that you have the correct start order." )
return {} -- ESX does not support item slots
end
---@description Adds the specified metadata key and number value to the player's data.
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param metadata string
--- @param value any
--- @return boolean|nil returns true if the metadata was set successfully, otherwise it returns nil
2025-01-08 06:33:31 -05:00
Framework.SetPlayerMetadata = function ( src , metadata , value )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-03-03 02:05:53 -05:00
if not xPlayer then return end
2025-01-08 06:33:31 -05:00
xPlayer.setMeta ( metadata , value , nil )
return true
end
2025-12-14 16:22:35 -05:00
---@description Gets the specified metadata key to the player's data.
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param metadata string
--- @return any|nil
2025-01-08 06:33:31 -05:00
Framework.GetPlayerMetadata = function ( src , metadata )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-03-03 02:05:53 -05:00
if not xPlayer then return end
2025-01-08 06:33:31 -05:00
return xPlayer.getMeta ( metadata ) or false
end
2025-12-14 16:22:35 -05:00
---@description This is an internal function and should not be used outside of bridge, this is only present in the esx portion.
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param column string
--- @return string|nil
2025-01-08 06:33:31 -05:00
Framework.GetStatus = function ( src , column )
2025-08-31 18:41:12 +01:00
--[[
defualt esx Available tables are:
identifier, accounts, group, inventory, job, job_grade, loadout, metadata, position,
firstname, lastname, dateofbirth, sex, height, skin, status, is_dead, id, disabled,
last_property, created_at, last_seen, phone_number, pincode
]]
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-03-03 02:05:53 -05:00
if not xPlayer then return end
2025-01-08 06:33:31 -05:00
return xPlayer.get ( column ) or nil
end
2025-12-14 16:22:35 -05:00
---@description This will return a boolean if the player is dead or in last stand.
2025-08-31 18:41:12 +01:00
--- @param src number
2025-12-14 16:22:35 -05:00
--- @return boolean
2025-05-02 03:13:07 -05:00
Framework.GetIsPlayerDead = function ( src )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return false end
2025-05-02 03:13:07 -05:00
return xPlayer.get ( "is_dead" ) or false
end
2025-12-14 16:22:35 -05:00
---@description This will revive a player, if the player is dead or in last stand.
2025-08-31 18:41:12 +01:00
--- @param src number
--- @return boolean
2025-05-09 19:06:50 -05:00
Framework.RevivePlayer = function ( src )
src = tonumber ( src )
if not src then return false end
2025-05-09 20:09:57 -05:00
TriggerEvent ( 'esx_ambulancejob:revive' , src )
2025-05-09 19:06:50 -05:00
return true
end
2025-08-31 18:41:12 +01:00
--- @description Adds the specified value from the player's thirst level
--- @param src number
--- @param value number
--- @return number | nil
2025-01-08 06:33:31 -05:00
Framework.AddThirst = function ( src , value )
local clampIT = Math.Clamp ( value , 0 , 200000 )
local levelForEsx = clampIT * 2000
TriggerClientEvent ( 'esx_status:add' , src , 'thirst' , levelForEsx )
return levelForEsx
end
2025-08-31 18:41:12 +01:00
--- @description Adds the specified value from the player's hunger level
--- @param src number
--- @param value number
--- @return number | nil
2025-01-08 06:33:31 -05:00
Framework.AddHunger = function ( src , value )
local clampIT = Math.Clamp ( value , 0 , 200000 )
local levelForEsx = clampIT * 2000
TriggerClientEvent ( 'esx_status:add' , src , 'hunger' , levelForEsx )
return levelForEsx
end
2025-12-14 16:22:35 -05:00
---@description This will get the hunger of a player
2025-08-31 18:41:12 +01:00
--- @param src number
2025-12-14 16:22:35 -05:00
--- @return number
2025-01-08 06:33:31 -05:00
Framework.GetHunger = function ( src )
2025-09-04 08:15:02 -04:00
local status = Framework.GetStatus ( src , "status" )
2025-12-14 16:22:35 -05:00
if not status then return 0 end
if type ( status ) ~= "table" then return 0 end
2025-09-01 14:22:03 +01:00
for _ , entry in ipairs ( status ) do
if entry.name == "hunger" then
2025-09-04 07:27:40 -04:00
return math.floor (( entry.percent ) + 0.5 ) or 0
2025-09-01 14:22:03 +01:00
end
end
2025-01-08 06:33:31 -05:00
end
2025-12-14 16:22:35 -05:00
---@description This will get the thirst of a player
2025-08-31 18:41:12 +01:00
--- @param src any
2025-12-14 16:22:35 -05:00
--- @return number
2025-01-08 06:33:31 -05:00
Framework.GetThirst = function ( src )
2025-09-04 08:15:02 -04:00
local status = Framework.GetStatus ( src , "status" )
2025-12-14 16:22:35 -05:00
if not status then return 0 end
if type ( status ) ~= "table" then return 0 end
2025-09-01 14:22:03 +01:00
for _ , entry in ipairs ( status ) do
if entry.name == "thirst" then
2025-09-04 07:27:40 -04:00
return math.floor (( entry.percent ) + 0.5 ) or 0
2025-09-01 14:22:03 +01:00
end
end
2025-01-08 06:33:31 -05:00
end
2025-12-14 16:22:35 -05:00
---@description Returns the phone number of the player.
2025-08-31 18:41:12 +01:00
--- @param src number
2025-12-14 16:22:35 -05:00
--- @return string | nil
2025-01-08 06:33:31 -05:00
Framework.GetPlayerPhone = function ( src )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-03-03 02:05:53 -05:00
if not xPlayer then return end
2025-01-08 06:33:31 -05:00
return xPlayer.get ( "phone_number" )
end
2026-08-17 03:49:37 -07:00
Framework.GetPlayerPhoneByIdentifier = function ( citizenid )
local xPlayer = Framework.GetPlayerByIdentifier ( citizenid )
if xPlayer then
return xPlayer.get ( "phone_number" )
end
local result = MySQL.single . await ( "SELECT phone_number FROM users WHERE identifier = @identifier" , {[ "@identifier" ] = citizenid })
return result and result.phone_number or nil
end
2025-12-14 16:22:35 -05:00
---@description This will return the job name, label, grade name, and grade level of the player.
---@deprecated
2025-04-15 08:04:43 -04:00
---@param src number
---@return string | nil
---@return string | nil
---@return string | nil
---@return string | nil
2025-01-08 06:33:31 -05:00
Framework.GetPlayerJob = function ( src )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-03-03 02:05:53 -05:00
if not xPlayer then return end
2025-04-15 08:04:43 -04:00
local job = xPlayer.getJob ()
return job.name , job.label , job.grade_label , job.grade
end
2025-12-14 16:22:35 -05:00
---@description This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table
2025-08-31 18:41:12 +01:00
--- @param src number
2025-12-14 16:22:35 -05:00
--- @return table {jobName, jobLabel, gradeName, gradeLabel, gradeRank, boss, onDuty}
2025-05-14 04:48:23 -04:00
Framework.GetPlayerJobData = function ( src )
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return {} end
2025-05-14 04:48:23 -04:00
local job = xPlayer.getJob ()
local isBoss = ( job.grade_name == "boss" )
return {
jobName = job.name ,
jobLabel = job.label ,
gradeName = job.grade_name ,
gradeLabel = job.grade_label ,
gradeRank = job.grade ,
boss = isBoss ,
onDuty = job.onduty ,
}
end
2025-12-14 16:22:35 -05:00
---@description Returns the players duty status.
2025-08-31 18:41:12 +01:00
--- @param src number
2025-12-14 16:22:35 -05:00
--- @return boolean
2025-04-15 08:04:43 -04:00
Framework.GetPlayerDuty = function ( src )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-04-15 08:04:43 -04:00
if not xPlayer then return false end
local job = xPlayer.getJob ()
if not job.onDuty then return false end
return true
end
2025-12-14 16:22:35 -05:00
---@description This will toggle a players duty status
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param status boolean
--- @return boolean
2025-06-21 07:53:49 -04:00
Framework.SetPlayerDuty = function ( src , status )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-04-15 08:04:43 -04:00
if not xPlayer then return false end
local job = xPlayer.getJob ()
2025-08-17 02:32:07 -04:00
if job.name == 'unemployed' then return false end
2025-06-21 07:53:49 -04:00
xPlayer.setJob ( job.name , job.grade , status )
2025-06-11 21:03:19 +03:00
return true
2025-01-08 06:33:31 -05:00
end
2025-12-14 16:22:35 -05:00
---@description Returns the gang name of the player.
---@param src number
---@return string | nil
Framework.GetPlayerGang = function ( src )
print ( "ESX does not support gangs, please ensure you are using a supported gang system or that you have the correct start order." )
return
end
2026-08-17 03:49:37 -07:00
Framework.GetPlayerGangByIdentifier = function ( citizenid )
print ( "ESX does not support gangs, please ensure you are using a supported gang system or that you have the correct start order." )
return
end
2025-12-14 16:22:35 -05:00
---@description This will get a table of player sources that have the specified job name.
2025-08-31 18:41:12 +01:00
--- @param job string
--- @return table
2025-01-08 06:33:31 -05:00
Framework.GetPlayersByJob = function ( job )
2025-08-07 00:47:51 -04:00
return Framework.GetPlayerSourcesByJob ( job ) or {}
2025-01-08 06:33:31 -05:00
end
2025-12-14 16:22:35 -05:00
---@description Sets the player's job to the specified name and grade.
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param name string
--- @param grade string
2025-01-08 06:33:31 -05:00
Framework.SetPlayerJob = function ( src , name , grade )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-03-03 02:05:53 -05:00
if not xPlayer then return end
2025-05-09 22:27:48 -03:00
if not ESX.DoesJobExist ( name , grade ) then
2025-12-14 16:22:35 -05:00
print ( "^6 Job Does Not Exsist In Framework :NAME " .. name .. " Grade:" .. grade .. " ^0 " )
2025-05-09 22:27:48 -03:00
return
end
2025-06-11 21:03:19 +03:00
xPlayer.setJob ( name , grade , true )
2025-08-07 00:47:51 -04:00
return true
2025-01-12 12:55:29 -05:00
end
2025-12-14 16:22:35 -05:00
---@description This will add money based on the type of account (money/bank)
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param _type string
--- @param amount number
2025-12-14 16:22:35 -05:00
--- @return boolean
2025-01-08 06:33:31 -05:00
Framework.AddAccountBalance = function ( src , _type , amount )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return false end
2025-05-05 10:45:00 -04:00
if _type == 'cash' then _type = 'money' end
2025-12-14 16:22:35 -05:00
if amount <= 0 then return false end
2025-06-11 21:03:19 +03:00
xPlayer.addAccountMoney ( _type , amount )
return true
2025-01-08 06:33:31 -05:00
end
2026-08-17 03:49:37 -07:00
---@description This will add money based on the type of account (money/bank)
--- @param src number
--- @param _type string
--- @param amount number
--- @return boolean
Framework.AddAccountBalanceByIdentifier = function ( src , _type , amount )
local xPlayer = Framework.GetPlayer ( src )
if _type == 'cash' then _type = 'money' end
if amount <= 0 then return false end
if xPlayer then
xPlayer.addAccountMoney ( _type , amount )
return true
end
local money = MySQL.single . await ( "SELECT accounts FROM users WHERE identifier = @identifier" , {[ "@identifier" ] = src })
if not money then return false end
local accounts = json.decode ( money.accounts )
accounts [ _type ] = ( accounts [ _type ] or 0 ) + amount
MySQL.update . await ( "UPDATE users SET accounts = @accounts WHERE identifier = @identifier" , {[ "@accounts" ] = json.encode ( accounts ), [ "@identifier" ] = src })
return true
end
2025-12-14 16:22:35 -05:00
---@description This will remove money based on the type of account (money/bank)
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param _type string
--- @param amount number
2025-12-14 16:22:35 -05:00
--- @return boolean
2025-01-08 06:33:31 -05:00
Framework.RemoveAccountBalance = function ( src , _type , amount )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return false end
2025-05-05 10:45:00 -04:00
if _type == 'cash' then _type = 'money' end
2025-12-14 16:22:35 -05:00
if amount <= 0 then return false end
local accountVal = Framework.GetAccountBalance ( src , _type )
if accountVal < amount then return false end
2025-05-01 11:44:22 -04:00
xPlayer.removeAccountMoney ( _type , amount )
return true
2025-01-08 06:33:31 -05:00
end
2026-08-17 03:49:37 -07:00
---@description This will remove money based on the type of account (money/bank)
--- @param src number
--- @param _type string
--- @param amount number
--- @return boolean
Framework.RemoveAccountBalanceByIdentifier = function ( src , _type , amount )
local xPlayer = Framework.GetPlayer ( src )
if _type == 'cash' then _type = 'money' end
if amount <= 0 then return false end
if xPlayer then
local accountVal = Framework.GetAccountBalance ( src , _type )
if accountVal < amount then return false end
xPlayer.removeAccountMoney ( _type , amount )
return true
end
local money = MySQL.single . await ( "SELECT accounts FROM users WHERE identifier = @identifier" , {[ "@identifier" ] = src })
if not money then return false end
local accounts = json.decode ( money.accounts )
if ( accounts [ _type ] or 0 ) < amount then return false end
accounts [ _type ] = ( accounts [ _type ] or 0 ) - amount
MySQL.update . await ( "UPDATE users SET accounts = @accounts WHERE identifier = @identifier" , {[ "@accounts" ] = json.encode ( accounts ), [ "@identifier" ] = src })
return true
end
2025-12-14 16:22:35 -05:00
---@description This will get money based on the type of account (money/bank)
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param _type string
2025-12-14 16:22:35 -05:00
--- @return number
2025-01-08 06:33:31 -05:00
Framework.GetAccountBalance = function ( src , _type )
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return 0 end
2025-05-05 10:45:00 -04:00
if _type == 'cash' then _type = 'money' end
2025-12-14 16:22:35 -05:00
local balance = xPlayer.getAccount ( _type ). money or 0
if balance <= 0 then return 0 end
return balance
2025-01-08 06:33:31 -05:00
end
2026-08-17 03:49:37 -07:00
Framework.GetAccountBalanceByIdentifier = function ( src , _type )
local xPlayer = Framework.GetPlayerByIdentifier ( src )
if _type == 'cash' then _type = 'money' end
if xPlayer then
local balance = xPlayer.getAccount ( _type ). money or 0
if balance <= 0 then return 0 end
return balance
end
local money = MySQL.single . await ( "SELECT accounts FROM users WHERE identifier = @identifier" , {[ "@identifier" ] = src })
if not money then return 0 end
local accounts = json.decode ( money.accounts )
return accounts [ _type ] or 0
end
2025-12-14 16:22:35 -05:00
---@description This will add an item, and return true or false based on success
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
---@param src number
---@param item string
---@param count number
---@param slot number (optional)
---@param metadata table (optional)
---@return boolean
Framework.AddItem = function ( src , item , count , slot , metadata )
if slot then print ( "ESX does not support item slots, please ensure you are using a supported inventory system or that you have the correct start order." ) end
if metadata then print ( "ESX does not support item metadata, please ensure you are using a supported inventory system or that you have the correct start order." ) end
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return false end
xPlayer.addInventoryItem ( item , count )
TriggerClientEvent ( "community_bridge:client:inventory:updateInventory" , src , { action = "add" , item = item , count = count , slot = slot , metadata = metadata })
2025-06-11 21:03:19 +03:00
return true
2025-01-08 06:33:31 -05:00
end
2025-12-14 16:22:35 -05:00
---@description Removes the specified item from the player's inventory.
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
2025-08-31 18:41:12 +01:00
--- @param src number
--- @param item string
--- @param amount number
2025-12-14 16:22:35 -05:00
--- @param slot number (optional)
--- @param metadata table (optional)
--- @return boolean
2025-01-08 06:33:31 -05:00
Framework.RemoveItem = function ( src , item , amount , slot , metadata )
2025-12-14 16:22:35 -05:00
if slot then
print ( "ESX does not support item slots, please ensure you are using a supported inventory system or that you have the correct start order." )
end
if metadata then
print ( "ESX does not support item metadata, please ensure you are using a supported inventory system or that you have the correct start order." )
end
2025-05-13 01:06:52 -04:00
local xPlayer = Framework.GetPlayer ( src )
2025-12-14 16:22:35 -05:00
if not xPlayer then return false end
2025-06-11 21:03:19 +03:00
xPlayer.removeInventoryItem ( item , amount )
return true
2025-01-08 06:33:31 -05:00
end
2025-12-14 16:22:35 -05:00
---@description Sets the metadata for the specified item in the player's inventory.
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
--- @param src number
--- @param item string
--- @param slot number
--- @param metadata table
--- @return boolean
Framework.SetMetadata = function ( src , item , slot , metadata )
print ( "ESX does not support item metadata, please ensure you are using a supported inventory system or that you have the correct start order." )
return false
end
---@description This will get all owned vehicles for the player
2025-08-31 18:41:12 +01:00
--- @param src number
--- @return table
2025-02-03 10:26:05 -05:00
Framework.GetOwnedVehicles = function ( src )
local citizenId = Framework.GetPlayerIdentifier ( src )
local result = MySQL.Sync . fetchAll ( "SELECT vehicle, plate FROM owned_vehicles WHERE owner = '" .. citizenId .. "'" )
2025-05-09 22:27:48 -03:00
local vehicles = {}
for i = 1 , # result do
2025-02-03 10:26:05 -05:00
local vehicle = result [ i ]. vehicle
local plate = result [ i ]. plate
local model = json.decode ( vehicle ). model
2025-05-09 22:27:48 -03:00
table.insert ( vehicles , { vehicle = model , plate = plate })
2025-02-03 10:26:05 -05:00
end
2025-05-09 22:27:48 -03:00
return vehicles
2025-02-03 10:26:05 -05:00
end
2025-12-28 17:10:26 +01:00
---@description Returns a table of owned vehicles for the player. format is {id = id, vehicle = model, plate = plate}
---@param src number
---@param plate string
---@return table
Framework.IsVehicleOwnedByPlayer = function ( src , plate )
local citizenId = Framework.GetPlayerIdentifier ( src )
local result = MySQL.Sync . fetchAll ( "SELECT id, vehicle, plate FROM owned_vehicles WHERE owner = '" .. citizenId .. "' AND plate = '" .. plate .. "'" )
if not result [ 1 ] then return false end
local id = result [ 1 ]. id
local vehicle = result [ 1 ]. vehicle
local model = json.decode ( vehicle ). model
return { id = id , vehicle = model , plate = plate }
end
2025-12-14 16:22:35 -05:00
---@description Registers a usable item with a callback function.
2025-08-31 18:41:12 +01:00
--- @param itemName string
--- @param cb function
2025-01-14 10:55:14 -06:00
Framework.RegisterUsableItem = function ( itemName , cb )
local func = function ( src , item , itemData )
itemData = itemData or item
itemData.metadata = itemData.metadata or itemData.info or {}
2025-05-06 14:39:29 -04:00
itemData.slot = itemData.id or itemData.slot
2025-01-26 12:07:26 -06:00
cb ( src , itemData )
2025-01-14 10:55:14 -06:00
end
ESX.RegisterUsableItem ( itemName , func )
2025-01-12 13:01:16 -05:00
end
2025-12-14 16:22:35 -05:00
---@description Event handler for when a player is loaded in ESX framework
---@param src number
2025-06-02 22:19:42 -05:00
RegisterNetEvent ( "esx:playerLoaded" , function ( src )
src = src or source
2025-03-09 23:13:03 -05:00
TriggerEvent ( "community_bridge:Server:OnPlayerLoaded" , src )
2025-08-31 19:17:01 -04:00
local jobData = Framework.GetPlayerJobData ( src )
if not jobData then return end
Framework.AddJobCount ( src , jobData.jobName )
2025-03-09 23:13:03 -05:00
end )
2025-12-14 16:22:35 -05:00
---@description Event handler for when a player logs out in ESX framework
---@param src number
2025-06-02 22:19:42 -05:00
RegisterNetEvent ( "esx:playerLogout" , function ( src )
src = src or source
2025-02-10 02:02:33 -05:00
TriggerEvent ( "community_bridge:Server:OnPlayerUnload" , src )
2025-01-27 14:41:16 -05:00
end )
2025-12-14 16:22:35 -05:00
---@description Event handler for when a player's job is updated in ESX framework
---@param src number
---@param job table
---@param lastJob table
2025-08-04 01:32:30 -04:00
RegisterNetEvent ( "esx:setJob" , function ( src , job , lastJob )
src = src or source
if not job or not lastJob then return end
TriggerEvent ( "community_bridge:Server:OnPlayerJobChange" , src , job.name )
end )
2025-12-14 16:22:35 -05:00
---@description Event handler for when a player disconnects from the server
2025-01-27 18:42:38 -05:00
AddEventHandler ( "playerDropped" , function ()
local src = source
TriggerEvent ( "community_bridge:Server:OnPlayerUnload" , src )
end )
2025-12-14 16:22:35 -05:00
---@description Callback to get framework jobs list
---@param source number
2026-08-17 03:49:37 -07:00
lib.callback . register ( 'community_bridge:Callback:GetFrameworkJobs' , function ( source )
2025-05-09 22:27:48 -03:00
return Framework.GetFrameworkJobs () or {}
2025-03-10 01:17:18 -04:00
end )
2025-12-14 16:22:35 -05:00
---@description This is linked to an internal function, its an attempt to standardize the item list across frameworks.
---@param source number
2026-08-17 03:49:37 -07:00
lib.callback . register ( 'community_bridge:Callback:GetFrameworkItems' , function ( source )
2025-07-09 22:08:44 -04:00
return Framework.ItemList () or {}
end )
2025-01-12 13:01:16 -05:00
Framework.Commands = {}
2025-12-14 16:22:35 -05:00
---@description Adds a command to the ESX framework
---@param name string
---@param help string
---@param arguments table
---@param argsrequired boolean
---@param callback function
---@param permission string
---@param ... any
2025-01-12 13:01:16 -05:00
Framework.Commands . Add = function ( name , help , arguments , argsrequired , callback , permission , ...)
ESX.RegisterCommand ( name , permission , function ( xPlayer , args , showError )
callback ( xPlayer , args )
end , false , {
help = help ,
arguments = arguments
})
2025-05-10 00:01:56 -04:00
end
2025-05-11 20:18:46 -04:00
2025-06-11 21:03:19 +03:00
return Framework