Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###############################################################################
- # SES: Enhanced Events
- # v1.2
- # 11.27.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.
- # 11.17.2012: v1.1 - Added support for playing BGS based on the player's distance
- # from the event
- # 11.27.2012: v1.2 - Fixed a bug with nil event pages
- #===============================================================================
- # This script adds in some new functions for events, including extra conditions
- # (such as script calls or requiring more than one actor to be in the party),
- # moving like a boat, ship, or airship, and changed passability so that events
- # set as Below Characters or Above Characters no longer block the movement of
- # events set as Same as Characters, unless they include a certain tag in a
- # Comments box.
- #===============================================================================
- # Required Scripts: Enelvon Script Core v1.0 or higher
- # Known Incompatibilities: None, though it contains some redefinitions so some
- # may occur if this script is below another script that aliases the same
- # method, or if it is above another script that redefines that method. A full
- # list of redefinitions is included at the bottom of my comments.
- #===============================================================================
- # Installation: Place below Materials and the Enelvon Script Core and above all
- # other custom scripts (just to be safe).
- #===============================================================================
- # Instructions:
- #
- # ***Constants for SES::EnhancedEvents***
- #
- # EventConditions - this is a hash of extra conditions for event pages. The keys
- # should all be strings, and the values should be strings that contain basic
- # or advanced scripts to be evaluated as conditions for a page. There are some
- # examples already included. Conditions will not be active unless a page
- # includes their key in a Conditions tag.
- #
- # ExtraCondition - this is the RegExp for giving an event page extra conditions.
- #
- # EventBlock - this is the RegExp for giving an event page extra conditions.
- #
- # MovementType - this is the RegExp for giving an event page extra conditions.
- #
- # PlaySound - this is the RegExp for the SE that will play when the player is
- # close to the event.
- #
- # ***Additional: Event Comments***
- #
- # You can customize this script for each event page in your game by adding tags
- # in Comments boxes. Each box can contain only one tag, unfortunately - but you
- # can have as many boxes as you want. These are the tags available in this script:
- #
- # <Condition: !Cond!>
- # Place this in a Comments box to give an event page extra conditions. You can
- # include as many of these as you would like on a page.
- # Replacements:
- # !Cond! with the name of the key in EventConditions that you want to use
- # as a condition.
- #
- # <EventBlock>
- # Place this in a Comments box to cause an event to prevent other events from
- # passing them, regardless of their priority type.
- # Replacements:
- # None
- #
- # <MovementType: !Type!>
- # Place this in a Comments box to change the movement type of the event page
- # to that of a boat, ship, or airship.
- # Replacements:
- # !Type! with Boat, Ship, or Fly.
- #
- # <Sound: !SE!, !MV!, !MD!>
- # Place this in a Comments box to cause the event to produce a Sound Effect
- # when the player is near.
- # Replacements:
- # !SE! with the name of the file in Audio/BGS (without the extension)
- # !MV! with the loudest the sound is allowed to be (max 100)
- # !MD! with the maximum distance that the player can be and still hear the
- # sound (albeit faintly); this is also used to calculate how loud the
- # sound is at various distances
- #
- #===============================================================================
- # Aliases:
- #
- # These are the methods that are aliased by this script. This information is
- # included for the purpose of pinpointing compatibility errors between scripts.
- #
- # ***class Game_Event***
- #
- # conditions_met?(page)
- #
- #===============================================================================
- # Redefinitions:
- #
- # These are the methods that are redefined by this script. This information is
- # included for the purpose of pinpointing compatibility errors between scripts.
- #
- # ***class Game_Event***
- #
- # map_passable?(x, y, d)
- #
- # collide_with_events(x, y)
- #
- ################################################################################
- module SES
- module EnhancedEvents
- EventConditions = {
- # Key => "script to evaluate",
- # As long as $game_variables[1] isn't 5, the event page can run
- "Var1" => "$game_variables[1] != 5",
- # The event page can run only if $game_variables[1] equals 6
- "Var2" => "$game_variables[1] == 6",
- # The event page can only run if the party doesn't include actor 3
- "Act3" => "!$game_party.members.include?($game_actors[3])",
- # The event page can only run if $game_switches[1] is off
- "Swi1" => "!$game_switches[1]",
- # The event can only run if the lead party member is equipped with a Hand Axe
- "Equ1" => "$game_party.members[0].weapons.include?($data_weapons[1])",
- }
- # RegExp for an event page's extra conditions. You can include more than one.
- ExtraCondition = /^Condition:(?:\s*)([\w]+)/i
- # RegExp to cause an event page to block the movement of other events.
- EventBlock = /^(EventBlock|Event Block)/i
- # RegExp for an event page's movement type.
- MovementType = /^Movement:(?:\s*)(Boat|Ship|Fly)/i
- # RegExp for the SE that will play when the player is close to the event
- PlaySound = /^Sound:(?:\s*)(\w+),(?:\s*)(\d+),(?:\s*)(\d+)/i
- end
- end
- $imported = {} if $imported.nil?
- $imported["SES - EnhancedEvents"] = true
- class RPG::Event::Page
- alias en_ee_sc en_scan_comments
- def en_scan_comments(comments = [])
- @extraconditions = []
- @eventblock = false
- @movement = "Walking"
- @sound = []
- comments.push([SES::EnhancedEvents::ExtraCondition, "@extraconditions.push($1.to_s)"])
- comments.push([SES::EnhancedEvents::EventBlock, "@eventblock = true"])
- comments.push([SES::EnhancedEvents::MovementType, "@movement = $1.to_s"])
- comments.push([SES::EnhancedEvents::PlaySound, "@sound = [$1.to_s, $2.to_i, $3.to_i]"])
- en_ee_sc(comments)
- end
- [:extraconditions, :eventblock, :movement, :sound].each do |i|
- define_method(traits[i]) do
- en_scan_comments if eval("@#{traits[i]}.nil?")
- return eval("@#{traits[i]}")
- end
- end
- end
- class Game_Event < Game_Character
- attr_reader :page
- 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
- alias en_ee_ge_u update
- def update
- en_ee_ge_u
- if @sound.nil? && @page && !@page.sound.empty?
- @sound = RPG::BGS.new(@page.sound[0], volume(@page.sound[1], @page.sound[2]), 100)
- @sound.play
- end
- (@sound.volume = volume(@page.sound[1], @page.sound[2]); @sound.play) if @sound
- end
- def volume(max_vol, max_dist)
- if distance_from($game_player) > max_dist then 0
- else [max_vol,
- (max_vol / max_dist) * (max_dist+1 - distance_from($game_player))].min
- end
- end
- def distance_from(char)
- return distance_x_from(char.x).abs + distance_y_from(char.y).abs
- end
- def collide_with_events?(x, y)
- $game_map.events_xy_nt(x, y).any? do |event|
- return true if event.page.eventblock
- return false if event.through
- return event.priority_type == self.priority_type
- end
- end
- alias en_ee_ge_cm conditions_met?
- def conditions_met?(page)
- page.extraconditions.each do |i|
- return false unless eval(SES::EnhancedEvents::EventConditions[i])
- end
- en_ee_ge_cm(page)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment