Frameworks: ESX and QBCore · Lesson 5/5 · 8 min

QBCore: the same thing with other names

QBCore does the same as ESX with a different API. If you understand ESX, translating to QBCore is straightforward.

QBCore is the other major framework. It does the same (players, money, jobs) but with different names. Knowing ESX, the translation is almost mechanical.

Get the core and the player

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

local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end

QBCore: core and player

Money and job

lua
-- Money
Player.Functions.AddMoney('cash', 500)
Player.Functions.RemoveMoney('bank', 200)
local cash = Player.PlayerData.money['cash']

-- Job
local job = Player.PlayerData.job.name -- 'police'
local grade = Player.PlayerData.job.grade.level
Player.Functions.SetJob('police', 2)

QBCore: money and job

Quick table ESX ↔ QBCore

  • ESX.GetPlayerFromId(src) ↔ QBCore.Functions.GetPlayer(src)
  • xPlayer.addMoney(n) ↔ Player.Functions.AddMoney('cash', n)
  • xPlayer.getAccount('bank').money ↔ Player.PlayerData.money['bank']
  • xPlayer.job.name ↔ Player.PlayerData.job.name
  • xPlayer.setJob(name, grade) ↔ Player.Functions.SetJob(name, grade)

Many modern scripts use a «bridge» to work on ESX and QBCore at the same time. If you understand both, you'll be able to adapt almost any resource.

Practice what you learned

0/3
Rellena los huecos

Completa para obtener el objeto del core de QBCore.

1local QBCore = exports['qb-core']:()
2local Player = QBCore.Functions.GetPlayer(source)
Pista

Es el equivalente de tener la global ESX en su framework.

Test

¿Cuál es el equivalente en QBCore de xPlayer.addMoney(500)?

Ordena el código

Ordena la traducción a QBCore de: obtener el jugador, comprobar que existe y darle 1000€ al banco.

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

Player.Functions.AddMoney('bank', 1000)
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
local QBCore = exports['qb-core']:GetCoreObject()
Pista

Core → jugador → comprobación → dinero. Es el paralelo de GetPlayerFromId + addAccountMoney.

Challenge: code it yourself

Translate this ESX code to QBCore: give 1000€ to a player's bank, checking that they exist.

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

GetCoreObject → GetPlayer → Player.Functions.AddMoney('bank', 1000).

Escribe aquí tu solución:

How was this lesson?