Per-job wheels
Swap the Eleven Radial wheel by job, duty or vehicle with SetContext and ClearContext. Copy-ready Lua examples for Qbox, QBCore, ESX and ox_lib on FiveM.
Eleven Radial has no per-job option in config.lua. That's what the client exports SetContext and ClearContext are for: one of your scripts swaps the wheel for as long as a situation lasts (on duty, inside a vehicle, in a house…) and then hands the normal wheel back.
How a context wheel works
- It replaces the player's wheel while it's active. It isn't saved and doesn't touch the slots the player has edited.
- It can't be edited: with a context wheel, SPACE doesn't open the editor.
- It's drawn with the actions you pass: 3 actions give 3 large slices; more than 8 are split into pages.
- Each action is
{ id, label, command, icon? }. There's nocolor: it uses the default colour. The icon is optional and must be in the icon list. - It clears itself when the character unloads (character switch or disconnect). When another character loads, call
SetContextagain if needed. - If the wheel is open when you change the context, it's redrawn straight away.
| Export (client) | What it does |
|---|---|
SetContext(list) | Turns on the context wheel with that list. An empty list or nil works like ClearContext |
ClearContext() | Goes back to the player's normal wheel. Does nothing if it's already the normal one |
The commands you use must exist on your server: the wheel runs them just as if the player typed them in chat.
Qbox and QBCore: on-duty police wheel
Qbox fires the same client events as QBCore (QBCore:Client:OnPlayerLoaded, QBCore:Client:OnJobUpdate, QBCore:Client:SetDuty), so this example works for both. It goes in the client.lua of one of your own resources.
local POLICE_WHEEL = {
{ id = 'radio', label = 'Radio', command = '/radio', icon = 'icon-radio' },
{ id = 'cuff', label = 'Cuff', command = '/cuff', icon = 'icon-shield' },
{ id = 'mdt', label = 'Tablet', command = '/mdt', icon = 'icon-clipboard' },
{ id = 'emotes', label = 'Emotes', command = '/emotemenu', icon = 'icon-play-circle' },
}
local function getPlayerData()
if GetResourceState('qbx_core') == 'started' then
return exports.qbx_core:GetPlayerData()
end
return exports['qb-core']:GetCoreObject().Functions.GetPlayerData()
end
local function updateWheel(job)
if job and job.name == 'police' and job.onduty then
exports['eleven-radial']:SetContext(POLICE_WHEEL)
else
exports['eleven-radial']:ClearContext()
end
end
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
local data = getPlayerData()
updateWheel(data and data.job)
end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)
updateWheel(job)
end)
RegisterNetEvent('QBCore:Client:SetDuty', function()
local data = getPlayerData()
updateWheel(data and data.job)
end)
Replace 'police' with your job name and the commands with your scripts' ones (/radio, /cuff and /mdt are just examples).
ESX: wheel per job
local ESX = exports.es_extended:getSharedObject()
local WHEELS = {
mechanic = {
{ id = 'repair', label = 'Repair', command = '/repair', icon = 'icon-tool' },
{ id = 'tow', label = 'Tow', command = '/tow', icon = 'icon-truck' },
},
}
local function updateWheel(job)
local list = job and WHEELS[job.name]
if list then
exports['eleven-radial']:SetContext(list)
else
exports['eleven-radial']:ClearContext()
end
end
RegisterNetEvent('esx:playerLoaded', function(xPlayer)
updateWheel(xPlayer and xPlayer.job)
end)
RegisterNetEvent('esx:setJob', function(job)
updateWheel(job)
end)
Inside a vehicle (with ox_lib)
ox_lib's lib.onCache('vehicle', …) fires when the player gets in or out of a vehicle:
lib.onCache('vehicle', function(vehicle)
if vehicle then
exports['eleven-radial']:SetContext({
{ id = 'engine', label = 'Engine', command = '/engine', icon = 'icon-power' },
{ id = 'lock', label = 'Lock', command = '/lock', icon = 'icon-key' },
})
else
exports['eleven-radial']:ClearContext()
end
end)
To use lib in your resource, add '@ox_lib/init.lua' to its shared_scripts.
Warning
If several of your scripts call SetContext, the last one wins. There's no context stack: one script's ClearContext also removes the other's. Decide in one place which wheel applies at any moment.
Clean up when your resource stops
The context wheel lives inside eleven-radial. If you stop or restart your script, clear it so the player isn't left with it:
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
exports['eleven-radial']:ClearContext()
end
end)
And the other way round: if you restart eleven-radial, the context is lost. Apply it again when it starts:
AddEventHandler('onClientResourceStart', function(resource)
if resource == 'eleven-radial' then
-- call your function again here, e.g. updateWheel(...)
end
end)
Server exports
You can't set a context from the server, but you can reload or reset a player's saved wheel:
exports['eleven-radial']:RefreshPlayer(source) -- reload their wheel
exports['eleven-radial']:ResetPlayer(source) -- delete their saved wheel: back to Config.DefaultItems
Both return true or false. More in Configuration.