[Release] Chat Roles [UPDATED 5/30/18] [Tutorial Released]

If you have a Hide Command script it interferes with the one built in with the rolesFX.

I got a double text
https://gyazo.com/fbe31497b2b036b2810b4822c5177c9b

for anyone who’s encountering double messages in the chat, verify that u dont have another chat resource, that’s the reason why is double message

https://gyazo.com/61f1d6024ccb86e27b95d9062259e2ae

Work fine but on the console i got this error, anyone have idea for thit

Error running system event handling function for resource rolesFX: citizen:/scripting/lua/scheduler.lua:41: Failed to execute thread: @rolesFX/sv_chat.lua:29: bad argument #1 to ‘find’ (string expected, got table)

@FAXES has a hide cmd script [Release] Hide Commands - Hide mis-spelled commands in chat! [fax-hidecmds] [1.1]

how would I make it so that the player’s name isnt colored but only the role is?

Is there a limit on the number of roles? If I have too many if/elses - it bombs once it reaches a magical “too many” number. The number is about 6-7 if/else checks before it just quits… How? Why?

Is there something running /t that has a wait timer on it that is timing out?

I’ve had many more than that and it has worked fine

Is it possible that I’m hitting the Discord bot too much and I haven’t set it up to handle that many checks? I’m just not understanding why if I have “a lot” of roles that I’m checking it just stops working.

I have rewritten this script to minimise repetition of code, while allowing for more options in terms of titles.

-- roles (updated by bazilcat)
-- this array is the staff ranks, odd numbers are staff members, even numbers are their ranks
-- example  ChatRoles = {"steam:111111111111111", "Server Staff", "7",} ChatRoles[1] is the hex, ChatRoles[2] is their rank and ChatRoles[3] is the colour
-- a rank can be obtained by finding their hex in the array then incrimenting by one, the colour for that rank is the name incrimented by two
-- colours: 1 red, 2 light green, 3 light yellow, 4 dark blue, 5 light blue, 6 violet, 7 white, 8 blood red, 9 fuchsia.

local ChatRoles = {	
	"steam:111111111111111", "title", "1", -- example
}


