Ehh.. hai..
I wanted to ask, if its possible to filter out a word from a sentence, like 'Player: blah blah blah WORD blah blah' and if the sentence contains words, do something? Its not possible with string.sub if i read the wiki right..
string.find might help you. Create a table of banned words and then when you check the player's message you should iterate through the table (in pairs loop) and check to see if the string has any of your table values
[code]
local bannedWords = {
"fuck",
"suck",
"dick",
"moron", -- DO NOT FORGET THE COMMAS!!! COMMA AFTER LAST ELEMENT IS OK IN LUA.
}
hook.Add( "PlayerSay", "blocked_words", function( ply, text, public )
text = string.lower( text ) -- Make the chat message entirely lowercase
local t = txt
for id, str in pairs( bannedWords ) do -- Loop through all the banned words
if ( string.find( text, str ) ) then -- If the text contains the banned word, do this:
-- Ban the bad person, uncomment to make it work
-- ply:Ban( 1440 ) ply:Kick( "Don't use bad words fag" )
local s, e = string.find( text, str )
t = string.gsub( t, string.sub(t, s,e), string.rep("*", e-s) )
-- remember, you can't put code after return in the same scope!
return "" -- Hide the entire message, comment this out if you want to just hide the bad words.
end
end
return t -- Hide the bad words
end )[/code]
I did not test it.
I have a system that lets you ban "names" but it isn't integrated into anything. Meaning added the PlayerSay hook and bassing the data through may work. it'd need to be changed a slight bit or you'd need to explode the text and pass each word in to test but it lets you specify a percentage of a word that exists so if "bad" is the word, "badminton" would be ~33% or 0.33333 of the word, so you could specify x percent before saying it is or is not...
Two save formats:
JSON [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/blacklist_names/sv_blacklist_names.lua.html[/url]
or
Newline formatted
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/blacklist_names/sv_blacklist_names_newline_file_format.lua.html[/url]
A simple solution would be what Robot posted... String find to see if the word exists and it doesn't have a flaw which mine does... If a really bad word is blocked, then adding chars to it would decrease the percentage which I never fixed in these versions. I may fix it in the future so if a word can only be bad then any percentage over 0 would return true...
Either way, hopefully one of the solutions or a part of one works for you.
[QUOTE=Robotboy655;46810178][code]
local bannedWords = {
"fuck",
"suck",
"dick",
"moron", -- DO NOT FORGET THE COMMAS!!! COMMA AFTER LAST ELEMENT IS OK IN LUA.
}
hook.Add( "PlayerSay", "blocked_words", function( ply, text, public )
text = string.lower( text ) -- Make the chat message entirely lowercase
local t = txt
for id, str in pairs( bannedWords ) do -- Loop through all the banned words
if ( string.find( text, str ) ) then -- If the text contains the banned word, do this:
-- Ban the bad person, uncomment to make it work
-- ply:Ban( 1440 ) ply:Kick( "Don't use bad words fag" )
local s, e = string.find( text, str )
t = string.gsub( t, string.sub(t, s,e), string.rep("*", e-s) )
-- remember, you can't put code after return in the same scope!
return "" -- Hide the entire message, comment this out if you want to just hide the bad words.
end
end
return t -- Hide the bad words
end )[/code]
I did not test it.[/QUOTE]
this one looks good for me, but why not use kickban, and would it work if the text is like 'Player: Blah blah blah+word' like if the word is connected to a 'not-banned' word?
[QUOTE=tomhillepille;46810320]this one looks good for me, but why not use kickban, and would it work if the text is like 'Player: Blah blah blah+word' like if the word is connected to a 'not-banned' word?[/QUOTE]
If I remember correctly yes it will. Check out:
[url]http://lua-users.org/wiki/StringLibraryTutorial[/url]
[QUOTE=tomhillepille;46810320]this one looks good for me, but why not use kickban, and would it work if the text is like 'Player: Blah blah blah+word' like if the word is connected to a 'not-banned' word?[/QUOTE]
it will work, it will not work like this though: "d i c k".
Yeah, its mainly used to prevent urls, that are known as exploits or such.
[editline]28th December 2014[/editline]
Like from kawaii, the po.st urls
[URL="http://facepunch.com/fp_events.php?type=bani"]Just make sure saying snigger won't trigger the "nigger" ban word.[/URL]
pft, they can appeal on my website. :D
Off-Topic: Is it possible to let the scoreboard show like a 'Fake-Player' Like for TTT that it shows in the spectator team "Server watcher bot" or such?
[editline]28th December 2014[/editline]
[code][ERROR] addons/banwords/lua/autorun/sh_banwords.lua:18: bad argument #1 to 'sub' (string expected, got nil)[/code]
Line 18:[code]t = string.gsub( t, string.sub(t, s, e), string.rep("*", e-s) )[/code]
[editline]28th December 2014[/editline]
OK I got the error fixed, but how Do I get ULX to ban that guy? i want it to be ULX because more input can be made. code: [code]ULib.kickban(ply:Nick(), nil, "Banned: Reason", "Reason" )[/code]
error: [code][ERROR] addons/ulib/lua/ulib/server/player.lua:154: bad key to string index (number expected, got string)
1. error - [C]:-1
2. __index - lua/includes/extensions/string.lua:274
3. kickban - addons/ulib/lua/ulib/server/player.lua:154
4. fn - addons/banwords/lua/autorun/sh_banwords.lua:13
5. unknown - addons/ulib/lua/ulib/shared/hook.lua:184[/code]
[editline]28th December 2014[/editline]
Oh and, it makes EVERY text lowercase, even if the banned word doesn't exist in there, is there a way to prevent that?
[editline]28th December 2014[/editline]
Okay got the lowercase text fixed. but the error about ban?
[editline]28th December 2014[/editline]
And it lets users bypass ulx mute :c
In the
[QUOTE]ULib.kickban(ply:Nick(), nil, "Banned: Reason", "Reason" )
[/QUOTE]
Remove the ':Nick()', It uses the ply entity it self, not his nickname.
[QUOTE=tzahush;46810776]In the
Remove the ':Nick()', It uses the ply entity it self, not his nickname.[/QUOTE]
now its [code][ERROR] addons/ulib/lua/ulib/server/player.lua:154: attempt to call method 'SteamID' (a nil value)[/code]
And what about the ULX mute bypass?
[QUOTE=tomhillepille;46810843]now its [code][ERROR] addons/ulib/lua/ulib/server/player.lua:154: attempt to call method 'SteamID' (a nil value)[/code]
And what about the ULX mute bypass?[/QUOTE]
Who are you trying to ban?
the player from the chat that says it, its in the 'Put the code what to do if uses banned words' section.
[QUOTE=tomhillepille;46810862]the player from the chat that says it, its in the 'Put the code what to do if uses banned words' section.[/QUOTE]
Show me the ban function
here's the whole code:
[code]
local bannedWords = {
"po.st",
}
hook.Add( "PlayerSay", "blocked_words", function( ply, text, public )
text2 = string.lower( text ) -- Make the chat message entirely lowercase
local t = text2
for id, str in pairs( bannedWords ) do -- Loop through all the banned words
if ( string.find( text, str ) ) then -- If the text contains the banned word, do this:
-- Ban the bad person, uncomment to make it work
-- ply:Ban( 1440 ) ply:Kick( "Don't use bad words fag" )
ULib:kickban(ply, nil, "Banned: Reason", "Admin" )
local s, e = string.find( text, str )
t = string.gsub( t, string.sub(t, s, e), string.rep("*", e-s) )
-- remember, you can't put code after return in the same scope!
return "*** HIDDEN ***" -- Hide the entire message, comment this out if you want to just hide the bad words.
end
end
return text2 -- Hide the bad words
end )
[/code]
[editline]28th December 2014[/editline]
Ehh, ignore the 'text' from the return. I fixed that before already, I just tried something.
I wouldn't recommend using n asterisks to block the word. Instead use a constant number of asterisks to avoid guessing.
You ******* suck! is easily guessed. You ********************* suck! is a little harder.
Acecool it blocks the whole sentence.
[editline]28th December 2014[/editline]
I forgot to remove the string.sub function part, since it aint used anywhere in the code.
Just have some nice words and use some gsub magic.
[lua]print( ( "you suck so much!" ):gsub( "suck", "rock" ) )
Output: you rock so much![/lua]
I dont want exploiters on the server ;) Plus it still wouldn't fix the ulx mute bypass.
Remove return text2
the return text2 returns the normal text if it didn't got the word, and it allows Caps.
Since you are hiding the entire message, this is the only thing you need:
[code]local bannedWords = {
"po.st",
}
hook.Add( "PlayerSay", "blocked_words", function( ply, text, public )
local t = string.lower( text )
for id, str in pairs( bannedWords ) do
if ( string.find( t, str ) ) then
ULib:kickban(ply, nil, "Banned: Reason", "Admin" )
return "*** HIDDEN ***"
end
end
end )[/code]
[QUOTE=tomhillepille;46810921]Acecool it blocks the whole sentence.
[editline]28th December 2014[/editline]
I forgot to remove the string.sub function part, since it aint used anywhere in the code.[/QUOTE]
You're right, I forgot to consider the return ****HIDDEN****; ( make sure that isn't the exact code otherwise it'll error; use quotes ).
Cant try robots last post yet, our Server got Null routed because of DDoS attacks.
[QUOTE=tomhillepille;46811608]Cant try robots last post yet, our Server got Null routed because of DDoS attacks.[/QUOTE]
You can try it in single player or on a local listen server, what is wrong with you, why do you put untested code right onto a live server?
Who said its a public server? Its a Global private server for every staff to help us 'Beta test' (I Know this can be made with a Local server, but my UL connection is 0.28mb/s.. ugh)
Given enough time, every player will eventually be banned by this, especially if they don't know which words are bannable.
Think of the players as monkeys on a typewriter to see why :v:
They can make a ban appeal on our website.
[QUOTE=tomhillepille;46812009]They can make a ban appeal on our website.[/QUOTE]
They can too if you ban them preventatively.
Sorry, you need to Log In to post a reply to this thread.