The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on March 13, 2008, 02:06:35 AM

Title: Advanced Areas
Post by: modern algebra on March 13, 2008, 02:06:35 AM
Advanced Areas
Version: 1.5
Author: modern algebra
Date: September 26, 2008

Version History



Description


Adds a couple of options to areas. If anyone has any ideas for more, please tell me.

Features


Screenshots

N/A

Instructions

See inside the script

Script


Code: [Select]
#==============================================================================
#  Advanced Areas
#  Version 1.5
#  Author: modern algebra (rmrk.net)
#  Date: September 26, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Instructions:
#    Set up the database below in the Editable Regions. Both are set up in the
#   same way, and they look like this:
#
#      when id
#        rate/switch = value
#
#    You only need to set it if it is not default. If an area has no switch,
#   then don't set it up. If you want the encounter step to be the same as
#   the parent map, then do not set it up. In any case, just so we are clear,
#   I provided a few examples in the Editable Regions. Feel free to
#   replace/delete them once you know what you're doing.
#
#    To restrict events so that they cannot move outside of a given area or
#   areas, then all you need to do is place a comment on the first line of any
#   page of the event you want to restrict, and in that comment put this:
#   \AREA[area id]. If you want him to be able to move freely in more than one
#   area, then you can put as many of those codes there as there are areas he
#   can move in. Thus, if an event had this in his comment:
#
#       \Area[1]\AreA[5]\AREA[9]
#
#     Then that event would have free passage in the Areas 1, 5, and 9, but
#   would not be able to move outside of them.
#==============================================================================

#==============================================================================
# ** RPG::Area
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of changes:
#    new methods - encounter_step, active?
#==============================================================================

class RPG::Area
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Encounter Rate
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def encounter_step
    rate = $game_map.encounter_step
    # Branch by ID
    case @id
    #----------------------------------------------------------------------
    #  EDITABLE REGION
    #----------------------------------------------------------------------
    when 1
      rate = 10
    when 3
      rate = 15
    #----------------------------------------------------------------------
    #  END EDITABLE REGION
    #----------------------------------------------------------------------
    end
    return rate
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Active?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def active?
    switch = 0
    case @id
    #----------------------------------------------------------------------
    #  EDITABLE REGION                                                    
    #----------------------------------------------------------------------
    when 1
      switch = 1
    when 4
      switch = 1
    #----------------------------------------------------------------------
    #  END EDITABLE REGION
    #----------------------------------------------------------------------
    end
    return true if switch == 0
    return $game_switches[switch]
  end
end

#==============================================================================
# ** Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased method - encounter_step
#==============================================================================

class Game_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Encounter Step
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_advncd_areas_step_encntr encounter_step
  def encounter_step
    # Get original Map Encounter Step
    encounter_rates = [modalg_advncd_areas_step_encntr]
    # Get all the areas the player is in. For ne
    $data_areas.values.each { |i| encounter_rates.push (i.encounter_step) if i.map_id == @map && $game_player.in_area? (i) }
    return encounter_rates.min
  end
end

#==============================================================================
# ** Game_Player
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased methods - in_area?
#==============================================================================

class Game_Player
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * In Area?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_advnced_areas_area_in? in_area?
  def in_area? (area)
    return false unless area.active?
    modalg_advnced_areas_area_in? (area)
  end
end

==============================================================================
# ** Game_Event
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased methods - setup, passable?
#    new method - in_area?
#==============================================================================

class Game_Event < Game_Character
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Event page setup
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_stp_advarea_contain_nfg5 setup
  def setup(new_page)
    @areas.nil? ? @areas = [] : @areas.clear
    # If new page is real
    if new_page != nil
      first_command = new_page.list[0].dup
      # If first line is a comment
      if first_command.code == 108
        loop do
          slice = first_command.parameters[0].slice! (/\\AREA\[(\d+)\]/i) { "" }
          slice == nil ? break : @areas.push ($1.to_i)
        end
      end
    end
    modalg_stp_advarea_contain_nfg5 (new_page)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Determine if Passable
  #     x : x-coordinate
  #     y : y-coordinate
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_contain_areas_adv_pass_hfe passable?
  def passable?(x, y)
    return modalg_contain_areas_adv_pass_hfe (x, y) if @areas == nil || @areas.empty?
    in_area = false
    @areas.each { |i|
      # If within one of the areas, it is passable
      in_area = in_area? ($data_areas[i], x, y)
      break if in_area
    }
    return in_area && modalg_contain_areas_adv_pass_hfe (x, y)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Determine if in Area (Transferred from Game_Player
  #     area : Area data (RPG::Area)
  #     x : x-coordinate
  #     y : y-coordinate
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def in_area?(area, x, y)
    return false if area == nil
    return false unless area.active?
    return false if $game_map.map_id != area.map_id
    return false if x < area.rect.x
    return false if y < area.rect.y
    return false if x >= area.rect.x + area.rect.width
    return false if y >= area.rect.y + area.rect.height
    return true
  end
end

Credit



Thanks


Support


Just post here if you have any errors. I will try to fix them. If you have any ideas about good options to add to the areas, please post here and if I think they are good I will write them in.

Known Compatibility Issues

No known compatibility issues.


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
Title: Re: Advanced Areas
Post by: worale on March 13, 2008, 05:18:40 PM
Nice Script :)

