Hey guys, I’m working in a function for the RadialMenu, basically I want that when you press the button if your job name is “ambulance” you get the ambulance menu, if is “police” the police one …
So I have created a variable named “funzione”, when I try to check the job for then changing the variable I get xPlayer = nil
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if xPlayer.job.Name == "ambulance" then
local funzione = "esx_ambulancejob:openmobile"
end
if xPlayer.job.Name == "bennys" then
local funzione = "bennysmenu"
end
if xPlayer.job.Name == "import" then
local funzione = "importmenu"
end
end)
And then in the sub menu
['general:lavoro'] = {
title = "Menu Lavoro",
icon = "#general-escort",
functionName = funzione
},
My question is:
Where can I define xPlayer to check the job of the player? And how?
Try this in client.lua
function setupSubItems()
local PlayerData = ESX.GetPlayerData()
if Config.JobInteractions[PlayerData.job.name] ~= nil and next(Config.JobInteractions[PlayerData.job.name]) ~= nil then
Config.MenuItems[3].items = Config.JobInteractions[PlayerData.job.name]
else
Config.MenuItems[3].items = {}
end
end
in client.lua in your OpenRadial function, I mean set nui focus add
setupSubItems()
and in Config.lua add
Config.JobInteractions = {
["mechanic"] = {
{
title = "Menu Lavoro",
icon = "#general-escort",
functionName = funzione
},
},
}
This code may not work with your RadialMenu. But its example how to do it.
Ok let’s say I changed it completely while looking at ur code.
Now it is
['general:lavoro'] = {
title = "Menu Lavoro",
icon = "#general-escort",
functionName = "NR_JobHandler:controllo"
},
So I created a script (client.lua):
ESX = nil TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterNetEvent('NR_JobHandler:controllo')
AddEventHandler('NR_JobHandler:controllo', function(lavoro)
local PlayerData = ESX.GetPlayerData()
local lavoro = PlayerData.job.name
if lavoro == "ambulance" then
xPlayer.triggerEvent("esx_ambulancejob:openmobile")
end
end)
The problem now is that xPlayer is a nil value, how can I solve?
Well the problem here was that I did xPlayer.triggerEvent(“event”)
Instead of only TriggetEvent --(lol)