Having a little issue getting a script to work, my goal is to only allow specific jobs to use the command but I can’t get the command to actually call, I have a server and client script I’m testing it on using 3DME - Elio
Here is the code:
Client
ESX = nil
local PlayerData = {}
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
while ESX.GetPlayerData().job == nil do
Citizen.Wait(10)
end
PlayerData = ESX.GetPlayerData()
end)
RegisterNetEvent("esx:setJob")
AddEventHandler("esx:setJob", function(job)
PlayerData.job = job
end)
RegisterCommand('me', function()
if PlayerData.job ~= nil then
if PlayerData.job.name == 'police' or PlayerData.job.name == 'fire' or PlayerData.job.name == 'ambulance'then
RegisterNetEvent('3dme:shareDisplay')
AddEventHandler('3dme:shareDisplay', function(text, serverId)
local ped = GetPlayerPed(GetPlayerFromServerId(serverId))
Display(ped, text)
end)
ESX.ShowNotification('THIS WORKED!')
else
ESX.ShowNotification('You are not permitted to use this command')
end
end
end, false)
CreateThread(function()
while true do
Wait(0)
end
end)
Server
local function TableToString(tab)
local str = ""
for i = 1, #tab do
str = str .. " " .. tab[i]
end
return str
end
-- --------------------------------------------
-- Commands
-- --------------------------------------------
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent('ref:reference')
AddEventHandler('ref:reference', function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if xPlayer.job.name == 'police' then
RegisterCommand('me', function(source, args)
local text = "ME - " .. TableToString(args) .. " "
TriggerClientEvent('3dme:shareDisplay', -1, text, source)
end)
else
TriggerClientEvent('esx:showNotification', _source, 'NOT THE RIGHT JOB')
end
end)
Any help would be greatly appreciated, I have not included all the client script because I believe that its unneeded, the the client code for passing the text shows up fine but the function doesn’t get called to show the message above the head.