You are using the RegisterCommand function, so this has a built in optional parameter at the end, where you set true or false to set “admin only”. So true is admins only and false is everyone. By default it’s false so you don’t need to add it for every command you register, but here you can see that you DO have it. So simply change it to true.
RegisterCommand('staff', function(source, args, rawCommand)
local playerName = GetPlayerName(source)
local msg = rawCommand:sub(6)
TriggerClientEvent('chat:addMessage', -1, {
template = '< div style=“padding: 0.5vw; margin: 0.5vw; background-color: rgba(255, 140, 0, 1); border-radius: 3px;”>< i class=“fab fa-twitter”>< /i> ZuiderMeer Staff: < b >{0}< /b>: {1}</ div>',
args = { playerName, msg }
})
end, true) -- true = admin only, false = all players
@ZuiderMeerRP Responding here instead of the private message, because others should be able to learn as you learn.
Yes, setting that false at the end to true, as I did, will make it admins only.
For police/ems to use it, you can do something different.
You can set it back to false so all players can use it, but then check the player’s job.
I might add that these are SERVER SIDE commands, not client side.
Here is an example of a command for players with the job “police”.
RegisterCommand('police', function(source, args, rawCommand)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name == 'police' then
local playerName = GetPlayerName(source)
local msg = rawCommand:sub(6)
TriggerClientEvent('chat:addMessage', -1, {
template = '< div style=“padding: 0.5vw; margin: 0.5vw; background-color: rgba(255, 140, 0, 1); border-radius: 3px;”>< i class=“fab fa-twitter”>< /i> Police: < b >{0}< /b>: {1}</ div>',
args = { playerName, msg }
})
else
TriggerClientEvent('esx:showNotification', source, 'This is for Police only!')
end
end, false)
[ script:esx_rpchat] SCRIPT ERROR: @esx_rpchat/server/main.lua:80: attempt to index a nil value (global ‘ESX’)
[ script:esx_rpchat] > ref (@esx_rpchat/server/main.lua:80)
What is on line 80?
Share the file? Or at least the function that includes line 80?
I imagine it is local xPlayer = ESX.GetPlayerFromId(source)
You ARE using ESX yeah? Not just using esx_rpchat without using ESX?
Make sure you have the following at the top of the script, if you are using ESX.