Skip to Content
APIQBCore Server Functions Reference

QBCore server functions

These signatures are pinned to server/functions.lua.

Player lookup

FunctionCurrent signature
GetIdentifierGetIdentifier(source, idType)
GetSourceGetSource(identifier) → source or 0
GetPlayerGetPlayer(source)
GetPlayerByCitizenIdGetPlayerByCitizenId(citizenId)
GetOfflinePlayerByCitizenIdGetOfflinePlayerByCitizenId(citizenId)
GetPlayerByLicenseGetPlayerByLicense(license)
GetPlayerByPhoneGetPlayerByPhone(number)
GetPlayersByJobGetPlayersByJob(job, checkOnDuty)
GetDutyCountGetDutyCount(job)

Callbacks, usable items, and permissions

FunctionCurrent signature
CreateCallbackCreateCallback(name, callback)
TriggerClientCallbackTriggerClientCallback(name, source, [callback], ...)
CreateUseableItemCreateUseableItem(item, callback)
CanUseItemCanUseItem(item) → registration or nil
UseItemUseItem(source, item)
HasItemHasItem(source, items, amount) → boolean; deprecated in favor of the inventory export
AddPermissionAddPermission(source, permission)
RemovePermissionRemovePermission(source, permission)
HasPermissionHasPermission(source, permission)
GetPermissionGetPermission(source)
QBCore.Functions.CreateCallback('myresource:server:getJob', function(source, callback) local Player = QBCore.Functions.GetPlayer(source) callback(Player and Player.PlayerData.job or nil) end)

World, vehicles, and buckets

Current world helpers include GetClosestPlayer, GetClosestObject, GetClosestVehicle, and GetClosestPed. Vehicle creation functions are:

  • SpawnVehicle(source, model, coords, warp) → entity handle
  • CreateAutomobile(source, model, coords, warp) → entity handle
  • CreateVehicle(source, model, vehicleType, coords, warp) → entity handle

Vehicle creation

All three vehicle functions are server side but not equal. The upstream comment above SpawnVehicle states that the CreateVehicle RPC still performs creation on a client, so a player has to be nearby. CreateAutomobile and CreateVehicle map onto the server-side creation natives. See OneSync, scope, and networked entities for when that distinction matters.

Routing buckets

The core keeps two module-level registries alongside the native calls:

TableKeyValue
QBCore.Player_Bucketsthe player’s license identifier{ id = source, bucket = bucket }
QBCore.Entity_Bucketsthe entity handle{ id = entity, bucket = bucket }

Both are plain Lua tables in the core’s server state. They are a convenience index over the natives, not the authority. The routing bucket itself is owned by the server runtime.

Signatures

FunctionSignatureReturns
GetBucketObjectsGetBucketObjects()Two tables: the player registry, then the entity registry
SetPlayerBucketSetPlayerBucket(source, bucket)true on success, false when either argument is falsy
SetEntityBucketSetEntityBucket(entity, bucket)true on success, false when either argument is falsy
GetPlayersInBucketGetPlayersInBucket(bucket)Array of player sources
GetEntitiesInBucketGetEntitiesInBucket(bucket)Array of entity handles

The upstream annotations on the two getters say table|boolean. The implementations always return a table, empty when nothing matches. Test with #result == 0, not with if not result.

SetPlayerBucket does two things

function QBCore.Functions.SetPlayerBucket(source, bucket) if source and bucket then local plicense = QBCore.Functions.GetIdentifier(source, 'license') Player(source).state:set('instance', bucket, true) SetPlayerRoutingBucket(source, bucket) QBCore.Player_Buckets[plicense] = { id = source, bucket = bucket } return true else return false end end

Besides calling the native, it writes the bucket ID into the player’s state bag under the key instance with replication enabled. Client scripts can therefore read the current bucket without a round trip:

-- client side local instance = LocalPlayer.state.instance

That also means any other resource writing to instance on the same state bag will disagree with the actual routing bucket. Pick one owner for that key.

Note the guard is if source and bucket. Bucket 0, the default bucket, is truthy in Lua, so returning a player to bucket 0 works. A nil bucket returns false without changing anything.

Cleanup differs between the two registries

QBCore.Player_Buckets is cleared for a player in the playerDropped handler in server/events.lua, keyed by the license on their PlayerData.

QBCore.Entity_Buckets has no cleanup anywhere in the core at this commit. Entries persist after the entity is deleted, so GetEntitiesInBucket can return stale handles. Validate before use:

local entities = QBCore.Functions.GetEntitiesInBucket(4) for i = 1, #entities do if DoesEntityExist(entities[i]) then -- safe to act on this handle end end

If your resource creates and destroys many entities inside buckets, clear your own entries or track them yourself rather than relying on this table.

Reading a bucket back

GetPlayersInBucket scans the core’s registry, so it only knows about players moved through SetPlayerBucket. A player moved with the native SetPlayerRoutingBucket directly is invisible to it. The natives GET_PLAYER_ROUTING_BUCKET and GET_ENTITY_ROUTING_BUCKET read the real value.

Using a bucket as an instance

What a bucket is for, which use cases the Cfx.re documentation names, why it says interiors are not among them, and the four lockdown modes are covered once in OneSync, scope, and networked entities. Read that before designing around buckets. What follows is only how the core wrappers are used.

-- server side, an isolated instance a player cannot spawn into local BUCKET = 42 SetRoutingBucketEntityLockdownMode(BUCKET, 'strict') SetRoutingBucketPopulationEnabled(BUCKET, false) QBCore.Functions.SetPlayerBucket(source, BUCKET) local vehicle = CreateVehicleServerSetter(joaat('blista'), 'automobile', 0.0, 0.0, 72.0, 0.0) QBCore.Functions.SetEntityBucket(vehicle, BUCKET)

Remember to move the player back, and to delete the entities and forget their registry entries, when the instance ends.

The core does not currently expose GetItems, GetVehiclesByName, GetJobs, GetGangs, ExecuteSql, or player item mutation methods. Read shared definitions through QBCore.Shared.Items, QBCore.Shared.Vehicles, QBCore.Shared.Jobs, and QBCore.Shared.Gangs; use the deployed inventory resource for inventory mutation.