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](name): [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.
[QUOTE=MegaJohnny;28610580]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.[/QUOTE]
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]
[QUOTE=ralle105;28614722]It's
[lua]
"[Leader] "..ply:Nick()
[/lua][/QUOTE]
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 :D
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
[QUOTE=ralle105;28615364]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[/QUOTE]
Wait, so that means that when superadmins talk, you dont see "[Leader] [name]: [text]" ?
Precisely
[QUOTE=ralle105;28615429]Precisely[/QUOTE]
But wait, how do we fix this? Otherwise the code is useless?
[QUOTE=ralle105;28615509][b][url=wiki.garrysmod.com/?title=Gamemode.ChatText]Gamemode.ChatText [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b][/QUOTE]
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.
[QUOTE=ralle105;28615984]How about you read the page? It even has an example on there.[/QUOTE]
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.
[QUOTE=zzaacckk;28616204][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.[/QUOTE]
This works but now it comes out as [name]: [SA](text)
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]
[QUOTE=zzaacckk;28617234][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][/QUOTE]
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"
[b]")" expected (to close "(" at line 9 near "table"[/b]
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]
[QUOTE=ralle105;28619718][b]")" expected (to close "(" at line 9 near "table"[/b]
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][/QUOTE]
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?
Is it in lua/autorun/client?
Also, you probably want to return true so that you don't get double chat lines.
Oh, and because you're doing
[lua]local chat = {}[/lua]
It will mess up the chat library, rename that variable or you'll get an error.
[QUOTE=LinkTwilight;28620464]Also, you probably want to return true so that you don't get double chat lines.
Oh, and because you're doing
[lua]local chat = {}[/lua]
It will mess up the chat library, rename that variable or you'll get an error.[/QUOTE]
Well i dint made the code so i have no idea how to rename it, and yes its in autorun/client i even tried it into just autorun and autorun/server
[lua]
hook.Add("OnPlayerChat","SuperAdminTag",function(ply, txt, team, dead)
local chat2 = {}
if ply:IsUserGroup("superadmin") then
table.insert(chat2, Color(75,225,75))
table.insert(chat2,"[SA] ")
end
table.insert(chat2,Color(200,225,200))
table.insert(chat2,ply:Nick()..": ")
table.insert(chat2,Color(225,225,225))
table.insert(chat2,txt)
chat.AddText(unpack(chat2))
return true
end)
[/lua]
lua/autorun/client <- Put it there & give unique name
[QUOTE=zzaacckk;28621364][lua]
hook.Add("OnPlayerChat","SuperAdminTag",function(ply, txt, team, dead)
local chat2 = {}
if ply:IsUserGroup("superadmin") then
table.insert(chat2, Color(75,225,75))
table.insert(chat2,"[SA] ")
end
table.insert(chat2,Color(200,225,200))
table.insert(chat2,ply:Nick()..": ")
table.insert(chat2,Color(225,225,225))
table.insert(chat2,txt)
chat.AddText(unpack(chat2))
return true
end)
[/lua]
lua/autorun/client <- Put it there & give unique name[/QUOTE]
Nope this doesnt work either, tried in all lua/autorun/client, server, autorun. Dont work, doesnt give a LUA error like it did before.
Add a print statement just above chat.AddText like this.
[lua]
print("Chat function is being called, something else is wrong.") -- new line
chat.AddText(unpack(chat2)) -- existing line
[/lua]
This will let you see if the hook is being called, you could also add more prints to check what values you are getting like print(txt) or print(team) or print(dead). If that print shows up in the console then try something like just changing the color of all the text, and if that works add the other stuff. Hope this helps.
[editline]15th March 2011[/editline]
Oh yea, and stop moving the file, it must go in lua/autorun/client
[QUOTE=Fantym420;28623122]Add a print statement just above chat.AddText like this.
[lua]
print("Chat function is being called, something else is wrong.") -- new line
chat.AddText(unpack(chat2)) -- existing line
[/lua]
This will let you see if the hook is being called, you could also add more prints to check what values you are getting like print(txt) or print(team) or print(dead). If that print shows up in the console then try something like just changing the color of all the text, and if that works add the other stuff. Hope this helps.
[editline]15th March 2011[/editline]
Oh yea, and stop moving the file, it must go in lua/autorun/client[/QUOTE]
Wait im kinda confused right know because this was from the previous code right? And yeah the chat.Addtext code I founded in one of the TTT gamefiles, into cl_voice so maybe i need to put it there? Dont know sure tho?
wow, lol here ya go, put it at the bottom of the TTT gamemode/cl_init.lua
[lua]
hook.Add("OnPlayerChat","SuperAdminTag",function(ply, txt, team, dead)
local chat2 = {}
if ply:IsUserGroup("superadmin") then
table.insert(chat2, Color(75,225,75))
table.insert(chat2,"[SA] ")
end
table.insert(chat2,Color(200,225,200))
table.insert(chat2,ply:Nick()..": ")
table.insert(chat2,Color(225,225,225))
table.insert(chat2,txt)
print("Chat function is being called, something else is wrong.")
chat.AddText(unpack(chat2))
return true
end)
[/lua]
then run the game and open up the chat and type something and press enter.
next press the key to bring up the console (usually ~) and see if the text "Chat function is being called, something else is wrong." is printed there if it is then the hook is being called and there's something wrong with the chat.AddText
[QUOTE=Fantym420;28625041]wow, lol here ya go, put it at the bottom of the TTT gamemode/cl_init.lua
[lua]
hook.Add("OnPlayerChat","SuperAdminTag",function(ply, txt, team, dead)
local chat2 = {}
if ply:IsUserGroup("superadmin") then
table.insert(chat2, Color(75,225,75))
table.insert(chat2,"[SA] ")
end
table.insert(chat2,Color(200,225,200))
table.insert(chat2,ply:Nick()..": ")
table.insert(chat2,Color(225,225,225))
table.insert(chat2,txt)
print("Chat function is being called, something else is wrong.")
chat.AddText(unpack(chat2))
return true
end)
[/lua]
then run the game and open up the chat and type something and press enter.
next press the key to bring up the console (usually ~) and see if the text "Chat function is being called, something else is wrong." is printed there if it is then the hook is being called and there's something wrong with the chat.AddText[/QUOTE]
Yeah this works, only the [SA] is green and the [name] is white, is there a way to make them both red?
Also, to add more groups, eg. VIP, Admin etc. how would that look like? Same code other color codes and different UserGroup?
for the color edit the color values they go red, green, blue change the amounts to get different colors, 0 is black and 255 full color. As far as adding more you could just copy the if statement and change the group and the text it's adding.
Sorry, you need to Log In to post a reply to this thread.