Jobs, gangs and items · Lesson 2/3 · 6 min

Gangs

QBCore separates the legal job from the criminal one: gangs. They work almost the same as jobs.

Besides the job, QBCore has a second parallel system: gangs, designed for criminal roleplay. A player can have both a job ('unemployed') and a gang ('ballas') at the same time.

lua
local Player = QBCore.Functions.GetPlayer(source)
local gang = Player.PlayerData.gang

local nombre = gang.name        -- 'ballas'
local etiqueta = gang.label     -- 'Ballas'
local rango = gang.grade.level  -- 0, 1, 2...

-- Assign a gang
Player.Functions.SetGang('ballas', 1)

Gangs with QBCore

Gangs are defined in qb-core/shared/gangs.lua. Use them for territory zones, drug sales between gangs, etc. Validation always goes on the server, just like with jobs.

Practice what you learned

0/3
Test

En QBCore, ¿qué relación hay entre el trabajo (job) y la banda (gang) de un jugador?

Rellena los huecos

Completa para asignar al jugador la banda 'ballas' con rango 1.

1local Player = QBCore.Functions.GetPlayer(source)
2Player.Functions.('ballas', 1)
Pista

Es el gemelo de SetJob, pero para bandas.

Ordena el código

Ordena un callback de servidor que devuelve el nombre de la gang del jugador, o 'none' si no tiene.

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

end)
QBCore.Functions.CreateCallback('gang:miBanda', function(source, cb)
cb(Player.PlayerData.gang.name or 'none')
if not Player then return cb('none') end
local Player = QBCore.Functions.GetPlayer(source)
Pista

Registra el callback → obtén el jugador → valida que existe → responde con cb() leyendo la gang.

Challenge: code it yourself

Make a callback that returns the player's gang name, or 'none' if they don't have one.

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

cb(Player.PlayerData.gang.name or 'none').

Escribe aquí tu solución:

How was this lesson?