The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: modern algebra on October 10, 2012, 01:53:31 AM

Title: [VXA] Map Transfer Common Events
Post by: modern algebra on October 10, 2012, 01:53:31 AM
Map Transfer Common Events
Version: 1.0.0
Author: modern algebra
Date: 9 October 2012

Version History



Description


This script lets you instantly run a specified common event when exiting or entering a map. This is useful, for instance, for when you want to instantly change the tone when transferring to a different map, or really for any other change that you want to take place instantly. The event will only be run once.

Features


Instructions

Paste the script into its own slot in the Script Editor, above Main but below Materials.

For configuration instructions, see the header of the script. Please note, however, that this ignores any switch condition on the common event, so it should not be used to call parallel process or autorun common events directly. Also, the player will not be able to move while the event is running, so you should not put many wait frames in the event. If you need wait frames, then the recommended option would be to make a parallel process event or common event, and if necessary you can turn on the switch with a common event called by this script.

Script


Code: [Select]
#==============================================================================
#    Map Transfer Common Event
#    Version: 1.0.0
#    Author: modern algebra (rmrk.net)
#    Date: 9 October 2012
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#   
#    This script lets you instantly run a specified common event when exiting
#   or entering a map. This is useful, for instance, for when you want to
#   instantly change the tone when transferring to a different map, or really
#   for any other change that you want to take place instantly. The event will
#   only be run once.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#   
#    Paste this script into its own slot in the Script Editor, above Main but
#   below Materials.
#
#    All you need to do to set this script up is place one or both of the
#   following codes into the note box of a map:
#
#      \EXIT_CE[0]
#      \ENTER_CE[0]
#
#    Obviously, the EXIT_CE will run when leaving the map, while the ENTER_CE
#   will run when entering the map. Replace the 0 with the ID of the common
#   event which you want to run in that circumstance.
#
#    Please note that this ignores any switch condition on the common event, so
#   it should not be used to call parallel process or autorun common events
#   directly. Also, the player will not be able to move while the event is
#   running, so you should not put many wait frames in the event. If you need
#   wait frames, then the recommended option would be to make a parallel
#   process event or common event, and if necessary you can turn on the switch
#   with a common event called by this script.
#==============================================================================

$imported = {} unless $imported
$imported[:MA_MapTransferCommonEvent] = true

#==============================================================================
# ** Game_Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - setup
#==============================================================================

class Game_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Setup
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mamtce_setup_9qg8 setup
  def setup(map_id, *args)
    if @map_id != map_id
      old_ce_id = $game_temp.common_event_id
      mamtce_run_instant_common_event(mamtce_out_common_event_id)
      mamtce_setup_9qg8(map_id, *args) # Call original method
      mamtce_run_instant_common_event(mamtce_in_common_event_id)
      $game_temp.reserve_common_event(old_ce_id) if old_ce_id > 0
    else
      mamtce_setup_9qg8(map_id, *args) # Call original method
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Transfer Common Event IDs
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def mamtce_in_common_event_id
    @map ? @map.note[/(?<=\\ENTER[_ ]CE\[)\s*\d+\s*(?=\])/i].to_i : 0
  end
  def mamtce_out_common_event_id
    @map ? @map.note[/(?<=\\EXIT[_ ]CE\[)\s*\d+\s*(?=\])/i].to_i : 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Instant Run Common Event
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def mamtce_run_instant_common_event(ce_id)
    return unless ce_id > 0
    $game_temp.reserve_common_event(ce_id)
    @interpreter.setup_reserved_common_event
    @interpreter.update
  end
end

Credit



Support


Please post in this topic at RMRK.net if you have any questions, suggestions, error reports, or comments about this script. Please do not message me privately, as it is more efficient and useful to answer any concerns you have in the topic where others may benefit from our correspondence.

Known Compatibility Issues

I do not know of any compatibility problems as of yet.

Terms of Use


I adopt RMRK's default Terms of Use (http://rmrk.net/index.php/topic,45481.0.html).
Title: Re: Map Transfer Common Events
Post by: Dark_falcao on October 10, 2012, 05:32:07 PM
Very useful script, I often make a script call on my game to change screen tone at the next map, I tried to call a common event too but I fail, the common event always started when the tranfer was completely done
Title: Re: Map Transfer Common Events
Post by: exhydra on October 10, 2012, 05:57:59 PM
Hooray! In the past I have tried to finagle something like this, as some of my maps shifted radically in terms of screen tone and appearance. Excellent script.
Title: Re: Map Transfer Common Events
Post by: modern algebra on October 10, 2012, 09:35:21 PM
I am glad you both like it! I don't know why I didn't write it earlier; I remember having that problem back when I was making games, always having to have a parallel process event in each map to initialize anything for the map and then delete itself. It wasn't a particularly daunting task, but it was easy to forget to do it, and for some repetetive things like changing the tone when exiting and entering indoor areas, it can be helpful to just have a single common event to call.