π Framework Integration
π Shared Framework (Bridge)
The core bridge logic is entirely open-source, allowing you to adapt client-server sync, item checks, and cash/bank additions dynamically to your specific framework version.
Bridge = {}
local Framework = nil
if GetResourceState('qb-core') == 'started' then
Framework = 'qb'
QBCore = exports['qb-core']:GetCoreObject()
elseif GetResourceState('es_extended') == 'started' then
Framework = 'esx'
ESX = exports['es_extended']:getSharedObject()
elseif GetResourceState('qbx_core') == 'started' then
Framework = 'qbox'
-- Qbox uses exports differently but mostly compatible with QB calls if shimmed
end
-- Notify
function Bridge.Notify(source, msg, type)
if IsDuplicityVersion() then -- Server
if Framework == 'qb' then
TriggerClientEvent('QBCore:Notify', source, msg, type)
elseif Framework == 'esx' then
TriggerClientEvent('esx:showNotification', source, msg)
else
-- Standalone or other
print("[Notify] " .. msg)
end
else -- Client
if Framework == 'qb' then
QBCore.Functions.Notify(msg, type)
elseif Framework == 'esx' then
ESX.ShowNotification(msg)
else
print("[Notify] " .. msg)
end
end
end
-- Get Player Data
function Bridge.GetPlayer(source)
if Framework == 'qb' or Framework == 'qbox' then
return QBCore.Functions.GetPlayer(source)
elseif Framework == 'esx' then
return ESX.GetPlayerFromId(source)
end
return nil
end
-- Get Source
function Bridge.GetSource(Player)
if Framework == 'qb' or Framework == 'qbox' then
return Player.PlayerData.source
elseif Framework == 'esx' then
return Player.source
end
end
-- Get Money
function Bridge.GetMoney(Player, type)
if Framework == 'qb' or Framework == 'qbox' then
return Player.PlayerData.money[type] or 0
elseif Framework == 'esx' then
if type == 'cash' then type = 'money' end
local account = Player.getAccount(type)
return account and account.money or 0
end
return 0
end
-- Add Money
function Bridge.AddMoney(Player, type, amount, reason)
if Framework == 'qb' or Framework == 'qbox' then
Player.Functions.AddMoney(type, amount, reason)
elseif Framework == 'esx' then
if type == 'cash' then type = 'money' end
Player.addAccountMoney(type, amount)
end
end
-- Remove Money
function Bridge.RemoveMoney(Player, type, amount, reason)
if Framework == 'qb' or Framework == 'qbox' then
return Player.Functions.RemoveMoney(type, amount, reason)
elseif Framework == 'esx' then
if type == 'cash' then type = 'money' end
if Player.getAccount(type).money >= amount then
Player.removeAccountMoney(type, amount)
return true
end
end
return false
end
-- Get Item
function Bridge.GetItemByName(Player, item)
if Framework == 'qb' or Framework == 'qbox' then
return Player.Functions.GetItemByName(item)
elseif Framework == 'esx' then
return Player.getInventoryItem(item)
end
return nil
end
-- Add Item
function Bridge.AddItem(Player, item, amount)
if Framework == 'qb' or Framework == 'qbox' then
return Player.Functions.AddItem(item, amount)
elseif Framework == 'esx' then
Player.addInventoryItem(item, amount)
return true
end
return false
end
-- Remove Item
function Bridge.RemoveItem(Player, item, amount)
if Framework == 'qb' or Framework == 'qbox' then
return Player.Functions.RemoveItem(item, amount)
elseif Framework == 'esx' then
Player.removeInventoryItem(item, amount)
return true
end
return false
end
-- Item Box (Visual feedback)
function Bridge.ItemBox(source, item, action)
if Framework == 'qb' or Framework == 'qbox' then
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[item], action)
end
end
-- Callbacks
function Bridge.CreateCallback(name, cb)
if Framework == 'qb' or Framework == 'qbox' then
QBCore.Functions.CreateCallback(name, cb)
elseif Framework == 'esx' then
ESX.RegisterServerCallback(name, cb)
end
end
function Bridge.TriggerCallback(name, cb, ...)
if Framework == 'qb' or Framework == 'qbox' then
QBCore.Functions.TriggerCallback(name, cb, ...)
elseif Framework == 'esx' then
ESX.TriggerServerCallback(name, cb, ...)
end
end