Need some advice with this code please :

Hey guys, so yesterday i was browse ring the gmod wiki a bit and wanted to make something special for superadmins etc. in my TTT server. So i came out with this code

Basicly how the final looks of the code must like is that when u write something in public chat, it says Leader: [text] Of course only when the player is in group Superadmin.

The code:

[lua]
local function AddChatColorText(ply, text)
if ply:IsSuperAdmin then
chat.AddText(Color(50, 200, 255),
[Leader] ply:Nick(),
Color(255,255,255),
": " … text)
end
[/lua]

But it doesnt seem to work?

I placed it into lua/autorun.

Thanks ^^

Edit: I founded this code [lua]Format("(%s) ", string.upper(GetTranslation(“Leader”))),[/lua]

But im not sure where to place that into the code above?

You need your own custom chatbox if you want it as: “Tag” “Name”: “Chat” I think.

Be more specific about how it’s not working - do you get any errors? How exactly does your code behave and how is that different from what you want it to do?

The second argument to your chat.AddText has a string literal in it, concatenated with a player’s nickname, so you need two dots between those and quotes around the string literal.

ply:IsSuperAdmin needs you to specify what arguments you’re passing to the function, in this case none. So you need an empty pair of brackets after it.

You also need another end, because you’ve begun a function and an if, both of which need to be closed.

If this is the entire code in the file, creating a function does not magically tell it when it should be called.

If this isn’t the entire code then I could do with seeing more.

Ok so what I understand from this is that the code should look like this?

[lua]
local function AddChatColorText(ply, text)
if ply:IsSuperAdmin() then
chat.AddText(Color(50, 200, 255),
[Leader] ply:Nick(),
Color(255,255,255),
": " … text)
end
end
[/lua]

I have this in my Dedicated Server and it doesnt seem to give a error it just wont work?
I think self that the line [lua][Leader] ply:Nick(),[/lua] is not correct because of the [Leader] part, it doesnt fit there.
But I dont know another option to use.

Edit:

I think its better to make it with groups not specific superadmins or admins etc.

so basicly the code would look like is this:

[lua]
local function AddChatColorText(ply, text)
if ply:IsUserGroup(“superadmin”) then
chat.AddText(Color(50, 200, 255),
[Leader] ply:Nick(),
Color(255,255,255),
": " … text)
end
end
[/lua]

The output of the code should look like when your talking into public chat it looks like this: “(Leader) Weapon317 : Example” But then of course the (Leader) part is in red letters and the name too (Weapon317) then the : and the text what comes after it, thats just white and then for specific groups eg. superadmins, admins, vip’s etc.

It’s
[lua]
"[Leader] "…ply:Nick()
[/lua]

Ah alright,

So then it would be:

[lua]
local function AddChatColorText(ply, text)
if ply:IsUserGroup(“superadmin”) then
chat.AddText(Color(50, 200, 255),
"[Leader] "…ply:Nick(),
Color(255,255,255),
": " … text)
end
end
[/lua]

By the way my groups are made with ULX but that shoulnt matter right?
And where do i have to place this file? lua/autorun/server or lua/autorun or straight in the gamefiles itself?
Just to be sure for myself :smiley:

lua/autorun/client but that code on it’s own will just create a function, it won’t modify what you see in chat in any way

Wait, so that means that when superadmins talk, you dont see “[Leader] [name]: [text]” ?

Precisely

But wait, how do we fix this? Otherwise the code is useless?

**[Gamemode.ChatText

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.ChatText)**

So it would be

[lua]
function chatTextHook(ply, text)
if ply:IsUserGroup(“superadmin”) then
chat.AddText(Color(50, 200, 255),
"[Leader] "…ply:Nick(),
Color(255,255,255),
": " … text)
end
end
hook.Add( “ChatText”, “ChatTextHook”, chatTextHook );
[/lua]

I think?

How about you read the page? It even has an example on there.

I did but i dont get it how to merge those codes together

[lua]
hook.Add(“PlayerSay”,“AddTag”,function(ply,txt,team)
local tag = “[SA]”
if ply:IsUserGroup(“superadmin”) then
return tag…" "…txt
end
end)
[/lua]

Try that.

This works but now it comes out as [name]: SA
It haves to be then [SA][name]: [txt] and the [SA][name] haves to be red for eg. like i had in the other function what dint work

[lua]
hook.Add(“OnPlayerChat”,“SuperAdminTag”,function(ply, txt, team, dead)
local chat = {}

if ply:IsUserGroup("superadmin") then
	table.insert(chat, Color(225,75,75))
	table.insert(chat,"[SA] ")
end

table.insert(chat,Color(225,200,200)
table.insert(chat,ply:Nick()..": "..txt)

chat.AddText(unpack(chat))

end)
[/lua]

This dont work, my server says (i have put it into lua/autorun/server in lua/autorun or lua/autorun/client dint worked) the error is : lua/autorun/server/superadminchat.lua:10 “)” expected (to close “(” at line 9 near “table”

")" expected (to close “(” at line 9 near "table"

There needs to be a ) to close the ( on line 9
Errors tell you what’s wrong, where it’s wrong and how it’s wrong, and (mostly) they do it in plain english.
[lua]
table.insert(chat,Color(225,200,200) <-- missing ) dawg
[/lua]

The code still wont work,
[lua]
hook.Add(“OnPlayerChat”,“SuperAdminTag”,function(ply, txt, team, dead)
local chat = {}

if ply:IsUserGroup("superadmin") then
    table.insert(chat, Color(225,75,75))
    table.insert(chat,"[SA] ")
end
 
table.insert(chat,Color(225,200,200))
table.insert(chat,ply:Nick()..": "..txt)
 
chat.AddText(unpack(chat))

end)
[/lua]
Is final code, it doesnt give a error now, it just wont work?