Hello. Someone on Reddit very kindly gave an example of how to remove player color codes using regex, below is the example:
local name = “My~r~Red~g~Name~w~”
print(tostring(name:gsub("(~%w~)", “”)))
However, im unsure as to how to implement this into FiveM. Id like to use this code to remove players color codes upon joining, because people with rainbow names etc can be annoying, and alot of servers use colored names to represent staff etc. Im just unsure of the process of changing there name. Any help would be appreciated
local names = {}
local nametable = {
["~r~"] = "",
["~g~"] = "",
["~o~"] = "",
["~b~"] = "",
["~m~"] = "",
["~p~"] = "",
}
AddEventHandler("playerConnecting", function(name)
local src = source
print("Name before: " .. name)
for k,v in pairs(nametable) do
name = string.gsub(name, k, v)
end
print("Name after: " .. name)
names[src] = name
end)
function GetNewPlayerName(id)
for k,v in pairs(names) do
if (k == id) then
return v
end
end
return GetPlayerName(id)
end
Ok just i dropped it into a folder with a __resouce.lua, and put that code in a server.lua, but it doesnt seemed to have worked. Cant be far off tho as code looks great. Im no lua expert tho
Wait it works to an extent. In the console it is printing the correct name change, but just not in the server. Might be because i use rolesFX for the chat, and its using the old name? Im not sure