Skip to content

Commit 9adb33b

Browse files
committed
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
1 parent 47cf3ac commit 9adb33b

File tree

5 files changed

+130
-43
lines changed

5 files changed

+130
-43
lines changed

client/functions.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,3 +1094,12 @@ function QBCore.Functions.GetGroundHash(entity)
10941094
local retval, success, endCoords, surfaceNormal, materialHash, entityHit = GetShapeTestResultEx(num)
10951095
return materialHash, entityHit, surfaceNormal, endCoords, success, retval
10961096
end
1097+
1098+
for functionName, func in pairs(QBCore.Functions) do
1099+
if type(func) == 'function' then
1100+
exports(functionName, func)
1101+
end
1102+
end
1103+
1104+
-- Access a specific function directly:
1105+
-- exports['qb-core']:Notify('Hello Player!')

client/main.lua

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,46 @@ QBCore.Shared = QBShared
55
QBCore.ClientCallbacks = {}
66
QBCore.ServerCallbacks = {}
77

8-
exports('GetCoreObject', function()
9-
return QBCore
10-
end)
8+
-- Get the full QBCore object (default behavior):
9+
-- local QBCore = GetCoreObject()
1110

12-
-- To use this export in a script instead of manifest method
13-
-- Just put this line of code below at the very top of the script
14-
-- local QBCore = exports['qb-core']:GetCoreObject()
11+
-- Get only specific parts of QBCore:
12+
-- local QBCore = GetCoreObject({'Players', 'Config'})
13+
14+
local function GetCoreObject(filters)
15+
if not filters then return QBCore end
16+
local results = {}
17+
for i = 1, #filters do
18+
local key = filters[i]
19+
if QBCore[key] then
20+
results[key] = QBCore[key]
21+
end
22+
end
23+
return results
24+
end
25+
exports('GetCoreObject', GetCoreObject)
26+
27+
local function GetSharedItems()
28+
return QBShared.Items
29+
end
30+
exports('GetSharedItems', GetSharedItems)
31+
32+
local function GetSharedVehicles()
33+
return QBShared.Vehicles
34+
end
35+
exports('GetSharedVehicles', GetSharedVehicles)
36+
37+
local function GetSharedWeapons()
38+
return QBShared.Weapons
39+
end
40+
exports('GetSharedWeapons', GetSharedWeapons)
41+
42+
local function GetSharedJobs()
43+
return QBShared.Jobs
44+
end
45+
exports('GetSharedJobs', GetSharedJobs)
46+
47+
local function GetSharedGangs()
48+
return QBShared.Gangs
49+
end
50+
exports('GetSharedGangs', GetSharedGangs)

fxmanifest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ game 'gta5'
33
lua54 'yes'
44
author 'Kakarot'
55
description 'Core resource for the framework, contains all the core functionality and features'
6-
version '1.2.6'
6+
version '1.3.0'
77

