• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TalkAction Advanced Anti-swearing

Lua:
local invalidWords = {
	'whore',
	'fuck',
	'dick',
}

function onSay(cid, words, param, channel)
	words = (words .. ' ' .. param)
	for k, v in ipairs(invalidWords) do
		words = words:gsub("%a*" .. v .. "%a*", function(v) return ('*'):rep(v:len()) end)
	end
	doCreatureSay(cid, words, TALKTYPE_SAY)
	return true
end

Should work better too :)


** Mod warning ** These are just examples, no need to infract me hehe :D
whore motherfucker just fuck yourself fucking dickhead lol go die haha
goes
***** ************ just **** yourself ******* ******** lol go die haha

Thank you. :thumbup:

I used your method by using string.rep, I also included param. Thx :)
 
Last edited:
@upup
Do it find for example 'fUcK'? Do you know lua function to search string not case sensitive? I made it other method in my script:
PHP:
...
    local wrongWords = {"otservlist.org", "ots-list.pl", ".com"}
        local lowerText = string.lower(text)
        for w = 1, #wrongWords do
                wordLen = string.len(wrongWords[w])
                for p = 1, string.len(text) do
                        if(string.sub(lowerText, p, p+wordLen-1) == wrongWords[w]) then
                                text = string.sub(text, 1, p-1) .. string.rep("*", wordLen) .. string.sub(text, p+wordLen)
                        end
                end
        end
but maybe there is any lua function.
 
@upup
Do it find for example 'fUcK'? Do you know lua function to search string not case sensitive? I made it other method in my script:
PHP:
...
    local wrongWords = {"otservlist.org", "ots-list.pl", ".com"}
        local lowerText = string.lower(text)
        for w = 1, #wrongWords do
                wordLen = string.len(wrongWords[w])
                for p = 1, string.len(text) do
                        if(string.sub(lowerText, p, p+wordLen-1) == wrongWords[w]) then
                                text = string.sub(text, 1, p-1) .. string.rep("*", wordLen) .. string.sub(text, p+wordLen)
                        end
                end
        end
but maybe there is any lua function.

Yes, I'm also aware of this problem. But you can't solve it by making "words" lower cases only. Maybe the player want to write: "Hi, my name is Mazen. fUck you.", it will turn into "hi, my name is mazen. **** you.". :( No one can use A-Z, they will turn into lower case characters, a-z.
 
Check my code :)
It make copy of text lowercase, search position of lowercase 'fUcK' in copy and change letters on same position(s) in orginal text and then return modified orginal text. It show:
"Hi, my name is Mazen. **** you."
 
This work incase-sensitive
Lua:
function nocase (s)
	--http://www.lua.org/pil/20.4.html
	return s:gsub("%a", function(c) return ("[%s%s]"):format(c:lower(), c:upper()) end)
end

local invalidWords = {
	'whore',
	'fuck',
	'dick',
	'pussy'
}

function onSay(cid, words, param, channel)
	words = (words .. ' ' .. param)
	for k, v in ipairs(invalidWords) do
	    words = words:gsub("%a*" .. nocase(v) .. "%a*", function(v) return ('*'):rep(v:len()) end)
	end
	doCreatureSay(cid, words, TALKTYPE_SAY)
	return true
end

only "shortened" that function, but didnt make it :p
 
This work incase-sensitive
Lua:
function nocase (s)
	--http://www.lua.org/pil/20.4.html
	return s:gsub("%a", function(c) return ("[%s%s]"):format(c:lower(), c:upper()) end)
end

local invalidWords = {
	'whore',
	'fuck',
	'dick',
	'pussy'
}

function onSay(cid, words, param, channel)
	words = (words .. ' ' .. param)
	for k, v in ipairs(invalidWords) do
	    words = words:gsub("%a*" .. nocase(v) .. "%a*", function(v) return ('*'):rep(v:len()) end)
	end
	doCreatureSay(cid, words, TALKTYPE_SAY)
	return true
end

only "shortened" that function, but didnt make it :p

Nice function, can be useful. :)

Check my code :)
It make copy of text lowercase, search position of lowercase 'fUcK' in copy and change letters on same position(s) in orginal text and then return modified orginal text. It show:
"Hi, my name is Mazen. **** you."

Oh I see ^^

Nice, but I guess I'll stick to nocase() :)

Thx to both of you, you made this possible. :D
 
Last edited:
heya maze, I get this:
[26/10/2009 17:34:39] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/addons/illegalwords.lua)
[26/10/2009 17:34:39] data/talkactions/scripts/addons/illegalwords.lua:26: ')' expected near 'InvalidWords'
[26/10/2009 17:34:39] Reloaded talk actions.

ya should fix that quickly :(
 
wait, I'll compile 0.3 again..
btw congratz, I consider this a wonderful feature, tfs0.4 should have it as an option:)
 
:( well compiled again and followed the tutorial from A to Z but I get this:
[26/10/2009 18:14:04] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/addons/illegalwords.lua)
[26/10/2009 18:14:04] data/talkactions/scripts/addons/illegalwords.lua:26: ')' expected near 'InvalidWords'
[26/10/2009 18:14:04] Reloaded talk actions.

error in line 26:
Lua:
TheWords = TheWords:gsub("(%a*".. nocase InvalidWords[i] .."%a*)", doFixString InvalidWords[i])

my(your)script:
Lua:
  local BlockedChannels = {
        {channel = CHANNEL_DEFAULT},
        {channel = CHANNEL_HELP, type = TALKTYPE_CHANNEL_Y},
        {channel = CHANNEL_GUILD, type = TALKTYPE_CHANNEL_Y}
}

local InvalidWords = {
        "whore",
        "slut",
        "fuck",
        "mother~fucker"
}

function onSay(cid, words, param, channel)
local TheWords = words .. param
        for i, select in ipairs(BlockedChannels) do
                if select.channel == channel then
                        talkType = select.type
                        break
                elseif select.channel ~= channel and i == #BlockedChannels then
                        return false
                end
        end

        for i = 1, #InvalidWords do
                TheWords = TheWords:gsub("(%a*".. nocase InvalidWords[i] .."%a*)", doFixString InvalidWords[i])
        end

        if channel == CHANNEL_DEFAULT then
                doCreatureSay(cid, TheWords, TALKTYPE_SAY)
        else
                doPlayerSendChannelMessage(cid, getCreatureName(cid), TheWords, talkType, channel)
        end
        return true
end

function doFixString(w)
        return ("*"):rep(w:len())
end

function nocase(s)
        -- From: [url=http://www.lua.org/pil/20.4.html]Programming in Lua : 20.4[/url]
        return s:gsub("%a", function(c) return ("[%s%s]"):format(c:lower(), c:upper()) end)
end

Lua:
<talkaction words="Allwords" event="script" value="addons/illegalwords.lua"/>
:( any idea? I'm doing everything fine
 
try replace line 26 with:
Code:
TheWords = TheWords:gsub("(%a*".. nocase(InvalidWords[i]) .."%a*)", doFixString(InvalidWords[i]))
 
:D gee thnx oops I can't rep u back again :p
btw you should fix the main post's
 
Topic very old, but I need this script. This script doesn't work with spells. When we calling a spell it's defined as "Allwords" and we don't see any action. Shorly all spells stop working when we turn on this script.
Anyone can fix it? Please :)
 
Unfortunately, I have a problem with this script. When I add this script and I'm trying to write someone a private message to my message does not reach the player.

Can anyone get this error corrected. I have the engine TFS 0.3.6
 
Back
Top