W-DevelopmentW-Development
Frameworks Updated 13 min read

Writing your first QBCore script

Learn QBCore scripting: GetCoreObject, PlayerData, money types, AddItem and RemoveItem, jobs, useable items, commands and a complete example resource.

Overview

QBCore is the other big roleplay framework. Where ESX has xPlayer, QBCore has a Player object with PlayerData and Functions. The concepts — money, items, jobs, commands, loaded events — map almost one to one, so moving between the two is mostly vocabulary.

01Getting the core object

client.lua and server.lualua
local QBCore = exports['qb-core']:GetCoreObject()
fxmanifest.lualua
fx_version 'cerulean'
game 'gta5'
lua54 'yes'

shared_script 'config.lua'
client_script 'client.lua'
server_script 'server.lua'

dependency 'qb-core'

The Player object

TaskCode
Get the playerlocal Player = QBCore.Functions.GetPlayer(source)
Character IDPlayer.PlayerData.citizenid
MoneyPlayer.PlayerData.money.cash, Player.Functions.AddMoney('bank', n, reason), RemoveMoney
ItemsPlayer.Functions.AddItem('bread', 1), Player.Functions.RemoveItem('bread', 1), GetItemByName
JobPlayer.PlayerData.job.name, .job.grade.level, .job.onduty, Player.Functions.SetJob('police', 0)
NotifyTriggerClientEvent('QBCore:Notify', source, 'Saved', 'success')
Player by citizenidQBCore.Functions.GetPlayerByCitizenId(cid)

02A complete example: selling fish

server.lualua
local QBCore = exports['qb-core']:GetCoreObject()
local PRICE = 45
local MARKET = vec3(-1845.0, -1195.0, 14.3)

RegisterNetEvent('fishmarket:sell', function()
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    if not Player then return end

    if #(GetEntityCoords(GetPlayerPed(src)) - MARKET) > 5.0 then return end

    local item = Player.Functions.GetItemByName('fish')
    local count = item and item.amount or 0
    if count < 1 then
        return TriggerClientEvent('QBCore:Notify', src, 'You have no fish', 'error')
    end

    if Player.Functions.RemoveItem('fish', count) then
        Player.Functions.AddMoney('cash', count * PRICE, 'fish-market')
        TriggerClientEvent('QBCore:Notify', src, ('Sold %d fish for $%d'):format(count, count * PRICE), 'success')
    end
end)
client.lualua
local MARKET = vec3(-1845.0, -1195.0, 14.3)

CreateThread(function()
    while true do
        local sleep = 1000
        if #(GetEntityCoords(PlayerPedId()) - MARKET) < 2.0 then
            sleep = 0
            if IsControlJustReleased(0, 38) then
                TriggerServerEvent('fishmarket:sell')
            end
        end
        Wait(sleep)
    end
end)

Usable items

server.lualua
QBCore.Functions.CreateUseableItem('bandage', function(source, item)
    local Player = QBCore.Functions.GetPlayer(source)
    if Player.Functions.RemoveItem(item.name, 1, item.slot) then
        TriggerClientEvent('medical:useBandage', source)
    end
end)

Define the item in qb-core/shared/items.lua (or in ox_inventory/data/items.lua if you run ox_inventory). The shared list is available as QBCore.Shared.Items.

Commands

server.lualua
QBCore.Commands.Add('givefish', 'Give fish to a player', {
    { name = 'id', help = 'Player ID' },
    { name = 'amount', help = 'Amount' },
}, true, function(source, args)
    local target = QBCore.Functions.GetPlayer(tonumber(args[1]))
    if target then target.Functions.AddItem('fish', tonumber(args[2]) or 1) end
end, 'admin')

The last argument is the permission level (user, mod, admin, god), which QBCore maps to ACE groups like qbcore.admin — see ACE permissions.

Client-side player data

client.lualua
local PlayerData = {}

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
    PlayerData = QBCore.Functions.GetPlayerData()
end)

RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)
    PlayerData.job = job
end)

Compare with the ESX tutorial — the same fish market, different vocabulary. Qbox, the QBCore successor, keeps most of this API while moving to ox_lib patterns.

Frequently asked questions

How do I get the QBCore object?

local QBCore = exports['qb-core']:GetCoreObject() in both client and server scripts.

How do I add money in QBCore?

Player.Functions.AddMoney('cash', amount, reason) — or 'bank' / 'crypto'.

Where are QBCore items defined?

In qb-core/shared/items.lua, or in your inventory resource if it keeps its own list (ox_inventory).

How do I restrict a QBCore command to admins?

Pass 'admin' as the last argument of QBCore.Commands.Add and give staff the matching ACE group.

Need this built, not just explained?

Premium ESX, QBCore & Qbox scripts with instant delivery — or a custom resource, React NUI and the web stack around your server, built to spec.

Related guides