### Get qb-core Version Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Retrieves the currently installed version of the qb-core resource. Optionally logs the calling resource name. ```lua function QBCore.Functions.GetCoreVersion(InvokingResource) @param InvokingResource string | nil - Resource name for logging @return string - Version string end ``` ```lua print(exports['qb-core']:GetCoreVersion()) -- "1.3.0" ``` -------------------------------- ### AddJob Usage Example Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md Shows how to add a new job to QBCore using the AddJob export and handle potential errors. ```lua local success, reason = exports['qb-core']:AddJob('builder', { label = 'Builder', defaultDuty = true, offDutyPay = false, grades = {['0'] = {name = 'Worker', payment = 100}} }) if not success then print('Failed to add job: ' .. reason) end ``` -------------------------------- ### SetJob Example Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md Use the SetJob method to assign a job to a player. It returns false if the job does not exist or is not found in QBCore.Shared.Jobs. ```lua if not player:SetJob('police', '2') then TriggerClientEvent('chat:addMessage', player.PlayerData.source, { color = {255, 0, 0}, args = {'Job Error', 'Job does not exist'} }) end ``` -------------------------------- ### SetMethod Usage Example Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md Demonstrates how to use the SetMethod export to add a custom function and check for success or failure. ```lua local success, reason = exports['qb-core']:SetMethod('CustomFunc', function(...) -- Implementation end) if not success then print('Error: ' .. reason) end ``` -------------------------------- ### Get All Players - QBCore Source: https://github.com/qbcore-framework/qb-core/wiki/Client-Side-Functions Returns a table of all players currently on the server. Note: Not compatible with OneSync Infinity on the client side. ```lua QBCore.Functions.GetPlayers = function() local players = {} for _, player in ipairs(GetActivePlayers()) do local ped = GetPlayerPed(player) if DoesEntityExist(ped) then table.insert(players, player) end end return players end ``` -------------------------------- ### Configure QBConfig Settings Source: https://github.com/qbcore-framework/qb-core/wiki/Home Modify these settings in the QBConfig table to customize game parameters like player limits, identifier types, starting money, and inventory limits. ```lua QBConfig = {} -- Don't Touch QBConfig.MaxPlayers = GetConvarInt('sv_maxclients', 64) -- Gets max players from config file, default 32 QBConfig.IdentifierType = "steam" -- Set the identifier type (can be: steam, license) QBConfig.DefaultSpawn = {x=-1035.71,y=-2731.87,z=12.86,a=0.0} QBConfig.Money = {} -- Don't Touch QBConfig.Money.MoneyTypes = {['cash'] = 500, ['bank'] = 5000, ['crypto'] = 0 } -- ['type'] = startamount - You can add more money types as well, for example: ['blackmoney'] = 0 QBConfig.Money.DontAllowMinus = {'cash', 'crypto'} -- Money types that the core won't allow to go negative QBConfig.Player = {} -- Don't Touch QBConfig.Player.MaxWeight = 120000 -- Max weight a player can carry (currently 120kg, written in grams) QBConfig.Player.MaxInvSlots = 41 -- Max inventory slots for a player QBConfig.Player.Bloodtypes = { "A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-", } QBConfig.Server = {} -- Don't Touch QBConfig.Server.closed = false -- Set server closed (no one can join except people with ace permission 'qbadmin.join') QBConfig.Server.closedReason = "Server Closed" -- Reason message to display when people can't join the server QBConfig.Server.uptime = 0 -- Time the server has been up. QBConfig.Server.whitelist = false -- Enable or disable whitelist on the server QBConfig.Server.discord = "add discord link here" -- Discord invite link QBConfig.Server.PermissionList = {} -- permission list ``` -------------------------------- ### GetPermission Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Gets all permissions a player has. ```APIDOC ## GetPermission ### Description Gets all permissions a player has. ### Parameters #### Path Parameters - **source** (number) - Required - Player server ID ### Returns - **table** - Table mapping permission name to true ### Request Example ```lua local perms = QBCore.Functions.GetPermission(source) print(json.encode(perms)) -- {admin = true, mod = true} ``` ``` -------------------------------- ### AddMoney Example Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md Use AddMoney to add currency to a player's account. Ensure the amount is positive and the money type exists. Returns true on success. ```lua player:AddMoney('cash', 100) ``` -------------------------------- ### Get All Player Permissions Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Retrieves a table containing all permissions assigned to a player. ```lua local perms = QBCore.Functions.GetPermission(source) print(json.encode(perms)) -- {admin = true, mod = true} ``` -------------------------------- ### Get Player by License Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Looks up a player using their FiveM license identifier. It first checks for an online player and then queries the database if necessary. ```lua local player = QBCore.Functions.GetPlayerByLicense('license:1234567890') ``` -------------------------------- ### Get Player Data - QBCore Source: https://github.com/qbcore-framework/qb-core/wiki/Client-Side-Functions Retrieves the player's data. Can be used with a callback or directly return the data. ```lua QBCore.Functions.GetPlayerData = function(cb) if cb ~= nil then cb(QBCore.PlayerData) else return QBCore.PlayerData end end ``` -------------------------------- ### Configure Money System Behavior Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/configuration.md Customize available money types, starting amounts, negative balance limits, and paycheck intervals. Ensure new money types are added to DontAllowMinus if they should not go negative. ```lua -- Allow bank to go to -$5000, but cash/crypto cannot be negative QBCore.Config.Money.MoneyTypes = { cash = 500, bank = 5000, crypto = 0, blackmoney = 0 -- Add custom money type } QBCore.Config.Money.DontAllowMinus = {'cash', 'crypto', 'blackmoney'} QBCore.Config.Money.MinusLimit = -5000 QBCore.Config.Money.PayCheckTimeOut = 15 -- Paychecks every 15 minutes ``` -------------------------------- ### Get Server Bucket Objects Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Retrieves the internal tables that track player and entity routing buckets. Use this to inspect current bucket assignments. ```lua function QBCore.Functions.GetBucketObjects() @return table, table - Player buckets table, Entity buckets table end ``` ```lua local playerBuckets, entityBuckets = QBCore.Functions.GetBucketObjects() ``` -------------------------------- ### Money Configuration Settings Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/types.md Configures starting money amounts for different types (cash, bank, crypto), defines which money types cannot go negative, sets the maximum negative limit, and configures paycheck intervals and sources. ```lua { MoneyTypes = { cash = 500, -- Starting cash amount bank = 5000, -- Starting bank amount crypto = 0 -- Starting crypto amount }, DontAllowMinus = {'cash', 'crypto'}, MinusLimit = -5000, PayCheckTimeOut = 10, PayCheckSociety = false } ``` -------------------------------- ### Handle Client Animation Promise Rejection Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md When using QBCore.Functions.PlayAnim, the returned Promise can reject with an error message. This example shows how to use the .catch() method to handle potential animation playback errors. ```lua QBCore.Functions.PlayAnim('combat@damage@rb_writhe', 'rb_writhe_loop'):next(function() print('Animation completed') end):catch(function(err) print('Animation error: ' .. err) end) ``` -------------------------------- ### AddMethod Example Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md Use AddMethod to dynamically add a new method to the player instance. It returns false if the methodName is not a string or the handler is not callable. ```lua player:AddMethod('CustomAction', function(args) print('Custom action performed with:', args) end) ``` -------------------------------- ### SetMoney Example Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md Use SetMoney to directly set a player's currency amount. It returns false if the amount is negative or the money type is invalid. ```lua player:SetMoney('bank', 1000) ``` -------------------------------- ### HasItem Example Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md Use HasItem to check if a player possesses a specific item. This method delegates to the qb-inventory system and returns a boolean. ```lua if player:HasItem('medkit') then -- Player has the item end ``` -------------------------------- ### Give Existing Players Money Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/configuration.md To give existing players money, use admin commands or database updates. This example shows how to add money to a player using a server-side function. ```lua -- Give existing players money local player = QBCore.Functions.GetPlayer(source) player:AddMoney('cash', 10000, 'admin_gift') ``` -------------------------------- ### Configure Server Settings in QBCore Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/configuration.md Modify server-level settings such as server status, whitelist, PVP, and permissions. Ensure correct values are set for desired functionality. ```lua QBCore.Config.Server.Closed = false QBCore.Config.Server.Whitelist = false QBCore.Config.Server.PVP = true QBCore.Config.Server.Discord = 'https://discord.gg/yourserver' QBCore.Config.Server.Permissions = {'god', 'admin', 'moderator', 'vip'} ``` -------------------------------- ### Get On-Duty Players by Job - Lua Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md A convenience function to get only the on-duty players for a specified job. It returns an array of player sources and the count. ```lua local police, count = QBCore.Functions.GetPlayersOnDuty('police') ``` -------------------------------- ### Get QBCore Object Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Obtain the QBCore core object for server-side or client-side use. You can also filter to get only specific fields like 'Functions' or 'Config'. ```lua -- Server-side local QBCore = exports['qb-core']:GetCoreObject() -- Client-side local QBCore = exports['qb-core']:GetCoreObject() -- Get filtered core (only specific fields) local core = exports['qb-core']:GetCoreObject({'Functions', 'Config'}) ``` -------------------------------- ### Get Player Data Synchronously or Asynchronously Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/client-functions.md Retrieves the player's data. Can be called synchronously to get data directly or asynchronously with a callback function to handle the data once loaded. ```lua local playerData = QBCore.Functions.GetPlayerData() print(playerData.charinfo.firstname) ``` ```lua QBCore.Functions.GetPlayerData(function(playerData) print('Loaded: ' .. playerData.charinfo.firstname) end) ``` -------------------------------- ### Define Starter Items Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/shared-functions.md Configures the default items provided to new characters upon creation. This table can be modified in the configuration file before players spawn. ```lua QBCore.Shared.StarterItems = { ['phone'] = { amount = 1, item = 'phone' }, ['id_card'] = { amount = 1, item = 'id_card' }, ['driver_license'] = { amount = 1, item = 'driver_license' }, } ``` -------------------------------- ### qb-core File Structure Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/FRAMEWORK_OVERVIEW.md This outlines the directory and file structure of the qb-core framework, detailing the purpose of each main directory and key files within them. ```lua qb-core/ ├── config.lua # Configuration ├── fxmanifest.lua # Manifest ├── qbcore.sql # Database schema ├── shared/ │ ├── main.lua # Initialization & exports │ ├── functions.lua # Utilities │ ├── jobs.lua # Job definitions │ ├── items.lua # Item definitions │ ├── vehicles.lua # Vehicle definitions │ ├── weapons.lua # Weapon metadata │ ├── gangs.lua # Gang definitions │ ├── locations.lua # Named locations │ └── locale.lua # Localization ├── server/ │ ├── functions.lua # Server API │ ├── player.lua # Player class │ ├── exports.lua # Public API │ ├── events.lua # Event handlers │ ├── commands.lua # Command system │ └── debug.lua # Debug tools ├── client/ │ ├── functions.lua # Client API │ ├── events.lua # Event handlers │ ├── drawtext.lua # 3D text rendering │ └── loops.lua # Status update loops ├── locale/ │ └── *.lua # Language files └── html/ ├── index.html # NUI interface └── (css, js) # Notification UI ``` -------------------------------- ### Vehicle Properties Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Functions to get and set properties of a spawned vehicle. ```APIDOC ## Vehicle Properties ### Get Vehicle Properties ```lua local props = QBCore.Functions.GetVehicleProperties(vehicle) ``` ### Set Vehicle Properties ```lua QBCore.Functions.SetVehicleProperties(vehicle, { modEngine = 2, modBrakes = 1, color1 = 0, neonEnabled = {true, true, true, true}, neonColor = {255, 0, 0} }) ``` ``` -------------------------------- ### Register Command Callback Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/types.md Use `QBCore.Commands.Add` to register a command that players can execute. The callback receives the source ID, a table of arguments, and the raw command string. Permissions can be specified. ```lua -- Callback signature function callback(source: number, args: table, rawCommand: string) -- source: player who executed command -- args: table of command arguments -- rawCommand: full command text end -- Example QBCore.Commands.Add('setjob', 'Set a players job', { {name = 'target', help = 'Target player ID'}, {name = 'job', help = 'Job name'}, {name = 'grade', help = 'Grade level'} }, true, function(source, args, rawCommand) local player = QBCore.Functions.GetPlayer(tonumber(args[1])) if player then player:SetJob(args[2], args[3]) end end, 'admin') ``` -------------------------------- ### Common QBCore Development Patterns Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/FRAMEWORK_OVERVIEW.md Demonstrates common QBCore API usage for developers, including accessing player data, modifying player attributes, sending notifications, checking permissions, and registering/triggering server callbacks. Ensure qb-core is loaded before using these functions. ```lua -- Get player object local player = QBCore.Functions.GetPlayer(source) if not player then return end -- Modify player data player:AddMoney('cash', 100, 'drug_sale') player:SetMetaData('stress', player:GetMetaData('stress') + 10) player.Functions.Save() -- Notify player player:Notify('Transaction complete', 'success') -- Check permissions if QBCore.Functions.HasPermission(source, 'admin') then -- Admin action end -- Register callback QBCore.Functions.CreateCallback('myresource:getData', function(source, cb, arg1) cb(someData) end) -- Trigger callback from client TriggerServerEvent('QBCore:Server:TriggerCallback', 'myresource:getData', arg1) ``` -------------------------------- ### Player.new Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/player-class.md Creates a new Player instance. This is typically called internally by QBCore during player login. ```APIDOC ## Player.new ### Description Creates a new Player instance. This is called internally by QBCore during player login. ### Parameters #### Path Parameters - **PlayerData** (table) - Required - Complete player data object - **Offline** (boolean | nil) - Optional - Mark as offline player ### Returns - **Player instance** (table) - Player class instance ### Source `server/player.lua:39` ``` -------------------------------- ### GetPlayersOnDuty Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md A shortcut function to get only the players who are currently on duty for a specified job. ```APIDOC ## GetPlayersOnDuty ### Description Convenience wrapper for GetPlayersByJob with checkOnDuty=true. ### Method `QBCore.Functions.GetPlayersOnDuty(job)` ### Parameters #### Path Parameters - **job** (string) - Required - Job name ### Returns - **table, number** - On-duty players, count ### Example ```lua local policeOnDuty, count = QBCore.Functions.GetPlayersOnDuty('police') ``` ``` -------------------------------- ### Get Entity Coordinates (Client-Side) Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Retrieves the world coordinates of a given entity. ```lua local coords = QBCore.Functions.GetCoords(entity) ``` -------------------------------- ### Get Shared Data Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Retrieves data from a shared namespace within the framework. ```APIDOC ## Shared Data Access ### Description Accesses data stored in shared namespaces managed by the qb-core framework. ### Method `exports['qb-core']:GetShared(namespace, key)` ### Parameters - **namespace** (string) - The name of the shared data namespace (e.g., 'Jobs', 'Gangs', 'Items'). - **key** (string, optional) - The specific key within the namespace to retrieve. If omitted, the entire namespace table is returned. ### Available Namespaces 'Jobs', 'Gangs', 'Items', 'Vehicles', 'Weapons', 'Locations', 'VehicleHashes', 'StarterItems' ### Usage Example ```lua -- Get the entire 'Jobs' namespace local jobs = exports['qb-core']:GetShared('Jobs') -- Get a specific item from the 'Jobs' namespace local policeJobData = exports['qb-core']:GetShared('Jobs', 'police') ``` ``` -------------------------------- ### Get Player Name Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/client-functions.md Returns the full name of the current player, formatted as 'FirstName LastName'. ```lua print(QBCore.Functions.GetName()) -- "John Doe" ``` -------------------------------- ### Get Players in Bucket Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Retrieves a list of all player source IDs currently in the specified routing bucket. ```lua function QBCore.Functions.GetPlayersInBucket(bucket) @param bucket number - Bucket ID @return table - Array of player sources in bucket end ``` ```lua local playersInBucket1 = QBCore.Functions.GetPlayersInBucket(1) ``` -------------------------------- ### Enable Server Whitelist Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/configuration.md Activate the server whitelist to control access. Players with the specified ACE permission will be allowed entry. ```lua QBCore.Config.Server.Whitelist = true QBCore.Config.Server.WhitelistPermission = 'whitelist' -- Then use ACE permission "qbcore.whitelist" for whitelisted players ``` -------------------------------- ### Register and Trigger Callback Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/README.md Demonstrates the callback system for asynchronous operations. Includes registering a server-side callback to provide data and triggering it from a client. ```lua -- Register callback QBCore.Functions.CreateCallback('myresource:getData', function(source, cb) cb({success = true, data = {}}) end) -- Trigger from client QBCore.Functions.TriggerCallback('myresource:getData', function(result) print(result.data) end) ``` -------------------------------- ### Get Player Reputation Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/player-class.md Retrieves the reputation value for a specified category. Returns 0 if the category is not found. ```lua function player:GetRep(rep) @param rep string - Reputation category @return number - Reputation value (default 0) end ``` ```lua local gangRep = player:GetRep('gang') print('Gang reputation: ' .. gangRep) ``` -------------------------------- ### Configure Server Maintenance Mode Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/configuration.md Set the server to closed for maintenance by enabling `QBCore.Config.Server.Closed` and providing a reason. ```lua -- Close server for maintenance QBCore.Config.Server.Closed = true QBCore.Config.Server.ClosedReason = 'Maintenance in progress. Back in 30 minutes.' -- Open server again QBCore.Config.Server.Closed = false ``` -------------------------------- ### Get Entities in Bucket Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Retrieves a list of all non-player entity handles currently within the specified routing bucket. ```lua function QBCore.Functions.GetEntitiesInBucket(bucket) @param bucket number - Bucket ID @return table - Array of entity handles in bucket end ``` ```lua QBCore.Functions.GetEntitiesInBucket(bucket) ``` -------------------------------- ### Register Server Function (Lua) Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/FRAMEWORK_OVERVIEW.md Use QBCore.Functions.SetMethod() to add custom server-side functions to the framework. This allows for extending core functionalities with your own logic. ```lua QBCore.Functions.SetMethod() ``` -------------------------------- ### Get Players Near Coordinates (Server-Side) Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Finds all player IDs within a specified radius of given coordinates. ```lua local nearbyPlayers = QBCore.Functions.GetPlayersFromCoords(vector3(0, 0, 0), 50) for _, playerId in ipairs(nearbyPlayers) do print('Found player: ' .. playerId) end ``` -------------------------------- ### Spawn Vehicle (Server/Client) Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Use QBCore.Functions.SpawnVehicle to spawn vehicles. The server-side version returns the spawned vehicle, while the client-side version uses a callback. ```lua -- Server-side spawn local veh = QBCore.Functions.SpawnVehicle(source, 'adder', vector4(0, 0, 0, 0), true) ``` ```lua -- Client-side spawn QBCore.Functions.SpawnVehicle('adder', function(vehicle) print('Vehicle spawned: ' .. vehicle) end, vector3(0, 0, 0), true, true) ``` -------------------------------- ### Get All Players Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Returns a table containing the server IDs of all players currently connected to the server. Useful for Onesync. ```lua QBCore.Functions.GetPlayers = function() local sources = {} for k, v in pairs(QBCore.Players) do table.insert(sources, k) end return sources end ``` -------------------------------- ### String Utilities Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Utilize QBCore.Shared functions for common string manipulations like generating random strings/integers, splitting strings, trimming whitespace, capitalizing, and rounding numbers. ```lua local random = QBCore.Shared.RandomStr(8) -- Random letters local random = QBCore.Shared.RandomInt(10) -- Random digits local parts = QBCore.Shared.SplitStr('a,b,c', ',') -- Split string local clean = QBCore.Shared.Trim(' text ') -- Trim whitespace local cap = QBCore.Shared.FirstToUpper('john') -- Capitalize local rounded = QBCore.Shared.Round(3.14159, 2) -- Round number ``` -------------------------------- ### Get Entity Coordinates Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/client-functions.md Obtains the position and heading of a specified entity. Requires the entity's handle as a number. ```lua local ped = PlayerPedId() local playerCoords = QBCore.Functions.GetCoords(ped) ``` -------------------------------- ### Manage Player and Entity Buckets Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Utilize QBCore functions to manage routing buckets for players and entities. This is useful for instancing and managing game world areas. ```lua -- Put player in bucket QBCore.Functions.SetPlayerBucket(source, 1) -- Put entity in bucket QBCore.Functions.SetEntityBucket(vehicle, 1) -- Get players in bucket local players = QBCore.Functions.GetPlayersInBucket(1) -- Get entities in bucket local entities = QBCore.Functions.GetEntitiesInBucket(1) ``` -------------------------------- ### Player Management - Get Player Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/INDEX.md Retrieves player data either by their server ID or their unique citizen ID. ```APIDOC ## Get Player ### Description Retrieves player data by server ID or citizen ID. ### Method `QBCore.Functions.GetPlayer(source)` `QBCore.Functions.GetPlayerByCitizenId(citizenId)` ### Parameters #### Path Parameters - **source** (number) - Required - The server ID of the player. - **citizenId** (string) - Required - The citizen ID of the player. ### Response #### Success Response (Player Object) - **player** (object) - The player object containing player data and methods. ``` -------------------------------- ### UpdateJob - Server Function Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Updates an existing job definition. This is useful for modifying job properties after initial setup. ```lua function QBCore.Functions.UpdateJob(jobName, job) @param jobName string - Job name @param job table - Updated job definition @return boolean, string - Success, reason end ``` -------------------------------- ### Add Job to qb-core Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Use AddJob to register a new job with its properties and grades. Default duty and pay settings can be configured. ```lua local success, reason = exports['qb-core']:AddJob('builder', { label = 'Builder', defaultDuty = true, offDutyPay = false, grades = { ['0'] = { name = 'Apprentice', payment = 100 }, ['1'] = { name = 'Master', payment = 200, isboss = true } } }) if not success then print('Error: ' .. reason) end ``` -------------------------------- ### GetCoreObject Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Exported function to get the QBCore object, optionally filtered. Call via `exports['qb-core']:GetCoreObject(filters)`. ```APIDOC ## GetCoreObject ### Description Exported function to get the QBCore object, optionally filtered. Call via `exports['qb-core']:GetCoreObject(filters)`. ### Parameters #### Path Parameters - **filters** (string[] | nil) - Optional - Table of keys to return (Config, Shared, Functions, etc.). ### Request Example ```lua -- Get full core local QBCore = exports['qb-core']:GetCoreObject() -- Get only Functions and Config local core = exports['qb-core']:GetCoreObject({'Functions', 'Config'}) ``` ### Response #### Success Response (200) - **table** - Core object or filtered subset ``` -------------------------------- ### Server Configuration Settings Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/types.md Configures server operational states like whether the server is closed, whitelist status, PvP enablement, and defines permissions for server administration. ```lua { Closed = false, ClosedReason = 'Server Closed', Uptime = 0, Whitelist = false, WhitelistPermission = 'admin', PVP = true, Discord = '', CheckDuplicateLicense = true, Permissions = {'god', 'admin', 'mod'} } ``` -------------------------------- ### Get Entity Coordinates and Heading Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Retrieves the position (x, y, z) and heading of any game entity. Useful for location-based logic. ```lua function QBCore.Functions.GetCoords(entity) @param entity number - Entity handle @return vector4 - Position and heading end ``` ```lua local coords = QBCore.Functions.GetCoords(PlayerPedId()) print(coords.x, coords.y, coords.z) ``` -------------------------------- ### QBCore.Functions.Progressbar Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/client-functions.md Shows a progress bar for timed activities. Requires the 'progressbar' resource. ```APIDOC ## QBCore.Functions.Progressbar ### Description Shows a progress bar for timed activities. Requires 'progressbar' resource. ### Method Signature ```lua function QBCore.Functions.Progressbar(name, label, duration, useWhileDead, canCancel, disableControls, animation, prop, propTwo, onFinish, onCancel) ``` ### Parameters #### name - **name** (string) - Required - Unique progressbar identifier #### label - **label** (string) - Required - Display label #### duration - **duration** (number) - Required - Duration in milliseconds #### useWhileDead - **useWhileDead** (boolean) - Optional - Usable while dead (Default: false) #### canCancel - **canCancel** (boolean) - Optional - Player can cancel (Default: true) #### disableControls - **disableControls** (table) - Optional - Disabled control flags (Default: {}) #### animation - **animation** (table) - Optional - {dict, anim, flag} animation to play #### prop - **prop** (table) - Optional - Prop to hold during progress #### propTwo - **propTwo** (table) - Optional - Secondary prop #### onFinish - **onFinish** (function) - Optional - Callback when completed #### onCancel - **onCancel** (function) - Optional - Callback when cancelled ### Example ```lua QBCore.Functions.Progressbar('craft_item', 'Crafting...', 5000, false, true, {}, {dict = 'combat@damage@rb_writhe', anim = 'rb_writhe_loop'}, nil, nil, function() TriggerEvent('some:craft:event') end, function() TriggerEvent('some:cancel:event') end ) ``` ``` -------------------------------- ### Access QBCore Configuration Client-Side Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/configuration.md Retrieve the QBCore configuration object on the client-side using an export. Specific sections can then be accessed. ```lua -- Get via export local config = exports['qb-core']:GetCoreObject('Config') local moneyTypes = config.Config.Money.MoneyTypes ``` -------------------------------- ### Get Player Metadata Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/player-class.md Retrieves the current value of a specified metadata field for the player. Returns `nil` if the key does not exist. ```lua function player:GetMetaData(meta) @param meta string - Metadata key @return any - Metadata value or nil end local hunger = player:GetMetaData('hunger') local stress = player:GetMetaData('stress') local cuffed = player:GetMetaData('ishandcuffed') ``` -------------------------------- ### Create Server Callback Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Creates a server-side callback function that can be triggered later. The callback is stored in QBCore.ServerCallbacks. ```lua QBCore.Functions.CreateCallback = function(name, cb) QBCore.ServerCallbacks[name] = cb end ``` -------------------------------- ### Execute SQL Query with QBCore Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Executes an SQL query, optionally waiting for the result. Useful as an alternative to ghmattimysql exports. ```lua QBCore.Functions.ExecuteSql = function(wait, query, cb) local rtndata = {} local waiting = true exports['ghmattimysql']:execute(query, {}, function(data) if cb ~= nil and wait == false then cb(data) end rtndata = data waiting = false end) if wait then while waiting do Citizen.Wait(5) end if cb ~= nil and wait == true then cb(rtndata) end end return rtndata end ``` -------------------------------- ### Get Player Data by Source or Identifier Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Retrieves player data by either their server source ID (number) or their identifier (string). ```lua QBCore.Functions.GetPlayer = function(source) if type(source) == "number" then return QBCore.Players[source] else return QBCore.Players[QBCore.Functions.GetSource(source)] end end ``` -------------------------------- ### Classes Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/INDEX.md Available classes within the qb-core framework. ```APIDOC ## Classes ### Player - Purpose: Individual player instance with data and methods ``` -------------------------------- ### Get Player Data (Server) Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/INDEX.md Retrieve player data using their server ID or Citizen ID. Refer to server-functions.md for more details. ```lua local player = QBCore.Functions.GetPlayer(source) -- By server ID ``` ```lua local player = QBCore.Functions.GetPlayerByCitizenId('ABC12345') ``` -------------------------------- ### QBCore Framework Architecture Diagram Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/FRAMEWORK_OVERVIEW.md Illustrates the three-tier architecture of the QBCore framework, separating client-side, shared, and server-side responsibilities. ```text ┌─────────────────────────────────────────────────────────┐ │ Client-Side (NUI) │ │ Player UI, Notifications, Animations, Interactions │ ├─────────────────────────────────────────────────────────┤ │ Shared Layer (Lua Tables) │ │ Jobs, Items, Vehicles, Weapons, Locations, Gangs │ ├─────────────────────────────────────────────────────────┤ │ Server-Side (Authority) │ │ Player Data, Permissions, Events, Database │ └─────────────────────────────────────────────────────────┘ ``` -------------------------------- ### AddField Example Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md Use AddField to add a new field to the player instance. It returns false if the fieldName is not a string or the data is a function. ```lua player:AddField('CustomData', { value = 123 }) ``` -------------------------------- ### Add Custom Server Permissions Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/configuration.md Define custom permission roles for server access. These can then be checked using `QBCore.Functions.HasPermission`. ```lua -- config.lua QBCore.Config.Server.Permissions = {'god', 'admin', 'mod', 'helper', 'trial'} ``` ```lua if QBCore.Functions.HasPermission(source, 'helper') then -- helper command end ``` -------------------------------- ### Get Player by Account Number Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Retrieves an online player using their bank account number. Returns the player object or nil if not found. ```lua local player = QBCore.Functions.GetPlayerByAccount('ACC123456') ``` -------------------------------- ### Register Client Callback Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/types.md Use `QBCore.Functions.CreateClientCallback` to register a client-side function that can be called by the server. The callback receives the source ID from the server trigger and arguments from the server. ```lua -- Callback signature function callback(source: number, ...) -- source: from server trigger -- ...: arguments from server end -- Example QBCore.Functions.CreateClientCallback('player:getPos', function(source, cb) cb(GetEntityCoords(PlayerPedId())) end) ``` -------------------------------- ### Get Player by Source Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Retrieves a player instance using their server ID or a unique identifier. Returns the player object or nil if not found. ```lua local player = QBCore.Functions.GetPlayer(source) if player then print(player:GetName()) player.Functions.AddMoney('cash', 100, 'job_payment') end ``` -------------------------------- ### Handle Item Use (Lua) Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/FRAMEWORK_OVERVIEW.md Use QBCore.Functions.CreateUseableItem() to define the logic for when a player uses a specific item. This function handles the server-side actions associated with item usage. ```lua QBCore.Functions.CreateUseableItem() ``` -------------------------------- ### Get Player Permission Level Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Retrieves a player's permission level based on their identifiers and configuration. Requires player data to be loaded. ```lua QBCore.Functions.GetPermission = function(source) local retval = "user" Player = QBCore.Functions.GetPlayer(source) local steamid = GetPlayerIdentifiers(source)[1] local licenseid = GetPlayerIdentifiers(source)[2] if Player ~= nil then if QBCore.Config.Server.PermissionList[Player.PlayerData.steam] ~= nil then if QBCore.Config.Server.PermissionList[Player.PlayerData.steam].steam == steamid and QBCore.Config.Server.PermissionList[Player.PlayerData.steam].license == licenseid then retval = QBCore.Config.Server.PermissionList[Player.PlayerData.steam].permission end end end return retval end ``` -------------------------------- ### Get Player Money Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/player-class.md Retrieves the current amount of a specific money type. Returns the amount as a number or false if the money type does not exist. ```lua function player:GetMoney(moneytype) @param moneytype string - Money type @return number | false - Amount or false if type invalid end ``` ```lua local cash = player:GetMoney('cash') local bank = player:GetMoney('bank') print('Cash: ' .. cash .. ', Bank: ' .. bank) ``` -------------------------------- ### Access QBCore Configuration Server-Side Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/configuration.md Access the entire QBCore configuration object or specific sections on the server. Configuration can be modified at runtime. ```lua -- Get entire config local config = QBCore.Config -- Access specific sections local serverClosed = QBCore.Config.Server.Closed local moneyTypes = QBCore.Config.Money.MoneyTypes local defaultSpawn = QBCore.Config.DefaultSpawn -- Modify at runtime QBCore.Config.Server.PVP = false ``` -------------------------------- ### Get Vehicle Properties Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/client-functions.md Retrieves all current properties of a vehicle entity and returns them as a table. This is useful for saving vehicle states or applying them to other vehicles. ```lua local veh = GetVehiclePedIsIn(PlayerPedId()) local props = QBCore.Functions.GetVehicleProperties(veh) -- Save props to database ``` -------------------------------- ### QBCore.Functions.CreateUseableItem Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Makes an item in the game usable by defining its interaction logic. ```APIDOC ## QBCore.Functions.CreateUseableItem ### Description Makes an item useable. ### Parameters #### Path Parameters - **item** (string) - Required - The name of the item to make usable. - **cb** (function) - Required - The callback function to execute when the item is used. ### Response This function does not return a value. ``` -------------------------------- ### Get Player Full Name Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/player-class.md Retrieves the player's complete name, typically formatted as 'FirstName LastName', by accessing their character information. ```lua function player:GetName() @return string - Full character name end print(player:GetName()) -- "John Doe" ``` -------------------------------- ### Access Configuration Values Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Access configuration settings directly through the QBCore.Config table. These values represent various server and player settings. ```lua -- Access config local config = QBCore.Config -- Common values config.DefaultSpawn -- vector4 config.MaxPlayers -- number config.Server.PVP -- boolean config.Server.Whitelist -- boolean config.Money.MoneyTypes -- table config.Money.DontAllowMinus -- table config.Player.Bloodtypes -- table config.Commands.OOCColor -- RGB table ``` -------------------------------- ### Get Player Instance in Lua Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/FRAMEWORK_OVERVIEW.md Retrieve the Player class instance for a given source ID. This object manages all player-specific data and methods. ```lua local player = QBCore.Functions.GetPlayer(source) ``` -------------------------------- ### Get Player Data Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/player-class.md Retrieves the current PlayerData table for a player. This can be used to access and print player information like their first name. ```lua local player = QBCore.Functions.GetPlayer(source) local data = player:GetPlayerData() print(data.charinfo.firstname) ``` -------------------------------- ### Dynamically Add QBCore Method Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/server-functions.md Adds a new function to QBCore.Functions at runtime. Ensure the methodName is unique to avoid conflicts. ```lua function QBCore.Functions.SetMethod(methodName, handler) @param methodName string - Method name @param handler function - Method handler @return boolean, string - Success, reason end ``` ```lua exports['qb-core']:SetMethod('MyCustomFunction', function() return 'Hello' end) ``` -------------------------------- ### QBCore.Functions.ToggleOptin Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Allows a staff member to toggle their opt-in status for receiving reports or participating in staff chat. Requires 'admin' permission. ```APIDOC ## QBCore.Functions.ToggleOptin ### Description Allows a staff member to opt in or out of receiving reports or being included in the staff chat (basically go off duty as staff). ### Parameters - **source** (number) - The server ID of the player. ### Example ```lua QBCore.Functions.ToggleOptin(source) ``` ``` -------------------------------- ### Command Callback Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/types.md Register commands that players can execute. This includes defining the command name, help text, arguments, and the callback function to execute when the command is used. ```APIDOC ## Command Callback Registered with `QBCore.Commands.Add(...)`: ### Callback Signature ```lua function callback(source: number, args: table, rawCommand: string) -- source: player who executed command -- args: table of command arguments -- rawCommand: full command text end ``` ### Example ```lua QBCore.Commands.Add('setjob', 'Set a players job', { {name = 'target', help = 'Target player ID'}, {name = 'job', help = 'Job name'}, {name = 'grade', help = 'Grade level'} }, true, function(source, args, rawCommand) local player = QBCore.Functions.GetPlayer(tonumber(args[1])) if player then player:SetJob(args[2], args[3]) end end, 'admin') ``` ``` -------------------------------- ### Register Usable Item Callback Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/types.md Use `QBCore.Functions.CreateUseableItem` to define behavior when a player uses a specific item from their inventory. The callback receives the player's source ID. ```lua -- Callback signature function callback(source: number) -- source: player server ID -- Called when player uses item from inventory end -- Example QBCore.Functions.CreateUseableItem('medkit', function(source) local player = QBCore.Functions.GetPlayer(source) player.Functions.RemoveMoney('cash', 50, 'heal') TriggerClientEvent('heal:animate', source) end) ``` -------------------------------- ### Get Player Source by Identifier Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Finds and returns the server source ID for a player matching the given identifier. Returns 0 if no player is found. ```lua QBCore.Functions.GetSource = function(identifier) for src, player in pairs(QBCore.Players) do local idens = GetPlayerIdentifiers(src) for _, id in pairs(idens) do if identifier == id then return src end end end return 0 end ``` -------------------------------- ### Use Item - QBCore.Functions.UseItem Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Executes the use action for a given item. This function calls the specific item's use function defined in `QBCore.UseableItems`. ```lua QBCore.Functions.UseItem = function(source, item) QBCore.UseableItems[item.name](source, item) end ``` -------------------------------- ### QBCore.Functions.GetPlayerData Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/client-functions.md Retrieves the current player's data. It can be called synchronously to get the data directly or asynchronously with a callback function that will be invoked once the data is available. ```APIDOC ## QBCore.Functions.GetPlayerData ### Description Returns the current player's data, or triggers callback if provided. ### Method `QBCore.Functions.GetPlayerData(cb)` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters Table | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | cb | function \| nil | No | nil | Callback to invoke with PlayerData | ### Returns PlayerData table or nil if callback used ### Request Example ```lua -- Synchronous local playerData = QBCore.Functions.GetPlayerData() print(playerData.charinfo.firstname) -- Asynchronous QBCore.Functions.GetPlayerData(function(playerData) print('Loaded: ' .. playerData.charinfo.firstname) end) ``` ``` -------------------------------- ### Getting the Core Object Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Retrieve the QBCore core object for server-side and client-side operations. You can also fetch a filtered core object with specific fields. ```APIDOC ## Getting the Core Object -- Server-side local QBCore = exports['qb-core']:GetCoreObject() -- Client-side local QBCore = exports['qb-core']:GetCoreObject() -- Get filtered core (only specific fields) local core = exports['qb-core']:GetCoreObject({'Functions', 'Config'}) ``` -------------------------------- ### Register Server Callback (Lua) Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/FRAMEWORK_OVERVIEW.md Use QBCore.Functions.CreateCallback() to register custom server-side callbacks. These can be invoked by client scripts to perform server-side operations. ```lua QBCore.Functions.CreateCallback() ``` -------------------------------- ### Query All Players Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Retrieve lists of players. Get all player IDs, all player objects, players by job, or players currently on duty for a specific job. ```lua local players = QBCore.Functions.GetPlayers() -- All player IDs local players = QBCore.Functions.GetQBPlayers() -- All Player objects local police, count = QBCore.Functions.GetPlayersByJob('police') local onDuty, count = QBCore.Functions.GetPlayersOnDuty('police') ``` -------------------------------- ### Debug Object with QBCore.Debug Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/api-reference/client-functions.md Sends a debug object to the server for console logging. Specify the resource name, the object to debug, and an optional table depth. ```lua function QBCore.Debug(resource, obj, depth) @param resource string - Calling resource name @param obj any - Object to debug print @param depth number | nil - Table depth to print end ``` ```lua QBCore.Debug('my-resource', QBCore.PlayerData, 3) ``` -------------------------------- ### Money Transaction Logging Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/errors.md All `AddMoney` and `RemoveMoney` operations are logged via `qb-log:server:CreateLog` for auditing purposes. ```lua TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'AddMoney', 'lightgreen', '**' .. player.PlayerData.name .. '** $' .. amount .. ' (' .. moneytype .. ')') ``` -------------------------------- ### Get Entity Coordinates with Heading Source: https://github.com/qbcore-framework/qb-core/wiki/Client-Side-Functions Retrieves the coordinates (x, y, z) and heading (a) of an entity. This function is an enhancement over the native GetEntityCoords by including the entity's heading. ```lua QBCore.Functions.GetCoords = function(entity) local coords = GetEntityCoords(entity, false) local heading = GetEntityHeading(entity) return { x = coords.x, y = coords.y, z = coords.z, a = heading } end ``` -------------------------------- ### Get Player Identifier by Type Source: https://github.com/qbcore-framework/qb-core/wiki/Server-Side-Functions Retrieves a player's identifier (Steam or License) based on the configured type. Returns nil if no matching identifier is found. ```lua QBCore.Functions.GetIdentifier = function(source, idtype) local idtype = idtype ~=nil and idtype or QBConfig.IdentifierType for _, identifier in pairs(GetPlayerIdentifiers(source)) do if string.find(identifier, idtype) then return identifier end end return nil end ``` -------------------------------- ### Get and Set Vehicle Properties Source: https://github.com/qbcore-framework/qb-core/blob/main/_autodocs/QUICK_REFERENCE.md Retrieve vehicle properties using GetVehicleProperties and modify them using SetVehicleProperties. Supports various vehicle modifications and cosmetic changes. ```lua local props = QBCore.Functions.GetVehicleProperties(vehicle) QBCore.Functions.SetVehicleProperties(vehicle, { modEngine = 2, modBrakes = 1, color1 = 0, neonEnabled = {true, true, true, true}, neonColor = {255, 0, 0} }) ```