Jump to content

[HELP] Banned words auto-ban


Recommended Posts

local banWord = "shit" 
local string = "This is my SHIT string!" 
--Btw, use string.lower to get everything in the messages to lowercase  
if (string.find(string.lower(string), banWord) ~= nil) then 
outputChatBox("Ban this insulter! :O") 
end 

EDIT: Nice smiley space in my code ^^'

Link to comment

Is this right? :)

  
local banWords = "test come to...", "test come to 1..."; 
local strings = "test come to...", "test come to 1..."; 
  
function addBan(source) 
if (string.find(string.lower(strings), banWords) ~= nil) then 
banPlayer(source, getRootElement(), "You are banned due to ...") 
end 
addEventHandler( "onPlayerChat", getRootElement(), addBan ) 

Link to comment

Mmm, I would use a table for the words and loop through it with string.find, this was just an example because I thought you know how it should work. (Also change the addBan function's name, because addBan is a code for MTA)

Anyway, but yes that will work but it will not check the player's their messages.

Link to comment

This thing is kind of new to me, making tables and looping and getting what a player has said in chat... And what do you recommend me to do instead of a table?

----EDIT----

How do I get what the player is saying in the chat? I couldn't find a way to get what the player is saying in any chat like the custom ones for advertising or local/global chat.

Link to comment

What I said was an example, because I thought you knew how to script it with tables.

banWords = { 
"Word1", 
"Word2", 
---etc... 
} 
  
function checkChat(tMessage) 
    for placeNumber, stringData(banWords) do 
        if (string.find(string.lower(tMessage), stringData) ~= nil) then 
            banPlayer(source) --Read the wiki for other parameters like IP ban, SERIAL ban, etc. 
        end 
    end 
end 
  
addEventHandler("onPlayerChat", getRootElement(), checkChat) 

Try to understand this script. If you don't, feel free to ask explanation :)

Link to comment

I want to know if this is right:

banWords = { 
"Word1", 
"Word2", 
  
} 
  
function checkChat(tMessage) 
    for placeNumber, stringData(banWords) do 
        if (string.find(string.lower(tMessage), stringData) ~= nil) then 
            local adGuy = getPlayerFromName( source ) 
            local adGuySerial = getPlayerSerial( adGuy ) 
            if ( adGuy ) then 
                addBan( adGuySerial, IP, seconds, source, "You were banned for beeing a cunt \"{SMILIES_PATH}/icon_razz.gif\" alt=\"\" title=\"Razz\" />" ) 
            end 
        end 
    end 
end 
addEventHandler("onPlayerChat", getRootElement(), checkChat) 

From what I understood from the wiki, if I put IP in "addBan" it will ban the player IP along with "adGuySerial", which is the player serial, and if I put seconds, it will ban the player for 0 seconds (permanent ban). So, is it right? :/

Edited by Guest
Link to comment

No, it is not.

banPlayer 

Click on it and read the wiki. This code has everything you need:

Required Arguments 
bannedPlayer: The player that will be banned from the server. 
Optional Arguments 
NOTE: When using optional arguments, you must supply all arguments before the one you wish to use. For more information on optional arguments, see Optional Arguments. 
IP: Will player be banned by IP? 
Username: Will player be banned by username? 
Serial: Will player be banned by serial? 
Note: to ban by username or serial, verifyserials must be enabled in the server configuration file. 
responsibleElement: The element that is responsible for banning the player. This can be a player or the root (getRootElement()) (Maximum 30 characters if using a string). 
reason: The reason the player will be banned from the server. 
seconds: The amount of seconds the player will be banned from the server for. This can be 0 for an infinite amount of time. 

Link to comment

Now.. I don't know why it ain't working, I don't seem to get any errors, and I tried to type "Word1" in all my server chats but nothing happens..

banWords = { 
"Word1", 
"Word2", 
  
} 
  
function checkChat(tMessage) 
    for placeNumber, in ipairs stringData(banWords) do 
        if (string.find(string.lower(tMessage), stringData) ~= nil) then 
            local adGuy = getPlayerFromName( source ) 
            local adGuySerial = getPlayerSerial( adGuy ) 
            if ( adGuy ) then 
                banPlayer( adGuySerial, source, "You were banned for beeing a..." ) 
            end 
        end 
    end 
end 
addEventHandler("onPlayerChat", getRootElement(), checkChat) 

Link to comment

Again, read the wiki.

Syntax of code banPlayer:

ban banPlayer ( player bannedPlayer, [ bool IP = true, bool Username = false, bool Serial = false,  
player responsiblePlayer = nil, string reason = nil, int seconds = 0 ] ) 

Read the wiki from event 'onPlayerChat': https://wiki.multitheftauto.com/wiki/OnPlayerChat and you will find this:

"The source of this event is the player who sent the chatbox message."

Example:

banPlayer(source, true, true, true, nil, "You were banned because of insulting words", 0) --This bans the player by IP, Username and Serial without a responsible player and permanently. 
banPlayer(source, true, false, false, nil, "You were banned because of insulting words", 15000) --This bans the player by IP without a responsible player and for 15 seconds. 

This:

local adGuy = getPlayerFromName( source ) 
            local adGuySerial = getPlayerSerial( adGuy ) 
            if ( adGuy ) then 

Is not necessary.

Link to comment
  
local BannedWords = {"Pizza","Spaghetti"}; 
addEventHandler("onPlayerChat",root,function(message,type) 
    if type == 0 or type == 2 then -- if it is a normal chat message or a team chat message, not a /me message; 
        for _,word in ipairs(BannedWords) do -- loop trough the list of banned words; 
            if message:find(word) then -- if the word is found in the player's chat message; 
                banPlayer(source,false,false,true,"Server","Your chat message contained the word '"..word.."'.",0); -- ban the player by serial for an infinite amount of time with the reason and the responsible element specified; 
            end; 
        end; 
    end; 
end); 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...