88
shared_scripts {
99
'config.lua',

server/functions.lua

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -394,33 +394,30 @@ function QBCore.Functions.CreateVehicle(source, model, vehtype, coords, warp)
394394
return veh
395395
end
396396

397-
---Paychecks (standalone - don't touch)
398397
function PaycheckInterval()
399-
if next(QBCore.Players) then
400-
for _, Player in pairs(QBCore.Players) do
401-
if Player then
402-
local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
403-
if not payment then payment = Player.PlayerData.job.payment end
404-
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
405-
if QBCore.Config.Money.PayCheckSociety then
406-
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
407-
if account ~= 0 then -- Checks if player is employed by a society
408-
if account < payment then -- Checks if company has enough money to pay society
409-
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
410-
else
411-
Player.Functions.AddMoney('bank', payment, 'paycheck')
412-
exports['qb-banking']:RemoveMoney(Player.PlayerData.job.name, payment, 'Employee Paycheck')
413-
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
414-
end
415-
else
416-
Player.Functions.AddMoney('bank', payment, 'paycheck')
417-
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
418-
end
398+
if not next(QBCore.Players) then return end
399+
for _, Player in pairs(QBCore.Players) do
400+
if not Player then return end
401+
local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
402+
if not payment then payment = Player.PlayerData.job.payment end
403+
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
404+
if QBCore.Config.Money.PayCheckSociety then
405+
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
406+
if account ~= 0 then
407+
if account < payment then
408+
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
419409
else
420410
Player.Functions.AddMoney('bank', payment, 'paycheck')
411+
exports['qb-banking']:RemoveMoney(Player.PlayerData.job.name, payment, 'Employee Paycheck')
421412
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
422413
end
414+
else
415+
Player.Functions.AddMoney('bank', payment, 'paycheck')
416+
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
423417
end
418+
else
419+
Player.Functions.AddMoney('bank', payment, 'paycheck')
420+
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
424421
end
425422
end
426423
end
@@ -471,15 +468,15 @@ end
471468
function QBCore.Functions.CreateUseableItem(item, data)
472469
local rawFunc = nil
473470

474-
if type(data) == "table" then
471+
if type(data) == 'table' then
475472
if rawget(data, '__cfx_functionReference') then
476473
rawFunc = data
477474
elseif data.cb and rawget(data.cb, '__cfx_functionReference') then
478475
rawFunc = data.cb
479476
elseif data.callback and rawget(data.callback, '__cfx_functionReference') then
480477
rawFunc = data.callback
481478
end
482-
elseif type(data) == "function" then
479+
elseif type(data) == 'function' then
483480
rawFunc = data
484481
end
485482

@@ -654,23 +651,23 @@ end
654651
function QBCore.Functions.GetDatabaseInfo()
655652
local details = {
656653
exists = false,
657-
database = "",
654+
database = '',
658655
}
659-
local connectionString = GetConvar("mysql_connection_string", "")
656+
local connectionString = GetConvar('mysql_connection_string', '')
660657

661-
if connectionString == "" then
658+
if connectionString == '' then
662659
return details
663-
elseif connectionString:find("mysql://") then
660+
elseif connectionString:find('mysql://') then
664661
connectionString = connectionString:sub(9, -1)
665-
details.database = connectionString:sub(connectionString:find("/") + 1, -1):gsub("[%?]+[%w%p]*$", "")
662+
details.database = connectionString:sub(connectionString:find('/') + 1, -1):gsub('[%?]+[%w%p]*$', '')
666663
details.exists = true
667664
return details
668665
else
669-
connectionString = { string.strsplit(";", connectionString) }
666+
connectionString = { string.strsplit(';', connectionString) }
670667

671668
for i = 1, #connectionString do
672669
local v = connectionString[i]
673-
if v:match("database") then
670+
if v:match('database') then
674671
details.database = v:sub(10, #v)
675672
details.exists = true
676673
return details
@@ -728,3 +725,12 @@ function QBCore.Functions.PrepForSQL(source, data, pattern)
728725
end
729726
return true
730727
end
728+
729+
for functionName, func in pairs(QBCore.Functions) do
730+
if type(func) == 'function' then
731+
exports(functionName, func)
732+
end
733+
end
734+
735+
-- Access a specific function directly:
736+
-- exports['qb-core']:Notify(source, 'Hello Player!')

server/main.lua

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,46 @@ QBCore.Shared = QBShared
44
QBCore.ClientCallbacks = {}
55
QBCore.ServerCallbacks = {}
66

7-
exports('GetCoreObject', function()
8-
return QBCore
9-
end)
7+
-- Get the full QBCore object (default behavior):
8+
-- local QBCore = GetCoreObject()
109

11-
-- To use this export in a script instead of manifest method
12-
-- Just put this line of code below at the very top of the script
13-
-- local QBCore = exports['qb-core']:GetCoreObject()
10+
-- Get only specific parts of QBCore:
11+
-- local QBCore = GetCoreObject({'Players', 'Config'})
12+
13+
local function GetCoreObject(filters)
14+
if not filters then return QBCore end
15+
local results = {}
16+
for i = 1, #filters do
17+
local key = filters[i]
18+
if QBCore[key] then
19+
results[key] = QBCore[key]
20+
end
21+
end
22+
return results
23+
end
24+
exports('GetCoreObject', GetCoreObject)
25+
26+
local function GetSharedItems()
27+
return QBShared.Items
28+
end
29+
exports('GetSharedItems', GetSharedItems)
30+
31+
local function GetSharedVehicles()
32+
return QBShared.Vehicles
33+
end
34+
exports('GetSharedVehicles', GetSharedVehicles)
35+
36+
local function GetSharedWeapons()
37+
return QBShared.Weapons
38+
end
39+
exports('GetSharedWeapons', GetSharedWeapons)
40+
41+
local function GetSharedJobs()
42+
return QBShared.Jobs
43+
end
44+
exports('GetSharedJobs', GetSharedJobs)
45+
46+
local function GetSharedGangs()
47+
return QBShared.Gangs
48+
end
49+
exports('GetSharedGangs', GetSharedGangs)

0 commit comments

Comments
 (0)