๐ŸŽฎClient Event Reference

Learn about and how to use common core client events!

QBCore:Client:OnPlayerLoaded

  • Handles the player loading in after character selection

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
    print('Im a client and i just loaded into your server!')
end)

QBCore:Client:OnPlayerUnload

  • Handles the player login out to character selection

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
    print('Im a client and i just logged out of your server!')
end)

QBCore:Client:PvpHasToggled

On player load this event checks is triggered after checking the qb-core config to see if PVP should be enabled or disabled

RegisterNetEvent('QBCore:Client:PvpHasToggled', function(pvp_state)
    print('PVP mode has been set to '..pvp_state..'!')
end)

QBCore:Command:SpawnVehicle

Arguments
Type
Required
Default

vehicle model

string

yes

none

Client example

-- /spawnveh adder

RegisterCommand('spawnveh', function(_, args)
    local vehicle = QBCore.Shared.Trim(args[1])
    TriggerEvent('QBCore:Command:SpawnVehicle', vehicle)
end)

Server example

-- /spawnveh adder

RegisterCommand('spawnveh', function(source, args)
    local vehicle = QBCore.Shared.Trim(args[1])
    TriggerClientEvent('QBCore:Command:SpawnVehicle', source, vehicle)
end)

QBCore:Command:DeleteVehicle

Arguments
Type
Required
Default

none

none

no

none

Client example

RegisterCommand('deleteveh', function(_, args)
    TriggerEvent('QBCore:Command:DeleteVehicle')
end)

Server example

RegisterCommand('deleteveh', function(source, args)
    TriggerClientEvent('QBCore:Command:DeleteVehicle', source)
end)

QBCore:Player:SetPlayerData

RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
    PlayerData = val
    print(QBCore.Debug(PlayerData))
end)

QBCore:Notify

Arguments
Type
Required
Default

message

string | table

yes

'Placeholder'

type

string

yes

'primary'

length

number

yes

5000

Client example

-- /testnotify This is my message, primary, 5000

RegisterCommand('testnotify', function(_, args)
    local message = {}
    for i=1, #args do
        message[#message + 1] = args[i]
        if string.match(args[i], ',') then
            local text = table.concat(message, ' '):gsub(",", "")
            local type = args[i + 1]:gsub(",", "")
            local length = args[i + 2]
            TriggerEvent('QBCore:Notify', text, type, length)
            break
        end
    end
end)

-- Using QBCore's shared functions!

RegisterCommand('testnotify', function(_, args)
    local message = QBCore.Shared.SplitStr(table.concat(args, ' '), ",")
    local text = message[1]
    local type = QBCore.Shared.Trim(message[2])
    local length = tonumber(message[3])
    TriggerEvent('QBCore:Notify', text, type, length)
end)

Server example

-- /testnotify This is my message, primary, 5000

RegisterCommand('testnotify', function(source, args)
    local message = {}
    for i=1, #args do
        message[#message + 1] = args[i]
        if string.match(args[i], ',') then
            local text = table.concat(message, ' '):gsub(",", "")
            local type = args[i + 1]:gsub(",", "")
            local length = args[i + 2]
            TriggerClientEvent('QBCore:Notify', source, text, type, length)
            break
        end
    end
end)

-- Using QBCore's shared functions!

RegisterCommand('testnotify', function(source, args)
    local message = QBCore.Shared.SplitStr(table.concat(args, ' '), ",")
    local text = message[1]
    local type = QBCore.Shared.Trim(message[2])
    local length = tonumber(message[3])
    TriggerClientEvent('QBCore:Notify', source, text, type, length)
end)

QBCore:Client:UseItem

Arguments
Type
Required
Default

item name

string

yes

none

Client example (must have the item in your inventory)

-- /useitem sandwich 1

RegisterCommand('useitem', function(_, args)
    local item = {
        name = args[1],
        amount = tonumber(args[2])
    }
    TriggerEvent('QBCore:Client:UseItem', item)
end)

Server example (must have the item in your inventory)

-- /useitem sandwich 1

RegisterCommand('useitem', function(source, args)
    local item = {
        name = args[1],
        amount = tonumber(args[2])
    }
    TriggerClientEvent('QBCore:Client:UseItem', source, item)
end)

QBCore:Command:ShowMe3D

Arguments
Type
Required
Default

player id

number

yes

none

message

string

yes

none

Client example

-- /3dtext This is my message

RegisterCommand('3dtext', function(_, args)
    local message = table.concat(args, ' ')
    TriggerEvent('QBCore:Command:ShowMe3D', PlayerId(), message)
end)

Server example

-- /3dtext This is my message

RegisterCommand('3dtext', function(source, args)
    local message = table.concat(args, ' ')
    TriggerClientEvent('QBCore:Command:ShowMe3D', source, message)
end)

QBCore:Client:UpdateObject

RegisterNetEvent('QBCore:Client:UpdateObject', function()
    QBCore = exports['qb-core']:GetCoreObject()
end)

Last updated