• Chat filter i made doesn't work, no Error messages
    6 replies, posted
this is my code, for some reason, it doesnt work File in autorun/server/chat_filter.lua [CODE]hook.Add("PlayerSay", "chat_filter", function( player, strText ) local tab = {} if ( IsValid( player ) ) then table.insert( tab, player ) else table.insert( tab, "Console" ) end local incomplete = string.Explode( strText, " ") local pre_table = util.KeyValuesToTable( file.Read( "meisno/reham.txt" ) ) local function apartk() for k,v in ipairs(pre_table) do return k end end local function apartv( K ) for k,v in ipairs(pre_table) do if k == K then return v end end end for k,v in ipairs(incomplete) do local value = tostring(v) if value == apartK() then value = apartv( k ) end end local complete = string.Implode( incomplete , " " ) table.insert( tab, Color( 255, 255, 255 ) ) table.insert( tab, ": "..complete ) chat.AddText( unpack(tab) ) return true end) [/CODE] Code in data/meisno/reham.txt [CODE]"CHAT_FILTER" { "fuck" "F***" "shit" "S***" "GMT" "Narb" }[/CODE]
Test it in a listen server first, it's got to be erroring somewhere or not functioning. Server errors aren't visible unless you host the server or you are the server. Next, I somehow remember that this conflicts with commands, but oh well. Anyhow, someone wrote a censor for me a while back. Also, use [lua] tags not [code] tags in the future.
That is not how you would use PlayerSay to alter the text. If you want to filter the word 'fuck' in chat text, you would do this: [lua]hook.Add( "PlayerSay", "Filter", function( ply, txt ) return string.replace( txt, "fuck", "****" ) end )[/lua] You were trying to needlessly call chat.AddText, which does not exist serverside.
Are you sure to use string.replace?
[QUOTE=H0rsey;21264069]Are you sure to use string.replace?[/QUOTE] Yes he is. He just forgot to capitalize it [lua] hook.Add( "PlayerSay", "Filter", function( ply, txt ) return string.Replace( txt, "fuck", "****" ) end ) [/lua]
Use [b][url=http://wiki.garrysmod.com/?title=String.gsub]String.gsub [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] instead, it is faster.
^ Yeah, that's what I meant.
Sorry, you need to Log In to post a reply to this thread.