Hello, everyone!
I'm currently writing my own chat system, and I'm currently attempting to set up a chat filter. However, this only seems to work if there is one word involved ( that matches the accursed word. )
Any help would be much appreciated!
chatfilter = {} chatfilter[1] = "badword" s = "badword." for w in string.gmatch(s, "%a+") do if s == chatfilter[1] then print("This message contained inappropiate content.") else print(s) end end
You can use string.find(), if it returns nothing or nil then it can't find a bad word within a string.
Here's an example I've created.
local filteredWords = {"N00B","HATE"} local plrString = "YOU SUCH A N00B LOLOL I HATE YOU LOLOLOL" --Typical hate speech for i = 1, #filteredWords do if string.find(plrString, filteredWords[i]) ~= nil then print("Bad word located!") else print("Innocent words!") end end
You can also track how many words were located by just having an integer that increases every time there's a bad word found.