Enelvon

Enelvon Script Core

Apr 14th, 2012
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.88 KB | None | 0 0
  1. ###############################################################################
  2. # Enelvon Script System Ace: Enelvon Script Core
  3. # v1.1
  4. # 4.14.2012
  5. # Compatibility: VXAce/RGSS3
  6. # Author: Enelvon
  7. #===============================================================================
  8. # Terms of Use:
  9. #
  10. # This script may be used for free in any game, whether it's commercial or not.
  11. # The only requirement is that I be credited in some visible manner. You may not
  12. # claim this script as your own work. You are free to modify this script, but
  13. # may not redistribute it except for in a thread that I have started that relates
  14. # to it in some way.
  15. #===============================================================================
  16. # Changelog:
  17. # 4.14.2012: v1.0 - Script written.
  18. # 4.14.2012: v1.1 - Realized I'd forgotten to include a handler for Common Events
  19. #                   and added it.
  20. #===============================================================================                          
  21. # This script is required for many of my scripts. It adds in a simple universal
  22. # method for scanning the notes of any RPG objects as well as the comments in
  23. # events. I would recommend that you always make sure you have the  latest
  24. # version of this script. I don't expect it to be updated very often, but when
  25. # it is you can be sure that it will be important.
  26. #===============================================================================
  27. # Required Scripts: None
  28. # Known Incompatibilities: None - there should never be any unless someone uses
  29. # the same method names as I did, which I feel is unlikely.
  30. #===============================================================================
  31. # Installation: Place below Materials and above all other custom scripts. There
  32. # are no redefinitions in this script, so there will be no conflicts with other
  33. # scripts - it simply contains some rather important definitions that need to be
  34. # implemented before many of my scripts will do anything but throw out errors.
  35. #===============================================================================
  36. # Instructions: Follow the Installation directions. That's all. This script does
  37. # nothing on its own, merely sets up a base for other scripts.
  38. #==============================================================================
  39. # How to use the Enelvon Script Core for your own scripts (Scripter Resource):
  40. #
  41. # The Enelvon Script Core provides an easy way to get information from the Notes
  42. # boxes of any game object, whether it's an actor, an item, an enemy, or even a
  43. # map or tileset. If it has a Notes box, it can check the data. It also allows
  44. # you to get information from the Comments boxes in events. It works entirely
  45. # through aliasing once this script is installed.
  46. #
  47. #
  48. # USING THE en_scan_notes METHOD TO RETRIEVE DATA FROM AN OBJECT
  49. #
  50. # 1) Open the class that you want to work with. Our example will use RPG::Actor.
  51. #
  52. #      class RPG::Actor < RPG::BaseItem
  53. #
  54. # 2) Create a unique alias for en_scan_notes. The method that I use is en_ (for
  55. #    Enelvon) followed by the initials of the script name, then the initials of
  56. #    the class that I'm working with, then _sn. I'll be calling this script
  57. #    Base Example, so my alias would be en_be_a_sn.
  58. #
  59. #      class RPG::Actor < RPG::BaseItem
  60. #         alias en_be_a_sn en_scan_notes
  61. #
  62. # 3) Now we open the en_scan_notes method. Be sure not to forget the parameters.
  63. #
  64. #      class RPG::Actor < RPG::BaseItem
  65. #         alias en_be_a_sn en_scan_notes
  66. #         def en_scan_notes(tags = [])
  67. #
  68. # 4) The next step is to set our new variables. I'll be creating an Age variable
  69. #    and a Sex variable.
  70. #
  71. #      class RPG::Actor < RPG::BaseItem
  72. #         alias en_be_a_sn en_scan_notes
  73. #         def en_scan_notes(tags = [])
  74. #           @age = 18
  75. #           @sex = "Female"
  76. #
  77. # 5) Now we're going to create the tags that the script will search for, as well
  78. #    as what will happen when they're found. I usually define them as Constants
  79. #    in a subclass of the Enelvon module, but in this case I'll just define them
  80. #    within en_scan_notes itself. We create a new tags by adding an array to tags
  81. #    that has a Regular Expression or String as its first value (which is what
  82. #    will be checked for in the Notes box) and a String as its second value. The
  83. #    second value should contain script information that will be evaluated if the
  84. #    tag is found. In the example, it will set one of the new variables to the
  85. #    value recovered from the Notes box.
  86. #
  87. #      class RPG::Actor < RPG::BaseItem
  88. #         alias en_be_a_sn en_scan_notes
  89. #         def en_scan_notes(tags = [])
  90. #           @age = 18
  91. #           @sex = "Female"
  92. #           tags.push([/^<(age|sex): (\w+)>/, "case $1.to_s
  93. #           when 'age'
  94. #             @age = $2.to_i
  95. #           when 'sex'
  96. #             @sex = $2.to_s
  97. #           end"])
  98. #
  99. # 6) Now we're going to call the alias and pass it the new tags array. We can
  100. #    close the method now.
  101. #
  102. #      class RPG::Actor < RPG::BaseItem
  103. #         alias en_be_a_sn en_scan_notes
  104. #         def en_scan_notes(tags = [])
  105. #           @age = 18
  106. #           @sex = "Female"
  107. #           tags.push([/^<(age|sex): (\w+)>/, "case $1.to_s
  108. #           when 'age'
  109. #             @age = $2.to_i
  110. #           when 'sex'
  111. #             @sex = $2.to_s
  112. #           end"])
  113. #           en_be_a_sn(tags)
  114. #         end
  115. #
  116. # 7) Now we have to set up a way to check the @age and @sex values - they'll
  117. #    return nil without any help. I prefer using this method to define my variables,
  118. #    as it takes much less time than doing it individually:
  119. #
  120. #      class RPG::Actor < RPG::BaseItem
  121. #         alias en_be_a_sn en_scan_notes
  122. #         def en_scan_notes(tags = [])
  123. #           @age = 18
  124. #           @sex = "Female"
  125. #           tags.push([/^<(age|sex): (\w+)>/, "case $1.to_s
  126. #           when 'age'
  127. #             @age = $2.to_i
  128. #           when 'sex'
  129. #             @sex = $2.to_s
  130. #           end"])
  131. #           en_be_a_sn(tags)
  132. #         end
  133. #
  134. #         traits = [:age, :sex]
  135. #         traits.each_index { |i|
  136. #           define_method(traits[i]) {
  137. #           en_scan_notes if eval("@#{traits[i]}.nil?")
  138. #           return eval("@#{traits[i]}")
  139. #           }
  140. #         }
  141. #
  142. #   Any Symbols (though I suppose Strings would work as well) in the traits array
  143. #   will be turned into methods that will call en_scan_notes if the variables
  144. #   matching them are nil. This can be included in as many scripts as you'd like
  145. #   with no issues, as it isn't a method - it's something that's run once when
  146. #   the script is first read, does its thing, and is then retired.
  147. #
  148. # 8) Now we can close the class - we're done!
  149. #
  150. #      class RPG::Actor < RPG::BaseItem
  151. #         alias en_be_a_sn en_scan_notes
  152. #         def en_scan_notes(tags = [])
  153. #           @age = 18
  154. #           @sex = "Female"
  155. #           tags.push([/^<(age|sex): (\w+)>/, "case $1.to_s
  156. #           when 'age'
  157. #             @age = $2.to_i
  158. #           when 'sex'
  159. #             @sex = $2.to_s
  160. #           end"])
  161. #           en_be_a_sn(tags)
  162. #         end
  163. #
  164. #         traits = [:age, :sex]
  165. #         traits.each_index { |i|
  166. #           define_method(traits[i]) {
  167. #           en_scan_notes if eval("@#{traits[i]}.nil?")
  168. #           return eval("@#{traits[i]}")
  169. #           }
  170. #         }
  171. #      end
  172. #
  173. # 10) Now we need to define these traits for Game_Actor, or else they're useless.
  174. #     To do this we'll have to alias the setup method.
  175. #
  176. #     class Game_Actor < Game_Battler
  177. #       attr_accessor :age; attr_accessor :sex
  178. #
  179. #       alias en_be_a_s setup
  180. #       def setup(actor_id)
  181. #         en_be_a_s(actor_id)
  182. #         @age = actor.age
  183. #         @sex = actor.sex
  184. #       end
  185. #     end
  186. #
  187. # 11) We're done! We can now retrieve and modify an actor's age or sex with the
  188. #     calls $game_actors[x].age and $game_actors[x].sex.
  189. #
  190. # USING THE en_scan_comments METHOD TO RETRIEVE DATA FROM AN EVENT PAGE
  191. #
  192. # 1) Open the RPG::Event::Page class.
  193. #
  194. #      class RPG::Event::Page
  195. #
  196. # 2) Create an alias for en_scan_comments. I do this in a similar manner to
  197. #    aliases for en_scan_notes, though I use _sc instead of _sn and leave out
  198. #    the part about the class, since it's all about RPG::Event::Page.
  199. #
  200. #      class RPG::Event::Page
  201. #        alias en_be_sc en_scan_comments
  202. #        def en_scan_comments(comments = [])
  203. #
  204. # 3) Now we'll set up our new variables. This example will show you how to make
  205. #    the Movement Type options from my ESS Ace: Enhanced Events script, so the
  206. #    variable that we'll be using is @movement.
  207. #
  208. #      class RPG::Event::Page
  209. #        alias en_be_sc en_scan_comments
  210. #        def en_scan_comments(comments = [])
  211. #          @movement = "Walking"
  212. #
  213. # 4) Now we'll add in the tag that needs to be in a Comments box for the movement
  214. #    type to be changed. Note that only one tag can be easily found in any given
  215. #    Comments box due to the fact that they recognize only a single line of data.
  216. #
  217. #      class RPG::Event::Page
  218. #        alias en_be_sc en_scan_comments
  219. #        def en_scan_comments(comments = [])
  220. #          @movement = "Walking"
  221. #          comments.push([/^Movement: (Boat|Ship|Fly)/, "@movement = $1.to_s"])
  222. #
  223. # 5) Now we'll call our alias and give it the comments array, after which we
  224. #    can close the method.
  225. #
  226. #      class RPG::Event::Page
  227. #        alias en_be_sc en_scan_comments
  228. #        def en_scan_comments(comments = [])
  229. #          @movement = "Walking"
  230. #          comments.push([/^Movement: (Boat|Ship|Fly)/, "@movement = $1.to_s"])
  231. #          en_be_sc(comments)
  232. #        end
  233. #
  234. # 6) Now we'll set up the methods for getting the value for movement. We can do
  235. #    this in the same way that we did in the section on en_scan_notes. After that
  236. #    we can close the class
  237. #
  238. #      class RPG::Event::Page
  239. #        alias en_be_sc en_scan_comments
  240. #        def en_scan_comments(comments = [])
  241. #          @movement = "Walking"
  242. #          comments.push([/^Movement: (Boat|Ship|Fly)/, "@movement = $1.to_s"])
  243. #          en_be_sc(comments)
  244. #        end
  245. #
  246. #        traits = [:age, :sex]
  247. #        traits.each_index { |i|
  248. #          define_method(traits[i]) {
  249. #          en_scan_notes if eval("@#{traits[i]}.nil?")
  250. #          return eval("@#{traits[i]}")
  251. #          }
  252. #        }
  253. #      end
  254. #
  255. # 7) The last thing that we need to do is set up the handling within Game_Event.
  256. #    We'll do this by redefining map_passable?
  257. #
  258. #      class Game_Event < Game_Character
  259. #        alias en_be_sc en_scan_comments
  260. #        def map_passable?(x, y, d)
  261. #          case @page.movement
  262. #          when "Boat"
  263. #            $game_map.boat_passable?(x, y)
  264. #          when "Ship"
  265. #            $game_map.ship_passable?(x, y)
  266. #          when "Flying"
  267. #            true
  268. #          else
  269. #            super
  270. #          end
  271. #        end
  272. #      end
  273. #
  274. # 8) We're done! Now events can travel as boats, ships, or airships if they have
  275. #    the right tag in a Comments box. This is done per-page, so an event can
  276. #    have different methods of travel by using different tags on different pages.
  277. #
  278. ################################################################################
  279.  
  280. $imported = {} if $imported.nil?
  281. $imported["ESSA - Script Core"] = true
  282.  
  283. module RPG  
  284.   def en_scan_notes(tags = [])
  285.     self.note.split(/[\r\n]+/).each { |line|
  286.     for tag in tags
  287.       case line
  288.       when tag[0]
  289.         eval(tag[1])
  290.       end
  291.     end
  292.     }
  293.   end
  294.  
  295.   def en_scan_comments(comments = [])
  296.     for command in @list
  297.       next unless command.code == 108
  298.       comments.each do |com|
  299.         case command.parameters[0]
  300.         when com[0]
  301.           eval(com[1])
  302.         end
  303.       end
  304.     end
  305.   end
  306. end
  307. class RPG::Map;include RPG;end
  308. class RPG::Class::Learning;include RPG;end
  309. class RPG::BaseItem;include RPG;end
  310. class RPG::Enemy;include RPG;end
  311. class RPG::Tileset;include RPG;end
  312. class RPG::Event::Page;include RPG;end
  313. class RPG::CommonEvent;include RPG;end
Advertisement
Add Comment
Please, Sign In to add comment