QB-CORE
Default QB-Core framework installation (axr_octastore/server/framework/qb-core.lua)
Server
if Config.Framework ~= 'qb-core' then
return
end
local QBCore = exports['qb-core']:GetCoreObject()
Framework = {}
---@param identifier integer
---@return boolean
Framework.canAccesMenu = function(identifier)
if identifier then
-- your custom functions to open menu (coma status/handcuff etc)
return true;
end
return false;
end
---@param source integer
---@return integer?nil
Framework.getPlayerIdentifier = function(source)
local Player = QBCore.Functions.GetPlayer(source)
if Player then
return tonumber(Player.PlayerData.citizenid)
end
return nil
end
---@param identifier integer
---@return integer
Framework.getIdentifierSource = function(identifier)
local players = QBCore.Functions.GetPlayers()
for _, src in pairs(players) do
local Player = QBCore.Functions.GetPlayer(src)
if Player and tonumber(Player.PlayerData.citizenid) == identifier then
return src
end
end
return nil
end
---@param identifier string
---@return table
Framework.getPlayerIdentity = function(identifier)
local src = Framework.getIdentifierSource(identifier)
local Player = QBCore.Functions.GetPlayer(src)
if Player then
return {
firstname = Player.PlayerData.charinfo.firstname,
secondname = Player.PlayerData.charinfo.lastname,
phone_numner = Player.PlayerData.charinfo.phone
}
end
return nil
end
---@param identifier integer
---@param price integer
---@return boolean
Framework.tryPaymentPlan = function(identifier, price)
local src = Framework.getIdentifierSource(identifier)
local Player = QBCore.Functions.GetPlayer(src)
if Player and Player.Functions.RemoveMoney("bank", price, "octastore-plan") then
return true
end
return false
end
---@param identifier integer
---@param price integer
---@return boolean
Framework.tryPayProductsOnline = function(identifier, price)
local src = Framework.getIdentifierSource(identifier)
local Player = QBCore.Functions.GetPlayer(src)
if Player and Player.Functions.RemoveMoney("bank", price, "octastore-plan") then
return true
end
return false
end
---@param identifier integer
---@param amount integer
---@return boolean
Framework.paySeller = function(identifier, amount)
if identifier then
local src = Framework.getIdentifierSource(identifier)
local Player = QBCore.Functions.GetPlayer(src)
if Player then
Player.Functions.AddMoney("bank", amount, "octastore-sell")
else
exports[Config.Sql]:execute(
"UPDATE players SET money = JSON_SET(money, '$.bank', JSON_EXTRACT(money, '$.bank') + @amount) WHERE citizenid = @citizenid",
{
['@amount'] = amount,
['@citizenid'] = identifier
})
end
end
end
---@param item string
---@param callback function
Framework.createItem = function(item, callback)
print("[OctaStore] createItem function should be handled by item registration")
end
---@param identifier integer
---@param item string
---@param amount integer?nil
---@return boolean
Framework.hasItem = function(identifier, item, amount)
if Config.Inventory == 'qb-core' then
local src = Framework.getIdentifierSource(identifier)
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local itemData = Player.Functions.GetItemByName(item)
if itemData then
if amount ~= nil then
return itemData.amount >= amount
else
return itemData.amount > 0
end
end
end
return false
else
print('ERRROR: Please edit your custom hasItem function (server/framework/qb-core.lua)')
end
end
---@param identifier integer
---@return table?nil
Framework.getPlayerItems = function(identifier)
if Config.Inventory == 'qb-core' then
local src = Framework.getIdentifierSource(identifier)
local Player = QBCore.Functions.GetPlayer(src)
local items = {}
if Player then
for k, v in pairs(Player.PlayerData.items) do
if v and v.name and not Config.blacklistedItems[v.name] then
items[v.name] = {
amount = v.amount,
img = exports.axr_octastore:getItemImagePath(v.name),
name = v.label or v.name
}
end
end
end
return items
else
print('ERRROR: Please edit your custom getPlayerItems function (server/framework/qb-core.lua)')
end
end
---@param identifier integer
---@param items table --{index: {name:'',item:'',amount:''}}
---@return boolean
Framework.hasSpaceForItems = function(identifier, items)
if identifier then
if Config.Inventory == 'qb-core' then
local src = Framework.getIdentifierSource(identifier)
return true
else
print('ERRROR: Please edit your custom hasSpaceForItems function (server/framework/qb-core.lua)')
end
end
end
---@param identifier integer
---@param item string
---@param amount integer
Framework.giveInventoryItem = function(identifier, item, amount)
if identifier then
if Config.Inventory == 'qb-core' then
local src = Framework.getIdentifierSource(identifier)
local Player = QBCore.Functions.GetPlayer(src)
if Player then
Player.Functions.AddItem(item, amount, false, false)
end
else
print('ERRROR: Please edit your custom giveInventoryItem function (server/framework/qb-core.lua)')
end
end
end
---@param identifier integer
---@param item string
---@param amount integer
Framework.removeInventoryItem = function(identifier, item, amount)
if identifier then
if Config.Inventory == 'qb-core' then
local src = Framework.getIdentifierSource(identifier)
local Player = QBCore.Functions.GetPlayer(src)
if Player then
Player.Functions.RemoveItem(item, amount, false)
end
else
print('ERRROR: Please edit your custom removeInventoryItem function (server/framework/qb-core.lua)')
end
end
end
---@param item string
---@return string
Framework.getItemName = function(item)
if item then
if Config.Inventory == 'qb-core' then
local info = QBCore.Shared.Items[item]
return info and info.label or item
end
end
return 'unknown'
end
---@param identifier integer
---@param lockerItems table --{index: {name:'',item:'',amount:''}}
Framework.giveLockerItems = function(identifier, lockerItems)
local source = Framework.getIdentifierSource(identifier);
if identifier and source then
if Framework.hasSpaceForItems(identifier, lockerItems) then
for index, itemData in pairs(lockerItems) do
Framework.giveInventoryItem(identifier, itemData.item, itemData.amount);
end
Framework.notify(source, Lang.notify['receive_locker_product'].message,
Lang.notify['receive_locker_product'].type)
else
Framework.notify(source, Lang.notify['no_inventory_weight'].message, Lang.notify['no_inventory_weight'].type)
end
end
end
---@param source integer
---@param notify string
---@param type string
Framework.notify = function(source, notify, type)
if Config.notifySystem == 'qb-core' then
TriggerClientEvent('QBCore:Notify', source, notify, type)
else
print('ERRROR: Please edit your custom notify system (server/framework/qb-core.lua)')
end
end
Framework.playerSpawn = function()
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player and tonumber(Player.PlayerData.citizenid) > 0 and exports.axr_octastore:getPlayerPlan(tonumber(Player.PlayerData.citizenid)) > 0 then
exports.axr_octastore:checkPlayerRemaningTimePlan(tonumber(Player.PlayerData.citizenid))
end
end)
end
-- Do not remove this line if you want the plans to expire monthly
Framework.playerSpawn();
Client
if Config.Framework ~= 'qb-core' then
return
end
Last updated