Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: nathmatt on January 08, 2011, 09:08:56 am

Title: [XP] RMX-OS Chat Filter
Post by: nathmatt on January 08, 2011, 09:08:56 am
RMX-OS Chat Filter
Authors: Nathmatt
Version: 2.2
Type: Message Filter
Key Term: RMX-OS Plugin



Introduction

filters game messages


Features




Screenshots

not really needed


Demo

no demo


Script

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# RMX-OS Chat Filter by Nathmatt
# Version: 2.2
# Type: Message filter
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
module Chat_Filter
 
  Flitered_Words = ['crap']
  Non_Filtered   = ['scrap']
  Replace_With   ='***'
 
end

class RMXOS::Network
 
  alias filter_add_message add_message
  def add_message(id, message, color, action = false)
    if @players[id] != nil
      message = filter_messages(message)
    end
    filter_add_message(id, message, color, action = false)
  end
 
  def filter_messages(text)
    message = text.dup
    text.each(' '){|word|
    w = word.downcase
    if !Chat_Filter::Non_Filtered.include?(w)
      Chat_Filter::Flitered_Words.each{|filter|
      if w.gsub!("#{filter}") {''} != nil
        message.gsub!("#{word}") {Chat_Filter::Replace_With+' '}
      end}
    end}
    return message
  end

end



Instructions

just place this below RMX-OS and above main



Compatibility

no issues known


Credits and Thanks




Author's Notes

if a word includes the filtered word the entire word is replaced unless it is included in the Non_Filtered array

post any bugs or suggestions here
Title: Re: [XP] RMX-OS Chat Filter
Post by: Noob on January 08, 2011, 09:36:16 am
Thanks very much for making this:)! I'll be sure to try it out and tell you about any problems I find.
Title: Re: [XP] RMX-OS Chat Filter
Post by: Noob on January 08, 2011, 11:09:48 am
Ok, just a few problems and suggestions for improvement: first of all, if you say the word within another then it isn't filtered (doesn't really matter, and I didn't specify it, just pointint it out). Also, now whenever the player talks a small non-game info box comes up telling them each word they say. This causes great inconvenience during gameplay, because it goes one word at a time. This is especially inconvenient when the player types /cmd, because it tells them all the commands one word at a time, and in the actual chatbox they are all jumbled together into one unreadable streak of gray text. As for the text in the chatbox, it is all squeezed into one line now, whereas beforehand it was split into different lines so it was readable. Also, when the server gives the player a message, such as "Bob has join the party," there are no spaces, so it looks like "Bobhasjoinedtheparty."
Title: Re: [XP] RMX-OS Chat Filter
Post by: Wizered67 on January 08, 2011, 11:24:07 am
The reason the things pop up is because nathmatt left debug stuff in. Just delete the lines that only say
p whatevericantremember
. The other problems I don't know. Oh, and one bug I found is that if you put an exclamation point after a word it gets through.
Edit: I'm not getting the no space error so I'm not sure why you are.... Did you do anything weird to the script....
Title: Re: [XP] RMX-OS Chat Filter
Post by: nathmatt on January 08, 2011, 02:39:12 pm
update 1.5 it now removes any indication of the word in that capitalization i hope to figure out a way to fix that
Title: Re: [XP] RMX-OS Chat Filter
Post by: ForeverZer0 on January 08, 2011, 02:50:07 pm
text.downcase.gsub!

Just have all the bad words you define be in all lower case.

You could also include a few regular expessions to not have it replace words that are with in other words.

ex. "ass" is a bad word.

the word "assisstance" would look like this: "***isstance"


EDIT: Nevermind the capitilization. I see you said you fixed that. oops.
Title: Re: [XP] RMX-OS Chat Filter
Post by: nathmatt on January 08, 2011, 02:58:37 pm
i thought of using.downcase but then nothing you typed would every be capitalized
Title: Re: [XP] RMX-OS Chat Filter
Post by: ForeverZer0 on January 08, 2011, 03:05:48 pm
Don't use downcase!, use downcase.
If you scripted it right it would not modify the original string, but only scan it for bad words in all lower case. It won't actually change it unless you are doing something like this.


old_string = 'HEY THIS IS CAPS'
new_string = old_string.downcase.gsub('caps') { '***' }


This returns: "hey this is ***"

If you simply do this, the capitilization remains the same:


old_string = 'HEY THIS IS CAPS'
old_string.downcase.gsub!('caps') { '***' }


This returns: "HEY THIS IS ***"
Title: Re: [XP] RMX-OS Chat Filter
Post by: nathmatt on January 08, 2011, 03:23:25 pm
update 2.0 fixed it the entire word gets replaced unless it is included in the Non_Filtered array
Title: Re: [XP] RMX-OS Chat Filter
Post by: mroedesigns on January 08, 2011, 06:13:50 pm
Hey, awesome script!

I found an issue though. If the string is multiple words, and the first word is filtered, it crashes on line 61 with 'ArgumentError Occurred'.

text.each(' '){|word|Chat_Filter::Flitered_Words.each{|filter|
Title: Re: [XP] RMX-OS Chat Filter
Post by: nathmatt on January 08, 2011, 07:53:52 pm
update 2.1 fixed above error had to do with editing the string i was going trough so i just duplicated it using .dup
Title: Re: [XP] RMX-OS Chat Filter
Post by: Noob on January 09, 2011, 03:01:21 pm
Thanks, everything seems to work now!
Title: Re: [XP] RMX-OS Chat Filter
Post by: Noob on January 26, 2011, 06:35:18 pm
Hey I've got a minor issue with this, nothing horrible, but i was wondering if it's fixable. When a user types /cmd to see the commands, certain ones are blotted out if "ass" is a bad word. For instance, /newpass. Even if I make it a non-filtered word, it's still blotted out in /cmd. Any ideas?
Title: Re: [XP] RMX-OS Chat Filter
Post by: nathmatt on January 26, 2011, 07:00:28 pm
update 2.2 fixed above bug