QBCore in depth: the player and their money · Lesson 1/4 · 8 min

Getting the Core on client and server

Everything in QBCore starts with GetCoreObject. Learn to get it properly on both sides and to wait for the player to load.

QBCore exposes a central object (the "Core") from the qb-core resource. You get it with an export, the same on client and server. From there you have Functions, Shared, etc.

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

Get the Core

In modern versions of QBCore you can get it directly with exports['qb-core']:GetCoreObject(). The old TriggerEvent('QBCore:GetObject', ...) is no longer needed.

On the client: wait for the player to load

lua
local QBCore = exports['qb-core']:GetCoreObject()
local PlayerData = {}

-- When the player joins and loads their character
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
  PlayerData = QBCore.Functions.GetPlayerData()
end)

-- When some data changes (job, money...)
RegisterNetEvent('QBCore:Player:SetPlayerData', function(data)
  PlayerData = data
end)

client.lua

On the client you DON'T have the full Player object (that one lives on the server). You have a read-only COPY: PlayerData. For any action with consequences (money, items) you ask the server.

Practice what you learned

0/3
Rellena los huecos

Completa la línea que obtiene el objeto Core de QBCore (vale igual en cliente y servidor).

1local QBCore = exports['qb-core']:()
Pista

Es un export del recurso qb-core; el viejo TriggerEvent('QBCore:GetObject', ...) ya no hace falta.

Test

En el cliente, ¿qué obtienes realmente del jugador con QBCore?

Ordena el código

Ordena el código de cliente que guarda PlayerData al cargar el personaje e imprime el citizenid.

Coloca las líneas en el orden correcto con las flechas.

local QBCore = exports['qb-core']:GetCoreObject()
print(PlayerData.citizenid)
end)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
PlayerData = QBCore.Functions.GetPlayerData()
local PlayerData = {}
Pista

Core → variable PlayerData → escuchar OnPlayerLoaded → rellenar con GetPlayerData → imprimir.

Challenge: code it yourself

On the client, print your citizenid to the console as soon as the character loads.

Write it yourself in your editor (VS Code) and test it on your server. You learn here by doing it, not by copying.

See hint

Store QBCore.Functions.GetPlayerData() in OnPlayerLoaded and do print(PlayerData.citizenid).

Escribe aquí tu solución:

How was this lesson?