..:D&G:.. Posted July 20, 2014 Posted July 20, 2014 Hello, is there anyway I can do so if a player says a word (that I define) in any chat, he gets auto-permbanned?
..:D&G:.. Posted July 20, 2014 Author Posted July 20, 2014 Can you give me a MTA example of string.find please? I never seen it before
Et-win Posted July 20, 2014 Posted July 20, 2014 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 ^^'
..:D&G:.. Posted July 20, 2014 Author Posted July 20, 2014 Thanks for helping me Btw, what does this mean? -- s:P -->
Et-win Posted July 20, 2014 Posted July 20, 2014 That was supposed to be a smiley, but it spaced I see.
..:D&G:.. Posted July 20, 2014 Author Posted July 20, 2014 How can I get the player that says the word? His name I mean..
Et-win Posted July 20, 2014 Posted July 20, 2014 Always read it on the wiki: https://wiki.multitheftauto.com/wiki/OnPlayerChat "The source of this event is the player who sent the chatbox message." So, with 'source'.
..:D&G:.. Posted July 20, 2014 Author Posted July 20, 2014 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 )
Et-win Posted July 20, 2014 Posted July 20, 2014 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.
..:D&G:.. Posted July 20, 2014 Author Posted July 20, 2014 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.
Et-win Posted July 20, 2014 Posted July 20, 2014 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
..:D&G:.. Posted July 21, 2014 Author Posted July 21, 2014 (edited) 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 July 21, 2014 by Guest
Et-win Posted July 21, 2014 Posted July 21, 2014 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.
..:D&G:.. Posted July 21, 2014 Author Posted July 21, 2014 I keep getting an error which says that 'in' is expected near '(' at this line: for placeNumber, stringData(banWords) do
Et-win Posted July 21, 2014 Posted July 21, 2014 My bad, change to: for placeNumber, stringData in ipairs(banWords) do Guess I was very sleepy yesterday.
..:D&G:.. Posted July 21, 2014 Author Posted July 21, 2014 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)
Et-win Posted July 21, 2014 Posted July 21, 2014 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.
..:D&G:.. Posted July 21, 2014 Author Posted July 21, 2014 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. I did this before, but it didn't work, imma try again.
Et-win Posted July 21, 2014 Posted July 21, 2014 Your resource needs ACL rights to ban by the way. To add them: 1. Open Admin Panel 2. Click resources tab 3. Manage ACL 4. Doubleclick on admin 5. Add object 6. enter: resource.resourcenamehere 7. Then ok.
..:D&G:.. Posted July 21, 2014 Author Posted July 21, 2014 I got this in my acl, so I don't need to add every resource in acl every time I have to: <object name="resource.*"></object>
cheez3d Posted July 21, 2014 Posted July 21, 2014 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);
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now