mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 02:01:33 +00:00
Core object filtering + exported functions/data
Maintains backwards compatibility and allows users to only get what they need from the core instead of importing it all
This commit is contained in:
@@ -1094,3 +1094,12 @@ function QBCore.Functions.GetGroundHash(entity)
|
|||||||
local retval, success, endCoords, surfaceNormal, materialHash, entityHit = GetShapeTestResultEx(num)
|
local retval, success, endCoords, surfaceNormal, materialHash, entityHit = GetShapeTestResultEx(num)
|
||||||
return materialHash, entityHit, surfaceNormal, endCoords, success, retval
|
return materialHash, entityHit, surfaceNormal, endCoords, success, retval
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for functionName, func in pairs(QBCore.Functions) do
|
||||||
|
if type(func) == 'function' then
|
||||||
|
exports(functionName, func)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Access a specific function directly:
|
||||||
|
-- exports['qb-core']:Notify('Hello Player!')
|
||||||
|
|||||||
+42
-6
@@ -5,10 +5,46 @@ QBCore.Shared = QBShared
|
|||||||
QBCore.ClientCallbacks = {}
|
QBCore.ClientCallbacks = {}
|
||||||
QBCore.ServerCallbacks = {}
|
QBCore.ServerCallbacks = {}
|
||||||
|
|
||||||
exports('GetCoreObject', function()
|
-- Get the full QBCore object (default behavior):
|
||||||
return QBCore
|
-- local QBCore = GetCoreObject()
|
||||||
end)
|
|
||||||
|
|
||||||
-- To use this export in a script instead of manifest method
|
-- Get only specific parts of QBCore:
|
||||||
-- Just put this line of code below at the very top of the script
|
-- local QBCore = GetCoreObject({'Players', 'Config'})
|
||||||
-- local QBCore = exports['qb-core']:GetCoreObject()
|
|
||||||
|
local function GetCoreObject(filters)
|
||||||
|
if not filters then return QBCore end
|
||||||
|
local results = {}
|
||||||
|
for i = 1, #filters do
|
||||||
|
local key = filters[i]
|
||||||
|
if QBCore[key] then
|
||||||
|
results[key] = QBCore[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return results
|
||||||
|
end
|
||||||
|
exports('GetCoreObject', GetCoreObject)
|
||||||
|
|
||||||
|
local function GetSharedItems()
|
||||||
|
return QBShared.Items
|
||||||
|
end
|
||||||
|
exports('GetSharedItems', GetSharedItems)
|
||||||
|
|
||||||
|
local function GetSharedVehicles()
|
||||||
|
return QBShared.Vehicles
|
||||||
|
end
|
||||||
|
exports('GetSharedVehicles', GetSharedVehicles)
|
||||||
|
|
||||||
|
local function GetSharedWeapons()
|
||||||
|
return QBShared.Weapons
|
||||||
|
end
|
||||||
|
exports('GetSharedWeapons', GetSharedWeapons)
|
||||||
|
|
||||||
|
local function GetSharedJobs()
|
||||||
|
return QBShared.Jobs
|
||||||
|
end
|
||||||
|
exports('GetSharedJobs', GetSharedJobs)
|
||||||
|
|
||||||
|
local function GetSharedGangs()
|
||||||
|
return QBShared.Gangs
|
||||||
|
end
|
||||||
|
exports('GetSharedGangs', GetSharedGangs)
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ game 'gta5'
|
|||||||
lua54 'yes'
|
lua54 'yes'
|
||||||
author 'Kakarot'
|
author 'Kakarot'
|
||||||
description 'Core resource for the framework, contains all the core functionality and features'
|
description 'Core resource for the framework, contains all the core functionality and features'
|
||||||
version '1.2.6'
|
version '1.3.0'
|
||||||
|
|
||||||
shared_scripts {
|
shared_scripts {
|
||||||
'config.lua',
|
'config.lua',
|
||||||
|
|||||||
+36
-30
@@ -394,33 +394,30 @@ function QBCore.Functions.CreateVehicle(source, model, vehtype, coords, warp)
|
|||||||
return veh
|
return veh
|
||||||
end
|
end
|
||||||
|
|
||||||
---Paychecks (standalone - don't touch)
|
|
||||||
function PaycheckInterval()
|
function PaycheckInterval()
|
||||||
if next(QBCore.Players) then
|
if not next(QBCore.Players) then return end
|
||||||
for _, Player in pairs(QBCore.Players) do
|
for _, Player in pairs(QBCore.Players) do
|
||||||
if Player then
|
if not Player then return end
|
||||||
local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
|
local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
|
||||||
if not payment then payment = Player.PlayerData.job.payment end
|
if not payment then payment = Player.PlayerData.job.payment end
|
||||||
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
|
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
|
||||||
if QBCore.Config.Money.PayCheckSociety then
|
if QBCore.Config.Money.PayCheckSociety then
|
||||||
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
|
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
|
||||||
if account ~= 0 then -- Checks if player is employed by a society
|
if account ~= 0 then
|
||||||
if account < payment then -- Checks if company has enough money to pay society
|
if account < payment then
|
||||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
|
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
|
||||||
else
|
|
||||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
|
||||||
exports['qb-banking']:RemoveMoney(Player.PlayerData.job.name, payment, 'Employee Paycheck')
|
|
||||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
|
||||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||||
|
exports['qb-banking']:RemoveMoney(Player.PlayerData.job.name, payment, 'Employee Paycheck')
|
||||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||||
|
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||||
|
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -471,7 +468,7 @@ end
|
|||||||
function QBCore.Functions.CreateUseableItem(item, data)
|
function QBCore.Functions.CreateUseableItem(item, data)
|
||||||
local rawFunc = nil
|
local rawFunc = nil
|
||||||
|
|
||||||
if type(data) == "table" then
|
if type(data) == 'table' then
|
||||||
if rawget(data, '__cfx_functionReference') then
|
if rawget(data, '__cfx_functionReference') then
|
||||||
rawFunc = data
|
rawFunc = data
|
||||||
elseif data.cb and rawget(data.cb, '__cfx_functionReference') then
|
elseif data.cb and rawget(data.cb, '__cfx_functionReference') then
|
||||||
@@ -479,7 +476,7 @@ function QBCore.Functions.CreateUseableItem(item, data)
|
|||||||
elseif data.callback and rawget(data.callback, '__cfx_functionReference') then
|
elseif data.callback and rawget(data.callback, '__cfx_functionReference') then
|
||||||
rawFunc = data.callback
|
rawFunc = data.callback
|
||||||
end
|
end
|
||||||
elseif type(data) == "function" then
|
elseif type(data) == 'function' then
|
||||||
rawFunc = data
|
rawFunc = data
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -654,23 +651,23 @@ end
|
|||||||
function QBCore.Functions.GetDatabaseInfo()
|
function QBCore.Functions.GetDatabaseInfo()
|
||||||
local details = {
|
local details = {
|
||||||
exists = false,
|
exists = false,
|
||||||
database = "",
|
database = '',
|
||||||
}
|
}
|
||||||
local connectionString = GetConvar("mysql_connection_string", "")
|
local connectionString = GetConvar('mysql_connection_string', '')
|
||||||
|
|
||||||
if connectionString == "" then
|
if connectionString == '' then
|
||||||
return details
|
return details
|
||||||
elseif connectionString:find("mysql://") then
|
elseif connectionString:find('mysql://') then
|
||||||
connectionString = connectionString:sub(9, -1)
|
connectionString = connectionString:sub(9, -1)
|
||||||
details.database = connectionString:sub(connectionString:find("/") + 1, -1):gsub("[%?]+[%w%p]*$", "")
|
details.database = connectionString:sub(connectionString:find('/') + 1, -1):gsub('[%?]+[%w%p]*$', '')
|
||||||
details.exists = true
|
details.exists = true
|
||||||
return details
|
return details
|
||||||
else
|
else
|
||||||
connectionString = { string.strsplit(";", connectionString) }
|
connectionString = { string.strsplit(';', connectionString) }
|
||||||
|
|
||||||
for i = 1, #connectionString do
|
for i = 1, #connectionString do
|
||||||
local v = connectionString[i]
|
local v = connectionString[i]
|
||||||
if v:match("database") then
|
if v:match('database') then
|
||||||
details.database = v:sub(10, #v)
|
details.database = v:sub(10, #v)
|
||||||
details.exists = true
|
details.exists = true
|
||||||
return details
|
return details
|
||||||
@@ -728,3 +725,12 @@ function QBCore.Functions.PrepForSQL(source, data, pattern)
|
|||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for functionName, func in pairs(QBCore.Functions) do
|
||||||
|
if type(func) == 'function' then
|
||||||
|
exports(functionName, func)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Access a specific function directly:
|
||||||
|
-- exports['qb-core']:Notify(source, 'Hello Player!')
|
||||||
|
|||||||
+42
-6
@@ -4,10 +4,46 @@ QBCore.Shared = QBShared
|
|||||||
QBCore.ClientCallbacks = {}
|
QBCore.ClientCallbacks = {}
|
||||||
QBCore.ServerCallbacks = {}
|
QBCore.ServerCallbacks = {}
|
||||||
|
|
||||||
exports('GetCoreObject', function()
|
-- Get the full QBCore object (default behavior):
|
||||||
return QBCore
|
-- local QBCore = GetCoreObject()
|
||||||
end)
|
|
||||||
|
|
||||||
-- To use this export in a script instead of manifest method
|
-- Get only specific parts of QBCore:
|
||||||
-- Just put this line of code below at the very top of the script
|
-- local QBCore = GetCoreObject({'Players', 'Config'})
|
||||||
-- local QBCore = exports['qb-core']:GetCoreObject()
|
|
||||||
|
local function GetCoreObject(filters)
|
||||||
|
if not filters then return QBCore end
|
||||||
|
local results = {}
|
||||||
|
for i = 1, #filters do
|
||||||
|
local key = filters[i]
|
||||||
|
if QBCore[key] then
|
||||||
|
results[key] = QBCore[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return results
|
||||||
|
end
|
||||||
|
exports('GetCoreObject', GetCoreObject)
|
||||||
|
|
||||||
|
local function GetSharedItems()
|
||||||
|
return QBShared.Items
|
||||||
|
end
|
||||||
|
exports('GetSharedItems', GetSharedItems)
|
||||||
|
|
||||||
|
local function GetSharedVehicles()
|
||||||
|
return QBShared.Vehicles
|
||||||
|
end
|
||||||
|
exports('GetSharedVehicles', GetSharedVehicles)
|
||||||
|
|
||||||
|
local function GetSharedWeapons()
|
||||||
|
return QBShared.Weapons
|
||||||
|
end
|
||||||
|
exports('GetSharedWeapons', GetSharedWeapons)
|
||||||
|
|
||||||
|
local function GetSharedJobs()
|
||||||
|
return QBShared.Jobs
|
||||||
|
end
|
||||||
|
exports('GetSharedJobs', GetSharedJobs)
|
||||||
|
|
||||||
|
local function GetSharedGangs()
|
||||||
|
return QBShared.Gangs
|
||||||
|
end
|
||||||
|
exports('GetSharedGangs', GetSharedGangs)
|
||||||
|
|||||||
Reference in New Issue
Block a user