Custom Roles In Text Chat

I was wondering if someone could help me/teach me Lua so that I could make a script that would do this function

Citizen | Text Chat Here
Police | Text Chat Here

So if you were a cop it would show that youre a cop when texting in the chat and if youre a citizen then do the same thing but i would eventually want it to be more advanced so i could put custom roles i.e.

Store Clerk | Text Chat Here
State Trooper | Text Chat Here
Police Officer | Text Chat Here

3 Likes

I have been wanting this for a while, hopefully it gets made!

AddEventHandler('chatMessage', function(s, n, m)
    if GetPlayerIdentifiers(s)[1] == 'steam:11000011865d06f' then 
        TriggerClientEvent('chatMessage', -1, 'Citizen | ' .. n, { 255, 0, 0 }, m)
	CancelEvent()
    end
end)

But you need to change the steamid.

4 Likes

This looks good, but where do we put it?

needs to go into chat_server

1 Like

Ok, thank you very much.

do you change the steamid for each person that you want to have that title?

If you want anyone joining to have civ title then find

    if not WasEventCanceled() then
        TriggerClientEvent('chatMessage', -1, name, color, message)
    end

and change it to

    if not WasEventCanceled() then
        TriggerClientEvent('chatMessage', -1, 'Citizen | ' name, color, message)
    end

Otherwise use for custom titles… There’s easier way to use this but it’s simple. so.

AddEventHandler('chatMessage', function(s, n, m)
    if GetPlayerIdentifiers(s)[1] == 'steam:11000011865d06f' then 
        TriggerClientEvent('chatMessage', -1, 'Owner | ' .. n, { 255, 0, 0 }, m)
	CancelEvent()
    end
end)
3 Likes

I personally wouldn’t edit the core server files such as chat. It can easily be added just like any other script.

do you know how to add something like this?

Just put the code into a .lua along with a __resource.lua that says it is server side code. Then add it to your list of auto start resources.

Code
local groupOne = {"steam:XXXXXXX", "steam:XXXXXXX", "steam:XXXXXXX"}
local groupTwo = {"steam:XXXXXXX", "steam:XXXXXXX", "steam:XXXXXXX"}
local sent

AddEventHandler('chatMessage', function(s, n, m)
	CancelEvent()
	sent = false
	for i=1, #groupOne do
		if GetPlayerIdentifiers(s)[1] == groupOne[i] then
			TriggerClientEvent('chatMessage', -1, "GroupOne | " .. n, { 255, 0, 0 }, m)
		elseif GetPlayerIdentifiers(s)[1] == groupTwo[i] then
			TriggerClientEvent('chatMessage', -1, "GroupTwo | " .. n, { 255, 0, 0 }, m)
		elseif sent == false
			TriggerClientEvent('chatMessage', -1, "None | " .. n, { 255, 0, 0 }, m)
			sent = true
		end
	end
end)

will Defrfinately try this thank you

When you use a command such as the ones in the EssentialMode admin plugin, the command works but it shows the command after. Is there a way to fix this?

So the __resource would look like this

resource_manifest_version ‘77731fab-63ca-442c-a67b-abc70f28dfa5’

server_script ‘sv_chat.lua’

When you use a command such as the ones in the EssentialMode admin plugin, the command works but it shows the command after. Is there a way to fix this? <

Try adding CancelEvent() somewhere in the code that handles the commands.

So the __resource would look like this

resource_manifest_version ‘77731fab-63ca-442c-a67b-abc70f28dfa5’

server_script ‘sv_chat.lua’

If you have the code inside a file called sv_chat.lua then yes.

2 Likes

Ok, will try and see if it works.

local Director = {“steam:XXXXXXX”, “steam:XXXXXXX”, “steam:XXXXXXX”}
local Rockwall County Sheriffs Office = {“steam:XXXXXXX”, “steam:XXXXXXX”, “steam:XXXXXXX”}
local Rockwall Police Department = {“steam:XXXXXXX”, “steam:XXXXXXX”, “steam:XXXXXXX”}
local Texas Department of Public Safety = {“steam:XXXXXXX”, “steam:XXXXXXX”, “steam:XXXXXXX”}
local Civilian = {“steam:XXXXXXX”, “steam:XXXXXXX”, “steam:XXXXXXX”}
local sent

AddEventHandler(‘chatMessage’, function(s, n, m)
CancelEvent()
sent = false
for i=1, #groupOne do
if GetPlayerIdentifiers(s)[1] == groupOne[i] then
TriggerClientEvent(‘chatMessage’, -1, "GroupOne | " … n, { 255, 0, 0 }, m)
elseif GetPlayerIdentifiers(s)[1] == groupTwo[i] then
TriggerClientEvent(‘chatMessage’, -1, "GroupTwo | " … n, { 255, 0, 0 }, m)
elseif sent == false
TriggerClientEvent(‘chatMessage’, -1, "None | " … n, { 255, 0, 0 }, m)
sent = true
end
end
end)

Where would I go from here

2 Likes

Well the variable names can’t have spaces, so Director is fine but Rockwall County Sherrifs Office would need to be changed to something like RCSO or Rockwall_County… Same for the other names.

Then just change:
if GetPlayerIdentifiers(s)[1] == groupOne[i] then
to
if GetPlayerIdentifiers(s)[1] == Director[i] then
and add more elseif statements which have your other tables.

Also just to make sure, you gotta change “steam:XXXXXX” to actual steam IDs in that format

2 Likes

ok thank you so much this was a lot of help

Could you add one person to multiple groups?