• Lua error relating to console usergroup
    2 replies, posted
Basically, I'm having the below error when using the "say " command via my server's webconsole. This error appears, and all users are disconnected due to scripting errors. [ERROR] addons/ulx/lua/autorun/client/cs_ct.lua:14: attempt to call method 'IsUserGroup' (a nil value) 1. fn - addons/ulx/lua/autorun/client/cs_ct.lua:14 2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 [HR][/HR] Code as below. Modified from the original to correct an error causing all chat to be red. [HR][/HR] --Chat Tags by Tyguy local Tags = { --Group --Tag --Color {"admin", "[ADMIN] ", Color(146, 0, 255, 255) }, {"superadmin", "[SUPERADMIN] ", Color(0, 187, 255, 255) }, {"regular", "[REGULAR] ", Color(209, 101, 0, 255) } } hook.Add("OnPlayerChat", "Tags", function(ply, strText) for k,v in pairs(Tags) do if ply:IsUserGroup(v[1]) then local R = GetConVarNumber("chat_tags_color_r") local G = GetConVarNumber("chat_tags_color_g") local B = GetConVarNumber("chat_tags_color_b") local A = GetConVarNumber("chat_tags_color_a") local nickteam = team.GetColor(ply:Team()) chat.AddText(v[3], v[2], nickteam, ply:Nick(), color_white, ": ", strText) return true end end end )
Next time, put your code in: [code][/code] tags to make it look nicer :). [code] --Chat Tags by Tyguy local Tags = { --Group --Tag --Color {"admin", "[ADMIN] ", Color(146, 0, 255, 255) }, {"superadmin", "[SUPERADMIN] ", Color(0, 187, 255, 255) }, {"regular", "[REGULAR] ", Color(209, 101, 0, 255) } local prefcol = Color(255,255,255,255) --Same as the: Color above. local conpref = "[CONSOLE] " --Same as the: Tag above local contextcol = Color(0,0,0,255) ---Text color the console name will be hook.Add("OnPlayerChat", "Tags", function(ply, strText) if not ply:IsPlayer() then chat.AddText(prefcol, conpref, contextcol, "Console", color_white, ":", strText) return true end for k,v in pairs(Tags) do if ply:IsUserGroup(v[1]) then local nickteam = team.GetColor(ply:Team()) chat.AddText(v[3], v[2], nickteam, ply:Nick(), color_white, ": ", strText) return true end end end ) [/code] Untested, not sure if this will work or not, lol. The problem you where having, was that the console isn't a player, therefor you can't use [code]ply:IsUserGroup()[/code] on it. Also, if all your users are being disconnected on an error, put: sv_kickerrornum 0 in your server's config file to prevent being kicked on errors.
[QUOTE=crazyscouter;41767732]Next time, put your code in: [code][/code] tags to make it look nicer :). [code] --Chat Tags by Tyguy local Tags = { --Group --Tag --Color {"admin", "[ADMIN] ", Color(146, 0, 255, 255) }, {"superadmin", "[SUPERADMIN] ", Color(0, 187, 255, 255) }, {"regular", "[REGULAR] ", Color(209, 101, 0, 255) } local prefcol = Color(255,255,255,255) --Same as the: Color above. local conpref = "[CONSOLE] " --Same as the: Tag above local contextcol = Color(0,0,0,255) ---Text color the console name will be hook.Add("OnPlayerChat", "Tags", function(ply, strText) if not ply:IsPlayer() then chat.AddText(prefcol, conpref, contextcol, "Console", color_white, ":", strText) return true end for k,v in pairs(Tags) do if ply:IsUserGroup(v[1]) then local nickteam = team.GetColor(ply:Team()) chat.AddText(v[3], v[2], nickteam, ply:Nick(), color_white, ": ", strText) return true end end end ) [/code] Untested, not sure if this will work or not, lol. The problem you where having, was that the console isn't a player, therefor you can't use [code]ply:IsUserGroup()[/code] on it. Also, if all your users are being disconnected on an error, put: sv_kickerrornum 0 in your server's config file to prevent being kicked on errors.[/QUOTE] Ah! I tried to tag it, but first time poster, and all. Thank you! The code's ALMOST perfect, barring a missing } in line 5. It solved the problem. You are a gentleman and a scholar.
Sorry, you need to Log In to post a reply to this thread.