Custom Roles In Text Chat

I think if you didd it would look weird it would look like this

Example Example | Text

So here is my final script

[code]local Director = {“steam:1100001073E76AA”}
local Rockwall_County_Sheriffs_Office = {“steam:110000106CA7122”, “steam:1100001129598CB”}
local Rockwall_Police_Department = {“steam:XXXXXXX”, “steam:”, “steam:XXXXXXX”}
local Texas_Department_of_Public_Safety = {“steam:110000109EC8A8F”, “steam:110000108CE1BFE”, “steam:110000107AFEDC4”, “steam:110000109E72C83”}
local Civilian = {“steam:11000011193652A”}
local sent

AddEventHandler(‘chatMessage’, function(s, n, m)
CancelEvent()
sent = false
for i=1, #groupOne do
if GetPlayerIdentifiers(s)[1] == Director[i] then
TriggerClientEvent(‘chatMessage’, -1, "Director | " … n, { 255, 0, 0 }, m)
elseif GetPlayerIdentifiers(s)[1] == Rockwall_County_Sheriffs_Office[i] then
TriggerClientEvent(‘chatMessage’, -1, "Rockwall County Sheriffs Office | " … n, { 255, 0, 0 }, m)
elseif GetPlayerIdentifiers(s)[1] == Rockwall_Police_Department[i] then
TriggerClientEvent(‘chatMessage’, -1, "Rockwall Police Department | " … n, { 255, 0, 0 }, m)
elseif GetPlayerIdentifiers(s)[1] == Texas_Department_of_Public_Safety[i] then
TriggerClientEvent(‘chatMessage’, -1, "Texas Department of Public Safety | " … n, { 255, 0, 0 }, m)
elseif GetPlayerIdentifiers(s)[1] == Civilian[i] then
TriggerClientEvent(‘chatMessage’, -1, "Civilian | " … n, { 255, 0, 0 }, m)
elseif sent == false
TriggerClientEvent(‘chatMessage’, -1, "None | " … n, { 255, 0, 0 }, m)
sent = true
end
end
end)[/code]

1 Like

Thank you, helped me out alot.

so that didnt work did i do something wrong

DTOX how did you make out? i am looking to use your script with some edits… did you get it to work or?

just posted in scripting help tried both methods still couldnt get it to work

dam wow wish id could help but i am playing with your script now… no luck

So when I add this:

AddEventHandler('chatMessage', function(s, n, m)
        TriggerClientEvent('chatMessage', -1, 'Citizen | ' .. n, { 255, 0, 0 }, m)
	CancelEvent()
    end
end)

It only pops up saying Citizen | : whatevertheysaid in chat. it doesnt preffix the persons actual name, just replaces it 0.o
the admin and owner ones work flawlessly though…?

Can this be done with IP’s and not Steam ID?

Steam ids are for only when you use steam. ips are for when steam is not running but some servers require steam. but yes, you can use both.

@Al_Rib Yeah I don’t require Steam for my server I wanted to assign them by IP, However I am not get any of this code to work " Most likely something on my end" I just didn’t know how to implement ip… would it be

local Sheriff = {“ip:0.0.0.0”} Or local Sheriff = {“IP:0.0.0.0”} ?

“ip:x.x.x.x” I never got the script to work, but you can try

Following this thread - where you have function(s, n, m) where are the parameters passed in? Is this handled by the framework or…?

Hey can u add me on discord to help me set up a server please?

discord: helicopter#6991

I had this error:

Error parsing script sv_chat.lua in resource chatholes: sv_chat.lua:19: ‘then’ expected near ‘TriggerClientEvent’

So I put “then” after “false” in line 13

elseif sent == false then” like that.

As a newbie programmer, i dont know if it is right. But it worked.

Anyone know how to fix this? Error thrown by mychat roles which worked perfectly on CFX.

Error running system event handling function for resource chatrole: citizen:/scripting/lua/scheduler.lua:41: Failed to execute thread: mychat.lua:84: bad argument #1 to ‘for iterator’ (table expected, got nil)
[ 958656] stack traceback:
[ 958656] [C]: in for iterator ‘for iterator’
[ 958672] mychat.lua:84: in function ‘has_value’
[ 958672] mychat.lua:54: in upvalue ‘handler’
[ 958672] citizen:/scripting/lua/scheduler.lua:163: in function citizen:/scripting/lua/scheduler.lua:162
[ 958672] stack traceback:
[ 958672] [C]: in function ‘error’
[ 958672] citizen:/scripting/lua/scheduler.lua:41: in field ‘CreateThreadNow’
[ 958672] citizen:/scripting/lua/scheduler.lua:162: in function citizen:/scripting/lua/scheduler.lua:131

@NYKILLA1127 If you show the code that you used, especially the parts around line 84, then we can check what’s wrong.

https://pastebin.com/fv0ykXme

Change this (around line 82)

function has_value (tab, val)
    for index, value in ipairs(tab) do

to this:

function has_value (tab, val)
    for index, value in pairs(tab) do

I think that should fix your problem.

May i ask, why hardcode the steam id’s? You already have a DB with roles defined, why not use them?