Hope someone can help ne

Hi everyone,

Im looking for a way to edit this code so that not everyone can abuse the ‘‘Admin/Staff message’’.

Can someone help me getting this connected to a job or group or license i dont know… I dont want ‘‘normal civilians’’ to use this admin chat command :slight_smile:

The code (i putted it in esx_rpchat → server.lua) works perfectly:

RegisterCommand(‘staff’, function(source, args, rawCommand)
local playerName = GetPlayerName(source)
local msg = rawCommand:sub(6)
fal = playerName
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 = { fal, msg }
})
end, false)

this is how it looks like:

If you have any question what I want let me know

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

Admin only is defined as the Ace Permission group of the player.
See the native reference docs for more info → RegisterCommand - Natives @ Cfx.re Docs

@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)

Amazing!

I get a error, u familiar with it ?

[ 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.

ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

This works like a charm! I owe you big time.

Really thanks for helping me, excellent work.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.