The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: modern algebra on April 23, 2014, 11:40:55 AM

Title: [VXA] Event-Based Regions & Terrains
Post by: modern algebra on April 23, 2014, 11:40:55 AM
Event-Based Regions & Terrains
Version: 1.0.0
Author: modern algebra
Date: 2014 April 23

Version History



Description


This script allows you to assign a region ID and/or terrain tag to any event. When this is done, any tile upon which that event steps will inherit that region ID and/or terrain tag for as long as the event is present on it. If more than one event with this feature is on the same tile, then it will have the region ID or terrain tag which is highest.

Features


Instructions

Insert this script into the Script Editor (F11), below Materials but still above Main.

Script


Code: [Select]
#==============================================================================
#    Event-Based Regions & Terrains
#    Version: 1.0.0
#    Author: modern algebra (rmrk.net)
#    Date: 23 April 2014
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to assign a region ID and/or terrain tag to any
#   event. When this is done, any tile upon which that event steps will inherit
#   that region ID and/or terrain tag for as long as the event is present on
#   it. If more than one event with this feature is on the same tile, then it
#   will have the region ID or terrain tag which is highest.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Insert this script into its own slot in the Script Editor, below Materials
#   but still above Main.
#
#    In order to assign a region ID to an event, create a comment in the first
#   event command of the page and use the following code:
#
#      \region[x]
#
#   Replace x with any integer from 1-63.
#
#    In order to assign a terrain tag to an event, make a comment the first
#   event command of the page and use the following code:
#
#      \terrain[x]
#
#   Replace x with any integer from 0-7, or higher if using a script that
#   permits that.
#
#    The region ID and terrain tag will apply only for the page in which they
#   are created. Once a new page is active, they will revert.
#==============================================================================

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

#==============================================================================
# ** Game_Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased methods - terrain_tag; region_id
#    new method - get_event_region
#==============================================================================

class Game_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Terrain Tag
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maebr_terntag_7uj2 terrain_tag
  def terrain_tag(x, y, *args, &block)
    event_tt = maebr_event_var(x, y, :maebr_terrain_tag)
    return event_tt if event_tt > 0
    maebr_terntag_7uj2(x, y, *args, &block) # Call Original Method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Region ID
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maebr_reginid_5sr9 region_id
  def region_id(x, y, *args, &block)
    event_rid = maebr_event_var(x, y, :maebr_region_id)
    return event_rid if event_rid > 0
    maebr_reginid_5sr9(x, y, *args, &block) # Call Original Method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Get Event-Based Variable for Region ID or Terrain Tag
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maebr_event_var(x, y, var)
    ([0] + events_xy(x,y).collect { |event| event.send(var) }).max
  end
end

#==============================================================================
# ** Game_Event
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new public instance variables - maebr_region_id; maebr_terrain_tag
#    aliased methods - init_public_members; setup_page_settings;
#      clear_page_settings
#==============================================================================

class Game_Event
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor(:maebr_region_id, :maebr_terrain_tag)
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Initialize Public Members
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maebr_inizpublcmems_8bn3 init_public_members
  def init_public_members(*args, &block)
    maebr_inizpublcmems_8bn3(*args, &block) # Call Original Method
    @maebr_region_id = 0
    @maebr_terrain_tag = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Clear Event Page Settings
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maebr_clrpagesets_3vw4 clear_page_settings
  def clear_page_settings(*args, &block)
    maebr_clrpagesets_3vw4(*args, &block) # Call Original Method
    @maebr_region_id = 0
    @maebr_terrain_tag = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Up Event Page Settings
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maebr_setppagttings_4cu6 setup_page_settings
  def setup_page_settings(*args, &block) # Call Original Method
    maebr_setppagttings_4cu6(*args, &block)
    # Collect first Comment
    first_comment, i = "", 0
    while !@list[i].nil? && (@list[i].code == 108 || @list[i].code == 408)
      first_comment += @list[i].parameters[0] + "\n"
      i += 1
    end
    @maebr_region_id = first_comment[/\\REGION\s*\[\s*(\d+)\s*\]/im] ? $1.to_i : 0
    @maebr_terrain_tag = first_comment[/\\TERRAIN\s*\[\s*(\d+)\s*\]/im] ? $1.to_i : 0
  end
end

Credit



Thanks


Support


Please post in this topic at RMRK.net if you have any questions, suggestions, error reports, or comments about this script. It is perfectly fine to post here even if this topic has not been posted in for a very long time.

Please do not message me privately, as any concerns you have are likely shared by others and they will benefit from our correspondence being public. Additionally, I am occasionally absent, and posting publicly will allow other members to assist you when I am unable to do so quickly.

Known Compatibility Issues

I am currently unaware of any compatibility bugs, but if you are using this script with my Terrain Features (http://rmrk.net/index.php/topic,47620.0.html) script, then how it interacts with the terrain substitution feature depends on whether it is above or below it. If below it, then you should just set \terrain[] directly to the tag, even if it is > 7. If above it, you should set it to whatever tag is substituted for the tag you want.

Terms of Use


I adopt the Terms of Use for RMVXA Scripts Database (http://rmrk.net/index.php/topic,45481.0.html).
Title: Re: [VXA] Event-Based Regions & Terrains
Post by: Fizzly on April 23, 2014, 01:51:54 PM
Works like a charm, modern! You're the best. Definitely credit you. Thank you!

Edit: Btw I'm using so many other scripts and it still works!  :tpg:

Edit: Oookay, found a bug! Teleport doesn't works. I mean that build-in teleport command, screen just goes black and nothing happens. Could you please check this out?
Title: Re: [VXA] Event-Based Regions & Terrains
Post by: modern algebra on April 24, 2014, 03:31:46 AM
It works for me when I try it in a demo with just my script, so it might be an incompatibility. Can you try and recreate the issue in a new project and share that with me?
Title: Re: [VXA] Event-Based Regions & Terrains
Post by: Fizzly on April 24, 2014, 01:17:18 PM
Of course, I'll check this out when I'll return home and let you know. Thank you.

Edit: Yes, my bad. It is some scripts incompatibility, i'll try to find with which one. Thanks!
Title: Re: [VXA] Event-Based Regions & Terrains
Post by: modern algebra on May 01, 2014, 11:10:07 PM
Any luck?
Title: Re: [VXA] Event-Based Regions & Terrains
Post by: Fizzly on May 23, 2014, 10:30:09 PM
Sorry for the late reply, but didn't found which one causes problem - just removed a lot of them. But now it works! :)