Hey I was wondering if there was a way to automatically ban a player for 1020 minutes if they have a bad name such as ni***r, ni**a, and such.
I'm guessing you would have to use this somewhere in there but that's all I really know. Help would be appreciated.
[code]
LocalPlayer():GetName() )
[/code]
You could use a game-event "player_connect" or CheckPassword hook: [url]http://wiki.garrysmod.com/page/GM/CheckPassword[/url]
Do a string.Find to see if it contains a word.
Can you help me out some more? Still lost.
[editline]3rd September 2014[/editline]
OK, here's my progress so far:
[code]
hook.Add( "CheckPassword", "CheckPasswordBan", function( ??? )
if ( string.needle( name ) == "ni**a", "ni**a" ) then
return ???
end
end )
[/code]
I know it's bad but I barely know lua and I'm trying my best. If you could help me out, that would be great.
You're on the right track.
However, it's string.Find() with the desired needle being in the argument. Here's how lua functions work:
You call a function with given arguments. The arguments are like variables for inside that function. Your hook will give the value of the arguments to the arguments.
For example, if I have this:
[lua]
hook.Add("PlayerDeath", "whatever", function(player, weapon, attacker)
print(player:Nick().." was killed by "..attacker)
end)
[/lua]
When someone dies it will print to console "Someone was killed by someone else."
You need to be using the "CheckPassword" hook, which has the fifth argument as the player's name.
You'll need to use that hook to call a function which checks that against blacklisted ones using string.Find(), but make sure you're using the correct arguments to string.Find(). string.Needle() is incorrect.
[editline]2nd September 2014[/editline]
Your hook.Add part correct, but the ??? is the function arguments you need to name and use.
What else would I put with name?
[code]
hook.Add( "CheckPassword", "BadName", function( name, )
[/code]
[editline]3rd September 2014[/editline]
[code]
hook.Add( "CheckPassword", "BadName", function( player, name )
if ( string.Find( name ) == "ni**a", "ni**a" ) then
game.ConsoleCommand("ulx ban" player:Nick() "1024 Bad Name")
end
end)
[/code]
What I have so far. Anything else I need to add in the function? Or is anything wrong?
[QUOTE=Snowpaw;45877617]What else would I put with name?
[code]
hook.Add( "CheckPassword", "BadName", function( name, )
[/code]
[editline]3rd September 2014[/editline]
[code]
hook.Add( "CheckPassword", "BadName", function( player, name )
if ( string.Find( name ) == "ni**a", "ni**a" ) then
game.ConsoleCommand("ulx ban" player:Nick() "1024 Bad Name")
end
end)
[/code]
What I have so far. Anything else I need to add in the function? Or is anything wrong?[/QUOTE]
You don't have the correct arguments, have a look at the link Acecool gave you.
[lua]function( player, name )[/lua] should be [lua]function( steamid, ip, svpass, clpass, name )[/lua]
Alright, thanks. Is there anything else wrong?
[code]
hook.Add( "CheckPassword", "BadName", function( steamid, ip, svpass, clpass, name )
if ( string.Find( name ) == "ni**a", "ni**a" ) then
game.ConsoleCommand("ulx ban" player:Nick() "1024 Bad Name")
end
end)
[/code]
Not exactly. Name is the last argument of CheckPassword; there are five others first: [url]http://wiki.garrysmod.com/page/GM/CheckPassword[/url]
[editline]2nd September 2014[/editline]
Ninja'd
your string.Find() is missing some arguments, it's checking if the name is literally "ni**a" (if you want to do multiple names it might be good to have a table of bad names and use table.HasValue(whatevertable, name), player:Nick() won't be anything because player is undefined, the consolecommand with ulx banning also won't work because you aren't joining the strings with .. , it would probably be better to use ulx banid with the steamid argument.
[QUOTE=Snowpaw;45877676]Alright, thanks. Is there anything else wrong?
[code]
hook.Add( "CheckPassword", "BadName", function( steamid, ip, svpass, clpass, name )
if ( string.Find( name ) == "ni**a", "ni**a" ) then
game.ConsoleCommand("ulx ban" player:Nick() "1024 Bad Name")
end
end)
[/code][/QUOTE]
Yes, string.Find should be [URL="http://wiki.garrysmod.com/page/string/find"]string.find[/URL] (lowercase f)
And you aren't using it correctly. First you need to put the string you are searching (their name) AND the string you are looking for both inside the brackets. And you need to do a separate check for each word.
[lua]if string.find(name,"nigger") or string.find(name,"nigga") then[/lua]
[QUOTE=zerf;45877692]the consolecommand with ulx banning also won't work because you aren't joining the strings with ..[/QUOTE]
And that too. But really you shouldn't do it like that because they could inject console commands via their name. Safer to do:
[lua]RunConsoleCommand("ulx","ban", name, "1024", "Bad Name")[/lua]
[code]hook.Add( "CheckPassword", "BadName", function( steamid, ip, svpass, clpass, name )
if ( string.Find( name ) == "ni**a", "ni**a" ) then
game.ConsoleCommand("ulx ban " .. steamid .. " 1024 Bad Name/n")
end
return false
end)[/code]
[QUOTE=code_gs;45877709][code]hook.Add( "CheckPassword", "BadName", function( steamid, ip, svpass, clpass, name )
if ( string.Find( name ) == "ni**a", "ni**a" ) then
game.ConsoleCommand("ulx ban " .. steamid .. " 1024 Bad Name/n")
end
return false
end)[/code][/QUOTE]
That should be "ulx banid" if you're banning via steamid.
OK, I've tried both codes and neither are working. I'm not sure if I put it in the right place or what.
I have it in:
lua/autorun/autobanbadname.lua
[QUOTE=Snowpaw;45893806]OK, I've tried both codes and neither are working. I'm not sure if I put it in the right place or what.
I have it in:
lua/autorun/autobanbadname.lua[/QUOTE]
CheckPassword is a serverside hook.
So, would I have to put it in lua/autorun/server and add:
if ( SERVER ) then
to it, or just put it in lua/autorun/server?
Just put it in server.
Think about it in a step by step manner.
Step 1. You want to kick/ban people who have a specific word(combination of letters) in their name.
Step 2. You want to be able to add words to that list easily. This obviously means you'd want to use Lua's version of an array, called tables. [url]http://lua-users.org/wiki/TablesTutorial[/url]
Step 3. You want to check their name against word in that table. This will require a 'for' loop. [url]http://www.lua.org/pil/4.3.4.html[/url]
Step 4. You want to see if a specific sub string exists within the string that is the players name. [url]http://wiki.garrysmod.com/page/string/find[/url]
Put it at together and here's your end result:
[CODE]
local bad_words =
{
"nigger",
"nigga",
"fuck",
"fag",
"etc.",
}
hook.Add( "CheckPassword", "bad_names", function( steamid, _, _, _, name )
for _, word in ipairs( bad_words ) do
if name:find( word ) then
game.ConsoleCommand("ulx ban " .. steamid .. " 1024 Bad Name/n")
return false
end
end
end )
[/CODE]
[QUOTE=CallMePyro;45904695][CODE]
if name:Find( word ) then
[/CODE][/QUOTE]
Wat
[QUOTE=PaellaPablo;45904713]Wat[/QUOTE]
Oops! Should be lower case. I've fixed that in my OP.
Keep in mind that strings are object in lua also, and have their own metatable. This metatables __index function points to the 'string' table. This means that you can use string methods in this way, as well as the standard
[CODE]
string.find( name, word )
[/CODE]
Sorry, you need to Log In to post a reply to this thread.