The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on July 12, 2011, 11:28:14 PM

Title: Geomancy
Post by: modern algebra on July 12, 2011, 11:28:14 PM
Geomancy
Version: 1.0
Author: modern algebra
Date: July 12, 2011

Version History



Description


This script, used in conjunction with a terrain tags script, allows you to set it so that specified skills can only be used on particular types of terrain.

Features


Instructions

This script REQUIRES a script that restores the terrain tag feature to RMVX. It is designed for either my Terrain Types (http://rmrk.net/index.php/topic,34410.0.html) script or DerVVulfman's Tileset Reader (http://houseslashers.b1.jcink.com/index.php?showtopic=40) script, but may work with other scripts which restore the feature (so long as they have a method in Game_Map named "terrain_tag" that takes the x and y position as arguments and returns the tag for that square).

Paste this script below Materials and above Main. If you are using the Note Editor and want to be able to edit geomancy notes, then you need the Note Editor's General Compatibility Patch and this script must be below both in the script order.

For instructions on setting the terrains on which skills can be used, see the header of the script.

Script


Code: [Select]
#==============================================================================
#    Geomancy
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: July 12, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script, used in conjunction with a terrain tags script, allows you to
#   set it so that certain skills can only be used on particular types of
#   terrain.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    This script REQUIRES a terrain tag script (designed for my Terrain Types
#   1.0 and DerVVulfman's Tileset Reader, but most would likely work).
#
#    To set it so that a skill can only be used on particular terrain tags,
#   simply put the following code in the notebox of the skill:
#
#        \Terrains[x, y, ..., z]
#
#   where x, y, ..., z are the terrain tags you want to enable it for. If you
#   don't set this code at all, then the skill can be used on any non-excluded
#   terrains.
#
#    You can also do it backwards - if you want the skill to be usable on all
#   terrains EXCEPT specified terrains, then you use the following code:
#
#        \!Terrains[x, y, ..., z]
#
#   where x, y, ..., z are this time the tags you DON'T want to be able to use
#  the skill on.
#==============================================================================

#==============================================================================
# ** RPG::Skill
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - valid_terrain?
#==============================================================================

class RPG::Skill
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Valid Terrain?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def valid_terrain? (terrain_tag)
    if !@valid_terrains
      @valid_terrains, @invalid_terrains = [], []
      $1.gsub! (/\d+/) { |tag| @invalid_terrains.push (tag.to_i) } if self.note[/\\!TERRAINS\[(.+?)\]/i]
      $1.gsub! (/\d+/) { |tag| @valid_terrains.push (tag.to_i) } if self.note[/\\TERRAINS\[(.+?)\]/i]
    end
    return (!@invalid_terrains.include? (terrain_tag)) && (@valid_terrains.empty? || @valid_terrains.include? (terrain_tag))
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Note Editor Compatibility - Reset Note
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  if self.method_defined? (:ma_reset_note_values)
    alias maga_geom_rst_note_6yc1 ma_reset_note_values
    def ma_reset_note_values (*args, &block)
      maga_geom_rst_note_6yc1 (*args, &block) # Run Original Method
      @valid_terrains, @invalid_terrains = nil, nil
    end
  end
end

#==============================================================================
# ** Game_Battler
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - skill_can_use?
#==============================================================================

class Game_Battler
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Skill Available?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mab_kf_geomancy_canuse_8hf9 skill_can_use?
  def skill_can_use? (skill, *args, &block)
    return false if skill.nil?
    if Game_Player.method_defined? (:ma_terrain_tag) # My Terrain Types
      return false unless skill.valid_terrain? ($game_player.ma_terrain_tag)
    elsif Game_Map.method_defined? (:terrain_tag)    # Dervvulfman's Tileset Reader
      x, y = $game_player.x, $game_player.y
      return false unless skill.valid_terrain? ($game_map.terrain_tag (x, y))
    end
    return mab_kf_geomancy_canuse_8hf9 (skill, *args, &block) # Run Original Method
  end
end

Credit



Thanks


Support


Please post in this topic at RMRK for support, no matter how old the topic is.

Known Compatibility Issues

This script is designed to work with my Terrain Tags (http://rmrk.net/index.php/topic,34410.0.html) script and DerVVulfman's Tileset Reader (http://houseslashers.b1.jcink.com/index.php?showtopic=40). It will likely work with other scripts that reintroduce the terrain tag feature as well.
Title: Re: Geomancy
Post by: exhydra on July 13, 2011, 12:18:34 AM
Looks all snazzy! I didn't realize '&block' was so neat ...
Title: Re: Geomancy
Post by: cozziekuns on July 13, 2011, 01:43:02 AM
You always manage to make your scripts look so purdy and efficient somehow. Good job, Modern!
Title: Re: Geomancy
Post by: modern algebra on July 13, 2011, 02:48:56 AM
&block was unnecessary in this script; it'd be pretty weird for someone to modify that method to expect a block. I get pretty paranoid though :P

@cozzie - If that's the case, it's probably because I haven't written a complicated script for like a decade and I have to do something to occupy my time :P
Title: Re: Geomancy
Post by: Adon on July 14, 2011, 01:59:14 PM
Not compatible with BEM's Snapshot Battleback, it "is" but it kind of "overrides" it.
Title: Re: Geomancy
Post by: pacdiggity on July 14, 2011, 03:23:26 PM
That's weird. Make sure Geomancy is below Battleback. This script only makes one new method and aliases another, so it should be compatible.
What exactly is wrong with the script processing?
Title: Re: Geomancy
Post by: Adon on July 14, 2011, 05:42:40 PM
@Pacman
No errors or anything, it just makes the BEM snapshot battle back script worthless. It doesn't even do anything.
 EDIT:
Ohh sorry! MA's Terrain script isn't compatible with YEM, or does above.
Title: Re: Geomancy
Post by: Infinate X on July 19, 2011, 06:41:16 PM
If your using the whole YEM engine then I see why it's uncompatable but if you try to figure out which scripts you need and which ones don't work then it will work. When I use YERD script I just take the ones I need and I leave the rest.

MA, this script is awesome as the rest of your scripts are, I just want to know if it's by the tile the battle starts on or if it's every tile on the map?
Title: Re: Geomancy
Post by: modern algebra on July 19, 2011, 07:27:03 PM
By the tile the battle starts on.
Title: Re: Geomancy
Post by: Zodiac on December 04, 2012, 09:40:04 PM
I actually have a question about this script, as it looks pretty cool and it's something I wouldn't mind using.  Is there any way to make a single skilled named Geomancy, and have it use the other skills depending on what terrain you're on? Like, I use the skill "Geomancy" on a road, and it uses an earth-based move, but if I'm in water, I use that same "Geomancy" Skill, and it uses a water-based move.  I was curious if that was possible instead of just graying out skills when they couldn't be used
Title: Re: Geomancy
Post by: modern algebra on December 04, 2012, 11:49:01 PM
Not currently, no.
Title: Re: Geomancy
Post by: Zodiac on December 05, 2012, 01:13:21 AM
Alright, thank you!