and pretty neat, too.

This will be really useful for game that has some situation happens in game and change enemy~
Title: Re: Advanced Areas
Post by: Restaurant Sackboy on March 15, 2008, 02:22:18 PM
Kind of like World of Warcraft; Threat.
The higher your level, the lower levels won't attack you but higher levels will.
It has differences though...
Title: Re: Advanced Areas
Post by: :) on March 15, 2008, 04:12:46 PM
Modern, you rock!
Title: Re: Advanced Areas
Post by: modern algebra on March 15, 2008, 06:11:41 PM
Kind of like World of Warcraft; Threat.
The higher your level, the lower levels won't attack you but higher levels will.
It has differences though...

That actually sounds more like this script: http://rmrk.net/index.php/topic,24610.0.html

The two are compatible.


Nice Script :)

and pretty neat, too.

This will be really useful for game that has some situation happens in game and change enemy~
Modern, you rock!

Thanks :)
Title: Re: Advanced Areas
Post by: Leventhan on March 16, 2008, 01:36:34 PM
+rep
Title: Re: Advanced Areas
Post by: GasparXR on March 17, 2008, 10:24:38 PM
Oo This will be extremely useful. Do you sit at the computer and endlessly script? XD
Title: Re: Advanced Areas
Post by: modern algebra on September 26, 2008, 02:49:45 PM
Updated to Version 1.5

You can now contain randomly moving events to an area or group of areas.
Title: Re: Advanced Areas
Post by: brutebasher9 on December 09, 2008, 10:34:33 PM
Hello, still in the pocess of trying to understand how this script works. I mean what is the use of rate/switch = #? I thought it was for when you stepped inside an area, to turn the switch on. It brings me to my second question, is there any way to update the script to turn a specific switch on when you step inside that area, and/or off when you leave?
Title: Re: Advanced Areas
Post by: modern algebra on December 10, 2008, 02:57:25 AM
rate is the encounter rate within that area.

switch is the switch that turns on that area. For instance, if you wanted to have a volcano erupt in your game and then have special monsters appear in that vicinity only, you would need to make a new map. With this, you can have the area be ther all along and just not active, then once the volcano erupts you can turn the switch on and the area will be made active.

As for turning a switch on when you enter an area, yes that is possible, but not currently with this script. I could make it if you like, but I'd like to know the reason why you would want such a feature.
Title: Re: Advanced Areas
Post by: brutebasher9 on December 10, 2008, 04:02:53 AM
Edit: Request removed. Thanks Modern, even silence teaches a lesson.
Title: Re: Advanced Areas
Post by: modern algebra on December 18, 2008, 11:08:17 PM
eh? I'm just seeing this topic now. What did you ask for?
Title: Re: Advanced Areas
Post by: brutebasher9 on December 19, 2008, 05:49:11 AM
Erm..To put the request in a nutshell, it was the possible feature of setting a switch on or off, mainly on, depending on if an event is inside an area ID or not. If  you'd like, I could send you a demo of what I'd like to use it for.

Thanks for your time and patience, Modern.  :)
Title: Re: Advanced Areas
Post by: modern algebra on December 19, 2008, 02:31:32 PM
Oh right. I think I remember reading that, but I forgot. Yeah, it's possible, but I should warn you that I have to use other computers for internet right now, so I won't be able to upload any work I do until after Christmas. It might be an idea to do this through events.

$game_player.in_area? ($data_areas[<area ID>]) is the code for checking if the player is in an area I believe.

If you did a parallel process on the maps where you needed it, you could save which area you are in currently with a variable and have an event that looks like this:

Code: [Select]
Conditional Branch: $game_player.in_area? ($data_areas[$game_variables[x]])
Else
  # Check All other Areas like so:
  Conditional Branch: $game_player.in_area? ($data_areas[y])
    Change BGM
    Variable[x] = y
  Branch END
  # ANd so on for all areas on the map
Branch END
Wait: 2 frames
Title: Re: Advanced Areas
Post by: brutebasher9 on December 29, 2008, 03:42:29 AM
Hey, sorry for the long wait with replies. I've seen this and tried it before, on the 20th and got thes ame error as before. For some reason, when I enabled the check for areas (when in or out of one, to enable the parallel process to check) it resulted in an error in the script. The error message showed the following in bold:

Script 'Advanced Areas' line 113: NoMethodError occured.

undefined method 'active?' for nil:NilClass


Thanks again for your time and patience, Modern Algebra.