mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-28 23:01:29 +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)
|
||||
return materialHash, entityHit, surfaceNormal, endCoords, success, retval
|
||||
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.ServerCallbacks = {}
|
||||
|
||||
exports('GetCoreObject', function()
|
||||
return QBCore
|
||||
end)
|
||||
-- Get the full QBCore object (default behavior):
|
||||
-- local QBCore = GetCoreObject()
|
||||
|
||||
-- To use this export in a script instead of manifest method
|
||||
-- Just put this line of code below at the very top of the script
|
||||
-- local QBCore = exports['qb-core']:GetCoreObject()
|
||||
-- Get only specific parts of QBCore:
|
||||
-- local QBCore = GetCoreObject({'Players', 'Config'})
|
||||
|
||||
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'
|
||||
author 'Kakarot'
|
||||
description 'Core resource for the framework, contains all the core functionality and features'
|
||||
version '1.2.6'
|
||||
version '1.3.0'
|
||||
|
||||
shared_scripts {
|
||||
'config.lua',
|
||||
|
||||
+36
-30
@@ -394,33 +394,30 @@ function QBCore.Functions.CreateVehicle(source, model, vehtype, coords, warp)
|
||||
return veh
|
||||
end
|
||||
|
||||
---Paychecks (standalone - don't touch)
|
||||
function PaycheckInterval()
|
||||
if next(QBCore.Players) then
|
||||
for _, Player in pairs(QBCore.Players) do
|
||||
if Player then
|
||||
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 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
|
||||
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
|
||||
if account ~= 0 then -- Checks if player is employed by a society
|
||||
if account < payment then -- Checks if company has enough money to pay society
|
||||
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
|
||||
if not next(QBCore.Players) then return end
|
||||
for _, Player in pairs(QBCore.Players) do
|
||||
if not Player then return end
|
||||
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 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
|
||||
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
|
||||
if account ~= 0 then
|
||||
if account < payment then
|
||||
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
|
||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -471,7 +468,7 @@ end
|
||||
function QBCore.Functions.CreateUseableItem(item, data)
|
||||
local rawFunc = nil
|
||||
|
||||
if type(data) == "table" then
|
||||
if type(data) == 'table' then
|
||||
if rawget(data, '__cfx_functionReference') then
|
||||
rawFunc = data
|
||||
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
|
||||
rawFunc = data.callback
|
||||
end
|
||||
elseif type(data) == "function" then
|
||||
elseif type(data) == 'function' then
|
||||
rawFunc = data
|
||||
end
|
||||
|
||||
@@ -654,23 +651,23 @@ end
|
||||
function QBCore.Functions.GetDatabaseInfo()
|
||||
local details = {
|
||||
exists = false,
|
||||
database = "",
|
||||
database = '',
|
||||
}
|
||||
local connectionString = GetConvar("mysql_connection_string", "")
|
||||
local connectionString = GetConvar('mysql_connection_string', '')
|
||||
|
||||
if connectionString == "" then
|
||||
if connectionString == '' then
|
||||
return details
|
||||
elseif connectionString:find("mysql://") then
|
||||
elseif connectionString:find('mysql://') then
|
||||
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
|
||||
return details
|
||||
else
|
||||
connectionString = { string.strsplit(";", connectionString) }
|
||||
connectionString = { string.strsplit(';', connectionString) }
|
||||
|
||||
for i = 1, #connectionString do
|
||||
local v = connectionString[i]
|
||||
if v:match("database") then
|
||||
if v:match('database') then
|
||||
details.database = v:sub(10, #v)
|
||||
details.exists = true
|
||||
return details
|
||||
@@ -728,3 +725,12 @@ function QBCore.Functions.PrepForSQL(source, data, pattern)
|
||||
end
|
||||
return true
|
||||
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.ServerCallbacks = {}
|
||||
|
||||
exports('GetCoreObject', function()
|
||||
return QBCore
|
||||
end)
|
||||
-- Get the full QBCore object (default behavior):
|
||||
-- local QBCore = GetCoreObject()
|
||||
|
||||
-- To use this export in a script instead of manifest method
|
||||
-- Just put this line of code below at the very top of the script
|
||||
-- local QBCore = exports['qb-core']:GetCoreObject()
|
||||
-- Get only specific parts of QBCore:
|
||||
-- local QBCore = GetCoreObject({'Players', 'Config'})
|
||||
|
||||
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