Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###############################################################################
- # Enelvon Script System Ace: Enelvon Script Core
- # v1.1
- # 4.14.2012
- # Compatibility: VXAce/RGSS3
- # Author: Enelvon
- #===============================================================================
- # Terms of Use:
- #
- # This script may be used for free in any game, whether it's commercial or not.
- # The only requirement is that I be credited in some visible manner. You may not
- # claim this script as your own work. You are free to modify this script, but
- # may not redistribute it except for in a thread that I have started that relates
- # to it in some way.
- #===============================================================================
- # Changelog:
- # 4.14.2012: v1.0 - Script written.
- # 4.14.2012: v1.1 - Realized I'd forgotten to include a handler for Common Events
- # and added it.
- #===============================================================================
- # This script is required for many of my scripts. It adds in a simple universal
- # method for scanning the notes of any RPG objects as well as the comments in
- # events. I would recommend that you always make sure you have the latest
- # version of this script. I don't expect it to be updated very often, but when
- # it is you can be sure that it will be important.
- #===============================================================================
- # Required Scripts: None
- # Known Incompatibilities: None - there should never be any unless someone uses
- # the same method names as I did, which I feel is unlikely.
- #===============================================================================
- # Installation: Place below Materials and above all other custom scripts. There
- # are no redefinitions in this script, so there will be no conflicts with other
- # scripts - it simply contains some rather important definitions that need to be
- # implemented before many of my scripts will do anything but throw out errors.
- #===============================================================================
- # Instructions: Follow the Installation directions. That's all. This script does
- # nothing on its own, merely sets up a base for other scripts.
- #==============================================================================
- # How to use the Enelvon Script Core for your own scripts (Scripter Resource):
- #
- # The Enelvon Script Core provides an easy way to get information from the Notes
- # boxes of any game object, whether it's an actor, an item, an enemy, or even a
- # map or tileset. If it has a Notes box, it can check the data. It also allows
- # you to get information from the Comments boxes in events. It works entirely
- # through aliasing once this script is installed.
- #
- #
- # USING THE en_scan_notes METHOD TO RETRIEVE DATA FROM AN OBJECT
- #
- # 1) Open the class that you want to work with. Our example will use RPG::Actor.
- #
- # class RPG::Actor < RPG::BaseItem
- #
- # 2) Create a unique alias for en_scan_notes. The method that I use is en_ (for
- # Enelvon) followed by the initials of the script name, then the initials of
- # the class that I'm working with, then _sn. I'll be calling this script
- # Base Example, so my alias would be en_be_a_sn.
- #
- # class RPG::Actor < RPG::BaseItem
- # alias en_be_a_sn en_scan_notes
- #
- # 3) Now we open the en_scan_notes method. Be sure not to forget the parameters.
- #
- # class RPG::Actor < RPG::BaseItem
- # alias en_be_a_sn en_scan_notes
- # def en_scan_notes(tags = [])
- #
- # 4) The next step is to set our new variables. I'll be creating an Age variable
- # and a Sex variable.
- #
- # class RPG::Actor < RPG::BaseItem
- # alias en_be_a_sn en_scan_notes
- # def en_scan_notes(tags = [])
- # @age = 18
- # @sex = "Female"
- #
- # 5) Now we're going to create the tags that the script will search for, as well
- # as what will happen when they're found. I usually define them as Constants
- # in a subclass of the Enelvon module, but in this case I'll just define them
- # within en_scan_notes itself. We create a new tags by adding an array to tags
- # that has a Regular Expression or String as its first value (which is what
- # will be checked for in the Notes box) and a String as its second value. The
- # second value should contain script information that will be evaluated if the
- # tag is found. In the example, it will set one of the new variables to the
- # value recovered from the Notes box.
- #
- # class RPG::Actor < RPG::BaseItem
- # alias en_be_a_sn en_scan_notes
- # def en_scan_notes(tags = [])
- # @age = 18
- # @sex = "Female"
- # tags.push([/^<(age|sex): (\w+)>/, "case $1.to_s
- # when 'age'
- # @age = $2.to_i
- # when 'sex'
- # @sex = $2.to_s
- # end"])
- #
- # 6) Now we're going to call the alias and pass it the new tags array. We can
- # close the method now.
- #
- # class RPG::Actor < RPG::BaseItem
- # alias en_be_a_sn en_scan_notes
- # def en_scan_notes(tags = [])
- # @age = 18
- # @sex = "Female"
- # tags.push([/^<(age|sex): (\w+)>/, "case $1.to_s
- # when 'age'
- # @age = $2.to_i
- # when 'sex'
- # @sex = $2.to_s
- # end"])
- # en_be_a_sn(tags)
- # end
- #
- # 7) Now we have to set up a way to check the @age and @sex values - they'll
- # return nil without any help. I prefer using this method to define my variables,
- # as it takes much less time than doing it individually:
- #
- # class RPG::Actor < RPG::BaseItem
- # alias en_be_a_sn en_scan_notes
- # def en_scan_notes(tags = [])
- # @age = 18
- # @sex = "Female"
- # tags.push([/^<(age|sex): (\w+)>/, "case $1.to_s
- # when 'age'
- # @age = $2.to_i
- # when 'sex'
- # @sex = $2.to_s
- # end"])
- # en_be_a_sn(tags)
- # end
- #
- # traits = [:age, :sex]
- # traits.each_index { |i|
- # define_method(traits[i]) {
- # en_scan_notes if eval("@#{traits[i]}.nil?")
- # return eval("@#{traits[i]}")
- # }
- # }
- #
- # Any Symbols (though I suppose Strings would work as well) in the traits array
- # will be turned into methods that will call en_scan_notes if the variables
- # matching them are nil. This can be included in as many scripts as you'd like
- # with no issues, as it isn't a method - it's something that's run once when
- # the script is first read, does its thing, and is then retired.
- #
- # 8) Now we can close the class - we're done!
- #
- # class RPG::Actor < RPG::BaseItem
- # alias en_be_a_sn en_scan_notes
- # def en_scan_notes(tags = [])
- # @age = 18
- # @sex = "Female"
- # tags.push([/^<(age|sex): (\w+)>/, "case $1.to_s
- # when 'age'
- # @age = $2.to_i
- # when 'sex'
- # @sex = $2.to_s
- # end"])
- # en_be_a_sn(tags)
- # end
- #
- # traits = [:age, :sex]
- # traits.each_index { |i|
- # define_method(traits[i]) {
- # en_scan_notes if eval("@#{traits[i]}.nil?")
- # return eval("@#{traits[i]}")
- # }
- # }
- # end
- #
- # 10) Now we need to define these traits for Game_Actor, or else they're useless.
- # To do this we'll have to alias the setup method.
- #
- # class Game_Actor < Game_Battler
- # attr_accessor :age; attr_accessor :sex
- #
- # alias en_be_a_s setup
- # def setup(actor_id)
- # en_be_a_s(actor_id)
- # @age = actor.age
- # @sex = actor.sex
- # end
- # end
- #
- # 11) We're done! We can now retrieve and modify an actor's age or sex with the
- # calls $game_actors[x].age and $game_actors[x].sex.
- #
- # USING THE en_scan_comments METHOD TO RETRIEVE DATA FROM AN EVENT PAGE
- #
- # 1) Open the RPG::Event::Page class.
- #
- # class RPG::Event::Page
- #
- # 2) Create an alias for en_scan_comments. I do this in a similar manner to
- # aliases for en_scan_notes, though I use _sc instead of _sn and leave out
- # the part about the class, since it's all about RPG::Event::Page.
- #
- # class RPG::Event::Page
- # alias en_be_sc en_scan_comments
- # def en_scan_comments(comments = [])
- #
- # 3) Now we'll set up our new variables. This example will show you how to make
- # the Movement Type options from my ESS Ace: Enhanced Events script, so the
- # variable that we'll be using is @movement.
- #
- # class RPG::Event::Page
- # alias en_be_sc en_scan_comments
- # def en_scan_comments(comments = [])
- # @movement = "Walking"
- #
- # 4) Now we'll add in the tag that needs to be in a Comments box for the movement
- # type to be changed. Note that only one tag can be easily found in any given
- # Comments box due to the fact that they recognize only a single line of data.
- #
- # class RPG::Event::Page
- # alias en_be_sc en_scan_comments
- # def en_scan_comments(comments = [])
- # @movement = "Walking"
- # comments.push([/^Movement: (Boat|Ship|Fly)/, "@movement = $1.to_s"])
- #
- # 5) Now we'll call our alias and give it the comments array, after which we
- # can close the method.
- #
- # class RPG::Event::Page
- # alias en_be_sc en_scan_comments
- # def en_scan_comments(comments = [])
- # @movement = "Walking"
- # comments.push([/^Movement: (Boat|Ship|Fly)/, "@movement = $1.to_s"])
- # en_be_sc(comments)
- # end
- #
- # 6) Now we'll set up the methods for getting the value for movement. We can do
- # this in the same way that we did in the section on en_scan_notes. After that
- # we can close the class
- #
- # class RPG::Event::Page
- # alias en_be_sc en_scan_comments
- # def en_scan_comments(comments = [])
- # @movement = "Walking"
- # comments.push([/^Movement: (Boat|Ship|Fly)/, "@movement = $1.to_s"])
- # en_be_sc(comments)
- # end
- #
- # traits = [:age, :sex]
- # traits.each_index { |i|
- # define_method(traits[i]) {
- # en_scan_notes if eval("@#{traits[i]}.nil?")
- # return eval("@#{traits[i]}")
- # }
- # }
- # end
- #
- # 7) The last thing that we need to do is set up the handling within Game_Event.
- # We'll do this by redefining map_passable?
- #
- # class Game_Event < Game_Character
- # alias en_be_sc en_scan_comments
- # def map_passable?(x, y, d)
- # case @page.movement
- # when "Boat"
- # $game_map.boat_passable?(x, y)
- # when "Ship"
- # $game_map.ship_passable?(x, y)
- # when "Flying"
- # true
- # else
- # super
- # end
- # end
- # end
- #
- # 8) We're done! Now events can travel as boats, ships, or airships if they have
- # the right tag in a Comments box. This is done per-page, so an event can
- # have different methods of travel by using different tags on different pages.
- #
- ################################################################################
- $imported = {} if $imported.nil?
- $imported["ESSA - Script Core"] = true
- module RPG
- def en_scan_notes(tags = [])
- self.note.split(/[\r\n]+/).each { |line|
- for tag in tags
- case line
- when tag[0]
- eval(tag[1])
- end
- end
- }
- end
- def en_scan_comments(comments = [])
- for command in @list
- next unless command.code == 108
- comments.each do |com|
- case command.parameters[0]
- when com[0]
- eval(com[1])
- end
- end
- end
- end
- end
- class RPG::Map;include RPG;end
- class RPG::Class::Learning;include RPG;end
- class RPG::BaseItem;include RPG;end
- class RPG::Enemy;include RPG;end
- class RPG::Tileset;include RPG;end
- class RPG::Event::Page;include RPG;end
- class RPG::CommonEvent;include RPG;end
Advertisement
Add Comment
Please, Sign In to add comment