General > Developers Corner
Admin sounds, tools and other code chat.
jay209015:
Thank You!
JamminR:
Perhaps you could write a client side censor instead using Client hook "chattext" and have your server send it to clients.
http://garrysmod.com/wiki/?title=Gamemode.ChatText
No idea if this would break other things or not.
jay209015:
I tried, but I couldn't figure out how to make it work without using playersay. Maybe I could modify ulx to get it's player text from WordC rather than text
JamminR:
I was just looking at Megiddo's code example above. I believe his won't break ulx commands unless they include some of those censored words (such as in the name of the player or the reason provided for ban/kick).
You're always returning WordC/text, modified or not.
Gmod chat hooks will always stop other hooks from functioning if anything but nil is returned. (as we've discussed)
However, Megiddo uses a 'return' if nothing was found/edited, or the modified text if something was.
You can use his, or make slight modification to yours code that would look like the following
--- Code: ---WordD = { "word1" , "word2" }
function WFilter( ply, text, toall )
local WordC = nil
for _, v in ipairs( WordD ) do
if string.find( text, v, 1, true) then
WordC = string.Replace(text,v,"****")
end
end
if WordC then return WordC else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---
In that code, WordC always gets set to nil everytime something is said.
If a censored word is found, it gets set in WordC. If not, WordC remains nil.
After it loops, if WordC has text, it is returned censored. If not, the hook is returned nothing, which should allow other scripts, such as ULX, to see the chat.
jay209015:
Tested and got this
word1
****
word2
****
word1 and word2
word1 and ****
word2 and word1
**** and word1
and it didn't break ulx
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version