Enelvon

SES: Enhanced Events

Apr 14th, 2012
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.56 KB | None | 0 0
  1. ###############################################################################
  2. # SES: Enhanced Events
  3. # v1.2
  4. # 11.27.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. # 11.17.2012: v1.1 - Added support for playing BGS based on the player's distance
  19. #                    from the event
  20. # 11.27.2012: v1.2 - Fixed a bug with nil event pages
  21. #===============================================================================                          
  22. # This script adds in some new functions for events, including extra conditions
  23. # (such as script calls or requiring more than one actor to be in the party),
  24. # moving like a boat, ship, or airship, and changed passability so that events
  25. # set as Below Characters or Above Characters no longer block the movement of
  26. # events set as Same as Characters, unless they include a certain tag in a
  27. # Comments box.
  28. #===============================================================================
  29. # Required Scripts: Enelvon Script Core v1.0 or higher
  30. # Known Incompatibilities: None, though it contains some redefinitions so some
  31. #     may occur if this script is below another script that aliases the same
  32. #     method, or if it is above another script that redefines that method. A full
  33. #     list of redefinitions is included at the bottom of my comments.
  34. #===============================================================================
  35. # Installation: Place below Materials and the Enelvon Script Core and above all
  36. # other custom scripts (just to be safe).
  37. #===============================================================================
  38. # Instructions:
  39. #
  40. # ***Constants for SES::EnhancedEvents***
  41. #
  42. # EventConditions - this is a hash of extra conditions for event pages. The keys
  43. #     should all be strings, and the values should be strings that contain basic
  44. #     or advanced scripts to be evaluated as conditions for a page. There are some
  45. #     examples already included. Conditions will not be active unless a page
  46. #     includes their key in a Conditions tag.
  47. #
  48. # ExtraCondition - this is the RegExp for giving an event page extra conditions.
  49. #
  50. # EventBlock - this is the RegExp for giving an event page extra conditions.
  51. #
  52. # MovementType - this is the RegExp for giving an event page extra conditions.
  53. #
  54. # PlaySound - this is the RegExp for the SE that will play when the player is
  55. #             close to the event.
  56. #
  57. # ***Additional: Event Comments***
  58. #
  59. # You can customize this script for each event page in your game by adding tags
  60. # in Comments boxes. Each box can contain only one tag, unfortunately - but you
  61. # can have as many boxes as you want. These are the tags available in this script:
  62. #
  63. # <Condition: !Cond!>
  64. #   Place this in a Comments box to give an event page extra conditions. You can
  65. #   include as many of these as you would like on a page.
  66. #   Replacements:
  67. #     !Cond! with the name of the key in EventConditions that you want to use
  68. #            as a condition.
  69. #
  70. # <EventBlock>
  71. #   Place this in a Comments box to cause an event to prevent other events from
  72. #   passing them, regardless of their priority type.
  73. #   Replacements:
  74. #     None
  75. #
  76. # <MovementType: !Type!>
  77. #   Place this in a Comments box to change the movement type of the event page
  78. #   to that of a boat, ship, or airship.
  79. #   Replacements:
  80. #     !Type! with Boat, Ship, or Fly.
  81. #
  82. # <Sound: !SE!, !MV!, !MD!>
  83. #   Place this in a Comments box to cause the event to produce a Sound Effect
  84. #   when the player is near.
  85. #   Replacements:
  86. #     !SE! with the name of the file in Audio/BGS (without the extension)
  87. #     !MV! with the loudest the sound is allowed to be (max 100)
  88. #     !MD! with the maximum distance that the player can be and still hear the
  89. #          sound (albeit faintly); this is also used to calculate how loud the
  90. #          sound is at various distances
  91. #
  92. #===============================================================================
  93. # Aliases:
  94. #
  95. # These are the methods that are aliased by this script. This information is
  96. # included for the purpose of pinpointing compatibility errors between scripts.
  97. #
  98. # ***class Game_Event***
  99. #
  100. #   conditions_met?(page)
  101. #
  102. #===============================================================================
  103. # Redefinitions:
  104. #
  105. # These are the methods that are redefined by this script. This information is
  106. # included for the purpose of pinpointing compatibility errors between scripts.
  107. #
  108. # ***class Game_Event***
  109. #
  110. #   map_passable?(x, y, d)
  111. #
  112. #   collide_with_events(x, y)
  113. #
  114. ################################################################################
  115. module SES
  116.   module EnhancedEvents
  117.    
  118.     EventConditions = {
  119.     # Key => "script to evaluate",
  120.    
  121.     # As long as $game_variables[1] isn't 5, the event page can run
  122.     "Var1" => "$game_variables[1] != 5",
  123.     # The event page can run only if $game_variables[1] equals 6
  124.     "Var2" => "$game_variables[1] == 6",
  125.     # The event page can only run if the party doesn't include actor 3
  126.     "Act3" => "!$game_party.members.include?($game_actors[3])",
  127.     # The event page can only run if $game_switches[1] is off
  128.     "Swi1" => "!$game_switches[1]",
  129.     # The event can only run if the lead party member is equipped with a Hand Axe
  130.     "Equ1" => "$game_party.members[0].weapons.include?($data_weapons[1])",
  131.     }
  132.    
  133.     # RegExp for an event page's extra conditions. You can include more than one.
  134.     ExtraCondition = /^Condition:(?:\s*)([\w]+)/i
  135.     # RegExp to cause an event page to block the movement of other events.
  136.     EventBlock = /^(EventBlock|Event Block)/i
  137.     # RegExp for an event page's movement type.
  138.     MovementType = /^Movement:(?:\s*)(Boat|Ship|Fly)/i
  139.     # RegExp for the SE that will play when the player is close to the event
  140.     PlaySound = /^Sound:(?:\s*)(\w+),(?:\s*)(\d+),(?:\s*)(\d+)/i
  141.    
  142.   end
  143. end
  144.  
  145. $imported = {} if $imported.nil?
  146. $imported["SES - EnhancedEvents"] = true
  147.  
  148. class RPG::Event::Page
  149.  
  150.   alias en_ee_sc en_scan_comments
  151.   def en_scan_comments(comments = [])
  152.     @extraconditions = []
  153.     @eventblock = false
  154.     @movement = "Walking"
  155.     @sound = []
  156.     comments.push([SES::EnhancedEvents::ExtraCondition, "@extraconditions.push($1.to_s)"])
  157.     comments.push([SES::EnhancedEvents::EventBlock, "@eventblock = true"])
  158.     comments.push([SES::EnhancedEvents::MovementType, "@movement = $1.to_s"])
  159.     comments.push([SES::EnhancedEvents::PlaySound, "@sound = [$1.to_s, $2.to_i, $3.to_i]"])
  160.     en_ee_sc(comments)
  161.   end
  162.  
  163.     [:extraconditions, :eventblock, :movement, :sound].each do |i|
  164.         define_method(traits[i]) do
  165.             en_scan_comments if eval("@#{traits[i]}.nil?")
  166.             return eval("@#{traits[i]}")
  167.         end
  168.   end
  169.  
  170. end
  171.  
  172. class Game_Event < Game_Character
  173.  
  174.   attr_reader :page
  175.  
  176.   def map_passable?(x, y, d)
  177.     case @page.movement
  178.     when "Boat"
  179.       $game_map.boat_passable?(x, y)
  180.     when "Ship"
  181.       $game_map.ship_passable?(x, y)
  182.     when "Flying"
  183.       true
  184.     else
  185.       super
  186.     end
  187.   end
  188.  
  189.   alias en_ee_ge_u update
  190.   def update
  191.     en_ee_ge_u
  192.     if @sound.nil? && @page && !@page.sound.empty?
  193.       @sound = RPG::BGS.new(@page.sound[0], volume(@page.sound[1], @page.sound[2]), 100)
  194.       @sound.play
  195.     end
  196.     (@sound.volume = volume(@page.sound[1], @page.sound[2]); @sound.play) if @sound
  197.   end
  198.  
  199.   def volume(max_vol, max_dist)
  200.     if distance_from($game_player) > max_dist then 0
  201.     else [max_vol,
  202.          (max_vol / max_dist) * (max_dist+1 - distance_from($game_player))].min
  203.     end
  204.   end
  205.  
  206.   def distance_from(char)
  207.     return distance_x_from(char.x).abs + distance_y_from(char.y).abs
  208.   end
  209.    
  210.   def collide_with_events?(x, y)
  211.     $game_map.events_xy_nt(x, y).any? do |event|
  212.       return true if event.page.eventblock
  213.       return false if event.through
  214.       return event.priority_type == self.priority_type
  215.     end
  216.   end
  217.  
  218.   alias en_ee_ge_cm conditions_met?
  219.   def conditions_met?(page)
  220.     page.extraconditions.each do |i|
  221.       return false unless eval(SES::EnhancedEvents::EventConditions[i])
  222.     end
  223.     en_ee_ge_cm(page)
  224.   end
  225. end
Advertisement
Add Comment
Please, Sign In to add comment