General > Developers Corner
Admin sounds, tools and other code chat.
jay209015:
This only filters out the word "", BTW the forums sensored the other two words
--- Code: ---WordD = { "<censor>" }
local WordC = ""
function WFilter( ply, text, toall )
for _, v in ipairs( WordD ) do
if string.find( text, v) then
WordC = string.Replace(text,v,"****")
else
WordC = (text)
end
end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );
--- End code ---
Megiddo:
--- Quote from: jay209015 on April 12, 2008, 01:16:40 PM ---Ok, so is this what you're saying?
--- Code: ---WordD = { "<censor>", "ass", "<censor>" }
local WordC = ""
function WFilter( ply, text, toall )
for _, v in pairs( WordD ) do
if string.find( text, v) then
WordC = string.Replace(text,v,"****")
else
WordC = (text)
end
end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );
--- End code ---
BTW, thanks for the move, and all the help you've given me so far.
--- End quote ---
Untested, but try this
--- Code: ---WordD = { "word" }
function WFilter( ply, text, toall )
local found = false
for _, v in pairs( WordD ) do
if string.find( text, v) then
text:gsub(v,"****")
found = true
end
end
if found then return text end
end
hook.Add( "PlayerSay", "WFilter", WFilter );
--- End code ---
jay209015:
--- Quote ---Untested, but try this
Code:
WordD = { "word" }
function WFilter( ply, text, toall )
local found = false
for _, v in pairs( WordD ) do
if string.find( text, v) then
text:gsub(v,"****")
found = true
end
end
if found then return text end
end
hook.Add( "PlayerSay", "WFilter", WFilter );
--- End quote ---
Tested, doesn't work
--- Code: ---WordD = { "<censor>" }
local WordC = ""
function WFilter( ply, text, toall )
for _, v in ipairs( WordD ) do
if string.find( text, v) then
WordC = string.Replace(text,v,"****")
else
WordC = (text)
end
end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );
--- End code ---
this one sensors out the last word in the WordD string , but breaks the ulx chat commands.
JamminR:
--- Quote from: jay209015 on April 12, 2008, 02:42:25 PM ---But, do you know why this script isn't working at all?
--- End quote ---
Two possibilities.
1) Tried removing the ( ) from your WordC= (text) ? Not sure why you have it. Pretty sure it's not needed.
2) http://www.lua.org/manual/5.1/manual.html#pdf-string.find - String find does pattern matching by default. Patterns are nice (but can be complex) ways of defining exactly what to look for without having to type more than necessary or make it easier to search for things that are hard to type (spaces for instance, special ascii characters, etc.)
Try changing your string.find to
string.find( text, v, 1, true)
jay209015:
--- Quote from: JamminR on April 12, 2008, 06:09:08 PM ---Two possibilities.
1) Tried removing the ( ) from your WordC= (text) ? Not sure why you have it. Pretty sure it's not needed.
2) http://www.lua.org/manual/5.1/manual.html#pdf-string.find - String find does pattern matching by default. Patterns are nice (but can be complex) ways of defining exactly what to look for without having to type more than necessary or make it easier to search for things that are hard to type (spaces for instance, special ascii characters, etc.)
Try changing your string.find to
string.find( text, v, 1, true)
--- End quote ---
Tested, but still this code only censors word2. Any idea as to why?
--- Code: ---WordD = { "word1" , "word2" }
local WordC = ""
function WFilter( ply, text, toall )
for _, v in ipairs( WordD ) do
if string.find( text, v, 1, true) then
WordC = string.Replace(text,v,"****")
else
WordC = (text)
end
end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version