General > Developers Corner
Admin sounds, tools and other code chat.
JamminR:
Upon closer look, I see why, but can you?
I feel as though I've moved away from teaching and been doing your work for you.
Hint: "text" never changes. "WordC" does. Therefore WordC censor text is always the last word in the table to get edited.
jay209015:
I see what you're talking about, but I don't see a way of fixing it. Unless this will work.
--- Code: ---WordD = { "word1" , "word2" }
function WFilter( ply, text, toall )
local WordC = text
for _, v in ipairs( WordD ) do
if string.find( text, v, 1, true) then
WordC = string.Replace(text,v,"****")
else
WordC = nil
end
end
if WordC then return WordC else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---
==EDIT==
Nope this one works even less. It only filters out word2 in all cases.
JamminR:
Closer.
But, WordC will get replaced with nil on words that aren't in the table.
Making it start all over again, ending up with the same results, last word of table censored.
I recommend actually modifying 'text' each loop.
Setting WordC to "found" or "true" if anything is found.
Returning "text" instead of "WordC" in the final if WordC check.
"if WordC then return text else return end"
jay209015:
Like this?
--- 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 = found
end
end
if WordC == found then
text = string.Replace(text, v, "****")
end
if WordC == found then return text else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---
==EDIT==
Tested and Failed :'(
jay209015:
Ok I changed it a little bit, but not tested yet.
--- 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 = found
end
if WordC == found then
text = string.Replace(text, v, "****")
end
end
if WordC then return text else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---
==EDIT==
Tested, Failed
also tried
--- 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 = found
if WordC == found then
text = string.Replace(text, v, "****")
end
end
end
if WordC then return text else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---
Same result.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version