-- none of this needs to be touched to add new roles
AddEventHandler('chatMessage', function(Source, Name, Msg)
    args = stringsplit(Msg, " ")
    CancelEvent()
    if string.find(args[1], "/") then
        local cmd = args[1]
        table.remove(args, 1)
    else
		local player = GetPlayerIdentifiers(Source)[1]
		if has_value(player) < 1 then
			TriggerClientEvent('chatMessage', -1, "^7" .. Name .. " ^6(ID: " .. Source .. "^6) ", { 128, 128, 128 }, Msg)
		else
			TriggerClientEvent('chatMessage', -1, "^" .. ChatRoles[has_value(player)+2] .."[" .. ChatRoles[has_value(player)+1] .. "] ^7" .. Name .. " ^" .. ChatRoles[has_value(player)+2] .."(ID: " .. Source .. "^".. ChatRoles[has_value(player)+2] ..")", { 128, 128, 128 }, Msg)
		
		end
    end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

function has_value (player)
    for index, value in ipairs(ChatRoles) do
        if value == player then
            return index
        end
    end

    return 0
end

this script don’t work for me do i have to disable the old chat?

Im a noobie so sorry if this is a stupid question, is there a way to add players to say ‘citizen’? cus from what i can see you have to manually add each players steam id to a role?

no trouble, anybody with any skill level was a newbie once…

i stripped that functionality out of my version, here’s a version with it added back:

-- roles (updated by bazilcat)
-- this array is the staff ranks, odd numbers are staff members, even numbers are their ranks
-- example  ChatRoles = {"steam:111111111111111", "Server Staff", "7",} ChatRoles[1] is the hex, ChatRoles[2] is their rank and ChatRoles[3] is the colour
-- a rank can be obtained by finding their hex in the array then incrimenting by one, the colour for that rank is the name incrimented by two
-- colours: 1 red, 2 light green, 3 light yellow, 4 dark blue, 5 light blue, 6 violet, 7 white, 8 blood red, 9 fuchsia.

local ChatRoles = {	
	"steam:111111111111111", "title", "1", -- example
}

--this controls the title of users who's Hexes aren't listed
-- it works like ChatRoles, the first one is the title, the second is the colour of the title
-- colours: 1 red, 2 light green, 3 light yellow, 4 dark blue, 5 light blue, 6 violet, 7 white, 8 blood red, 9 fuchsia.
local StandardTitle = {"Citizen", "9"}

-- none of this needs to be touched to add new roles
AddEventHandler('chatMessage', function(Source, Name, Msg)
    args = stringsplit(Msg, " ")
    CancelEvent()
    if string.find(args[1], "/") then
        local cmd = args[1]
        table.remove(args, 1)
    else
		local player = GetPlayerIdentifiers(Source)[1]
		if has_value(player) < 1 then
			TriggerClientEvent('chatMessage', -1, "^" .. StandardTitle[2] .. "[" .. StandardTitle[1] .."] ^7" .. Name .. " ^" .. StandardTitle[2] .. "(ID: " .. Source .. "^" .. StandardTitle[2] .. ") ", { 128, 128, 128 }, Msg)
		else
			TriggerClientEvent('chatMessage', -1, "^" .. ChatRoles[has_value(player)+2] .."[" .. ChatRoles[has_value(player)+1] .. "] ^7" .. Name .. " ^" .. ChatRoles[has_value(player)+2] .."(ID: " .. Source .. "^".. ChatRoles[has_value(player)+2] ..")", { 128, 128, 128 }, Msg)
		
		end
    end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

function has_value (player)
    for index, value in ipairs(ChatRoles) do
        if value == player then
            return index
        end
    end

    return 0
end

hope this helps :smiley:

1 Like

you need to stop the original, then replace the code with this and restart it.
Failing this, here is my current version set up as a standalone resource
chatroles.rar (1.2 KB)

1 Like

how is your civ set?

what?

Thanks so much!

Having a small issue, i can get the Owner role too work but when im doing other staff they still come up has citizens any quick fix?


-- roles (updated by bazilcat)
-- this array is the staff ranks, odd numbers are staff members, even numbers are their ranks
-- example  ChatRoles = {"steam:111111111111111", "Server Staff", "7",} ChatRoles[1] is the hex, ChatRoles[2] is their rank and ChatRoles[3] is the colour
-- a rank can be obtained by finding their hex in the array then incrimenting by one, the colour for that rank is the name incrimented by two
-- colours: 1 red, 2 light green, 3 light yellow, 4 dark blue, 5 light blue, 6 violet, 7 white, 8 blood red, 9 fuchsia.

local ChatRoles = {	
	"steam:11000011a804ed1", "Owner", "8", -- Minnesota
	"steam:11000011555301C", "Owner", "8", -- Robert 
	"steam:11000011914A210", "Mod", "1", -- Levi.R
	"steam:110000115b95ecd", "Mod", "1", -- Dice.Tucker
	"steam:110000136df58bf", "Mod", "1", -- Jacob
	"steam:111111111111111", "title", "1", -- example
}

--this controls the title of users who's Hexes aren't listed
-- it works like ChatRoles, the first one is the title, the second is the colour of the title
-- colours: 1 red, 2 light green, 3 light yellow, 4 dark blue, 5 light blue, 6 violet, 7 white, 8 blood red, 9 fuchsia.
local StandardTitle = {"Citizen", "9"}

-- none of this needs to be touched to add new roles
AddEventHandler('chatMessage', function(Source, Name, Msg)
    args = stringsplit(Msg, " ")
    CancelEvent()
    if string.find(args[1], "/") then
        local cmd = args[1]
        table.remove(args, 1)
    else
		local player = GetPlayerIdentifiers(Source)[1]
		if has_value(player) < 1 then
			TriggerClientEvent('chatMessage', -1, "^" .. StandardTitle[2] .. "[" .. StandardTitle[1] .."] ^7" .. Name .. " ^" .. StandardTitle[2] .. "(ID: " .. Source .. "^" .. StandardTitle[2] .. ") ", { 128, 128, 128 }, Msg)
		else
			TriggerClientEvent('chatMessage', -1, "^" .. ChatRoles[has_value(player)+2] .."[" .. ChatRoles[has_value(player)+1] .. "] ^7" .. Name .. " ^" .. ChatRoles[has_value(player)+2] .."(ID: " .. Source .. "^".. ChatRoles[has_value(player)+2] ..")", { 128, 128, 128 }, Msg)
		
		end
    end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

function has_value (player)
    for index, value in ipairs(ChatRoles) do
        if value == player then
            return index
        end
    end

    return 0
end

Only thing i can see is the line break after – Robert try deleting it?

1 Like