Main Menu
  • Welcome to The RPG Maker Resource Kit.

[Self-Resolved] Magey Mage Spellbook

Started by themrmystery, March 02, 2009, 02:46:32 PM

0 Members and 1 Guest are viewing this topic.

themrmystery

I'm attempting to re-do DerVVulfman's Spellbook System:

Reasons, the script currently relies on Hit Rate and Variance to teach/require/remove skills.  This limits you to having all your spells in the 1-100 range.  I unfortunately have all my melee/character skills from 1-100 and have over 175 spells in slots 151-325... This makes this script pretty much useless to me.

However, I'm going to attempt to remake it into a "hash/array" or something style any suggestions on other methods that would allow me to use this script to it's full potential without the limit of 1-100 hit rate/variance.. let me know!

#==============================================================================
# ** The Magey Mage's Spellbook System
#------------------------------------------------------------------------------
#    by DerVVulfman
#    version 1.0
#    10-20-2008
#    RGSS / RPGMaker XP
#==============================================================================
#
#  INTRODUCTION:
#
#  This system permits you to create items within your RPGMaker database that
#  can bestow a single 'skill' to one or more partymembers.  This feature was
#  available in earlier RPGMaker™ systems, now re-introduced.
#
#      >>>   The instructions are longer than the actual code. ^_-   <<<
#
#
#------------------------------------------------------------------------------
#
#  USAGE:
#
#  --Spellbook Elements--
#  This system requires you to create additional elements within the 'SYSTEM'
#  database in your  RPGMaker Design system.   If you don't know what I mean,
#  an element is something like 'Fire, Ice, Thunder, vs Poison' and the like.
#
#  You may specify only one 'element' or multiple elements.  The quantity is
#  really up to you, but the elements must be consecutive in your list.   No
#  breaking up or spreading them about in the database.   That means you can
#  have them ordered like (18-Spellbook1, 19-Spellbook2, 20-Spellbook3), but
#  not like (18-Spellbook1, 23-Spellbook2, 30-Spellbook3).   It is important
#  to keep them organized for the configuration section.
#
#  You can name the elements anything you want, but it's understandable that
#  they have descriptive names like 'scrolls', 'white magic',  'black magic'
#  and the like.

#  Now after creating the elements, go ahead and edit the configuration sec-
#  tion of this script to accommodate the Spellbook Elements. As I mentioned
#  earlier, the elements had to be consecutive... and not broken up. Now you
#  will see why.
#
#  The first configurable (SPBOOK_ID_START) is to be set to the ID number of
#  your first Spellbook element. If the first element is 23, then please set
#  this value to 23.  The second configurable (SPBOOK_ID_NUMBER) informs the
#  system how many Spellbook elements you have. If you crafted four elements
#  for your project, enter 4.   With this example...  with a first Spellbook
#  element being 23, your last Spellbook element would be #26  in your data-
#  base.
#
#
#  --Class Limitations--
#  Not every class can use these items, right?  ^_^  Heh, I didn't think so.
#
#  The third  and final configurable  in this script  is the  SPBOOK_CLASSES
#  value.  This is a hash array that holds the ID values of classes that can
#  use Skill-bestowing items,  and the matching 'Spellbook Elements' they are
#  permitted to use.
#
#  The format for editing this array is like this:
#
#  SPBOOK_CLASSES    = { class_id => [ element_id, element_id, ... ],
#                        class_id => [ element_id, element_id, ... ], ... }
#
#  As such, each class can have one or more Spellbook Elements from which it
#  may learn from,  and you can have multiple classes that can utilize these
#  items.  Or... you could just set up one class that only has one element.
#
#
#  --Items--
#  After creating your Spellbook Elements  and configured which class(s) can
#  utilize the Skill-Bestowing items... it's time to set up your items.
#
#  Within the ITEM database of your RPGMaker system,  create or edit an item
#  and then click on (or tag) the Spellbook element(s) that identifies it. A
#  Skill-Bestowing Item MAY have more than one Spellbook Element with it.
#
#  After that, now is the time to set the 'skill' which this item will teach
#  to the player character(s).   Within the same ITEM,  go down and find the
#  'Variance' field (at the bottom of the screen).  By default, a newly made
#  item has a '0'(zero) variance.   Set the Variance to the  ID value of the
#  skill you wish the item to teach.   If you set the value to 33,  then the
#  item will teach the 33rd skill (Venom).  And if you set it to 7, the item
#  will teach the 7th skill (Fireball). Values below '1' and above the total
#  number of skills in the database are ignored to prevent errors.
#
#  --Items (optional features)--
#  As an optional feature,  the system  can require you  to have a currently
#  learned skill  for a new skill to be imposed.   By setting the 'Hit Rate'
#  field in the ITEM database to a value other than 0, you inform the system
#  that the 'Skill-Bestowing' item requires the character(s) to have a skill
#  already learned.  As expected, this value matches the ID value of a skill
#  in your database.  So, if the hit rate value is set to 62, then skill #62
#  (typically 'Beast Slayer') will be needed to learn the new skill.

#  Not only that... but as a bonus, this system will remove the old skill in
#  favor of the newer one if the 'pdef-f'  value of the item has been set to
#  value of '1' or more.   If set to '0',  the skill is just learned, but if
#  set to a value  greater than '0',  the old skill is lost  and the new one
#  remains.
#
#  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
#  Be warned:  Unless you are using these optional features, remember to set
#  your 'Hit Rate' value to '0' (zero).
#
#
#------------------------------------------------------------------------------
#
#  SCRIPT PLACEMENT:
#
#  The basic function of this system is to bypass any other 'item effect' and
#  to teach a skill.   Unlike other scripts that edit the item_effect method,
#  it does not change  values or affect any other outcome  with the exception
#  of learned skills.  As such, it would be best to place it BELOW any script
#  that alters or changes the item_effect method.
#
#
#------------------------------------------------------------------------------
#
#  EDITS AND MODIFICATIONS:

#  This system Aliases the following methods:
#  * item_effect                     (Game_Battler)
#
#
#------------------------------------------------------------------------------
#
#  THANKS:
#
#  To Jaide for identifying a missing feature that was in earlier RPGMaker™
#  systems.
#
#
#------------------------------------------------------------------------------
#  TERMS AND CONDITIONS:
#
#  Free to use, even in commercial projects.  Just note that I need some form
#  of due credit... even a mere mention in some end titles.
#
#
#==============================================================================

  # Spellbook Elements
  SPBOOK_ID_START   = 24  # Start of element list
  SPBOOK_ID_NUMBER  = 11   # Number of elements
 
  # Class Limitations
  SPBOOK_CLASSES    = {
  3 => [24],
  6 => [25],
  5 => [26],
  7 => [27],
  11 => [28],
  9 => [29],
  8 => [29],
  13 => [30],
  14 => [31],
  15 => [32],
  16 => [33],
  23 => [34]
  }


#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass for the Game_Actor
#  and Game_Enemy classes.
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # * Application of Item Effects
  #     item : item
  #--------------------------------------------------------------------------
  alias spbook_effect item_effect
  def item_effect(item)
    # If item scope is for non-enemy ranges with a matching SPELLBOOK tag
    # This includes allies with or without 0 hp, all allies and user tags.
    if item.scope > 2
      # Variance value check (must be from 1 to item value max).
      if item.variance > 0 && item.variance < $data_skills.size
        # Sort through item element ranges (spellbook item check)
        for sb_range in SPBOOK_ID_START..(SPBOOK_ID_START + SPBOOK_ID_NUMBER-1)
          # If the item has a specified spellbook element
          if item.element_set.include?(sb_range)
            # Confirmed that it's a spellbook item, but...
            # If no pre-defined 'required' skill is set
            unless item.hit == 0
              # Exit out if 'required' skill wasn't learned.
              return false unless self.skills.include?(item.hit)
            end
            # Set/reset the target's spellbook array
            sb_class = []
            # Obtain spellbooks available for target class (if any)
            sb_class = SPBOOK_CLASSES[self.class_id] if SPBOOK_CLASSES.include?(self.class_id)
            # If matching spellbook for class
            if sb_class.include?(sb_range)     
              unless item.hit == 0
                self.forget_skill(item.hit) if self.skills.include?(item.hit) && item.pdef_f > 0
              end             
              # Target learns skill
              self.learn_skill(item.variance)
              # Set to effective flag
              effective = true
            end
            return effective
          end
        end
      end
    end
    # Perform the original call
    spbook_effect(item)
  end
end

themrmystery

Modified Code: Allows for 9999 skills/item spell books.  Simply changed the check from variance to recover hp, and hit rate to recover sp.  Tested and works.

#==============================================================================
# ** The Magey Mage's Spellbook System
#------------------------------------------------------------------------------
#    by DerVVulfman
#    version 1.0
#    10-20-2008
#    RGSS / RPGMaker XP
#    Modified by: TheMrMystery
#    03-02-2009
#==============================================================================
#
#  INTRODUCTION:
#
#  This system permits you to create items within your RPGMaker database that
#  can bestow a single 'skill' to one or more partymembers.  This feature was
#  available in earlier RPGMaker™ systems, now re-introduced.
#
#      >>>   The instructions are longer than the actual code. ^_-   <<<
#
#
#  MODIFICATIONS (TheMrMystery):

#  Changed the elements in the item from variance to recover hp, and from hit
#  rate to recover sp, this will allow you to use up to 9999 skills instead of
#  only 100.
#------------------------------------------------------------------------------
#
#  USAGE:
#
#  --Spellbook Elements--
#  This system requires you to create additional elements within the 'SYSTEM'
#  database in your  RPGMaker Design system.   If you don't know what I mean,
#  an element is something like 'Fire, Ice, Thunder, vs Poison' and the like.
#
#  You may specify only one 'element' or multiple elements.  The quantity is
#  really up to you, but the elements must be consecutive in your list.   No
#  breaking up or spreading them about in the database.   That means you can
#  have them ordered like (18-Spellbook1, 19-Spellbook2, 20-Spellbook3), but
#  not like (18-Spellbook1, 23-Spellbook2, 30-Spellbook3).   It is important
#  to keep them organized for the configuration section.
#
#  You can name the elements anything you want, but it's understandable that
#  they have descriptive names like 'scrolls', 'white magic',  'black magic'
#  and the like.

#  Now after creating the elements, go ahead and edit the configuration sec-
#  tion of this script to accommodate the Spellbook Elements. As I mentioned
#  earlier, the elements had to be consecutive... and not broken up. Now you
#  will see why.
#
#  The first configurable (SPBOOK_ID_START) is to be set to the ID number of
#  your first Spellbook element. If the first element is 23, then please set
#  this value to 23.  The second configurable (SPBOOK_ID_NUMBER) informs the
#  system how many Spellbook elements you have. If you crafted four elements
#  for your project, enter 4.   With this example...  with a first Spellbook
#  element being 23, your last Spellbook element would be #26  in your data-
#  base.
#
#
#  --Class Limitations--
#  Not every class can use these items, right?  ^_^  Heh, I didn't think so.
#
#  The third  and final configurable  in this script  is the  SPBOOK_CLASSES
#  value.  This is a hash array that holds the ID values of classes that can
#  use Skill-bestowing items,  and the matching 'Spellbook Elements' they are
#  permitted to use.
#
#  The format for editing this array is like this:
#
#  SPBOOK_CLASSES    = { class_id => [ element_id, element_id, ... ],
#                        class_id => [ element_id, element_id, ... ], ... }
#
#  As such, each class can have one or more Spellbook Elements from which it
#  may learn from,  and you can have multiple classes that can utilize these
#  items.  Or... you could just set up one class that only has one element.
#
#
#  --Items--
#  After creating your Spellbook Elements  and configured which class(s) can
#  utilize the Skill-Bestowing items... it's time to set up your items.
#
#  Within the ITEM database of your RPGMaker system,  create or edit an item
#  and then click on (or tag) the Spellbook element(s) that identifies it. A
#  Skill-Bestowing Item MAY have more than one Spellbook Element with it.
#
#  After that, now is the time to set the 'skill' which this item will teach
#  to the player character(s).   Within the same ITEM,  go down and find the
#  'Rcvr HP' field (at the middle of the screen).  By default, a newly made
#  item has a '0'(zero) recover hp.   Set the Rcvr HP to the  ID value of the
#  skill you wish the item to teach.   If you set the value to 33,  then the
#  item will teach the 33rd skill (Venom).  And if you set it to 7, the item
#  will teach the 7th skill (Fireball). Values below '1' and above the total
#  number of skills in the database are ignored to prevent errors.
#
#  --Items (optional features)--
#  As an optional feature,  the system  can require you  to have a currently
#  learned skill  for a new skill to be imposed.   By setting the 'Rcvr SP'
#  field in the ITEM database to a value other than 0, you inform the system
#  that the 'Skill-Bestowing' item requires the character(s) to have a skill
#  already learned.  As expected, this value matches the ID value of a skill
#  in your database.  So, if the recover sp value is set to 62, then skill #62
#  (typically 'Beast Slayer') will be needed to learn the new skill.

#  Not only that... but as a bonus, this system will remove the old skill in
#  favor of the newer one if the 'pdef-f'  value of the item has been set to
#  value of '1' or more.   If set to '0',  the skill is just learned, but if
#  set to a value  greater than '0',  the old skill is lost  and the new one
#  remains.
#
#------------------------------------------------------------------------------
#
#  SCRIPT PLACEMENT:
#
#  The basic function of this system is to bypass any other 'item effect' and
#  to teach a skill.   Unlike other scripts that edit the item_effect method,
#  it does not change  values or affect any other outcome  with the exception
#  of learned skills.  As such, it would be best to place it BELOW any script
#  that alters or changes the item_effect method.
#
#
#------------------------------------------------------------------------------
#
#  EDITS AND MODIFICATIONS:

#  This system Aliases the following methods:
#  * item_effect                     (Game_Battler)
#
#
#------------------------------------------------------------------------------
#
#  THANKS:
#
#  To Jaide for identifying a missing feature that was in earlier RPGMaker™
#  systems.
#
#
#------------------------------------------------------------------------------
#  TERMS AND CONDITIONS:
#
#  Free to use, even in commercial projects.  Just note that I need some form
#  of due credit... even a mere mention in some end titles.
#
#
#==============================================================================

  # Spellbook Elements
  SPBOOK_ID_START   = 24  # Start of element list
  SPBOOK_ID_NUMBER  = 11   # Number of elements
 
  # Class Limitations
  SPBOOK_CLASSES    = {
  3 => [24],
  6 => [25],
  5 => [26],
  7 => [27],
  11 => [28],
  9 => [29],
  8 => [29],
  13 => [30],
  14 => [31],
  15 => [32],
  16 => [33],
  23 => [34]
  }


#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass for the Game_Actor
#  and Game_Enemy classes.
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # * Application of Item Effects
  #     item : item
  #--------------------------------------------------------------------------
  alias spbook_effect item_effect
  def item_effect(item)
    # If item scope is for non-enemy ranges with a matching SPELLBOOK tag
    # This includes allies with or without 0 hp, all allies and user tags.
    if item.scope > 2
      # Variance value check (must be from 1 to item value max).
      if item.recover_hp > 0 && item.recover_hp < $data_skills.size
        # Sort through item element ranges (spellbook item check)
        for sb_range in SPBOOK_ID_START..(SPBOOK_ID_START + SPBOOK_ID_NUMBER-1)
          # If the item has a specified spellbook element
          if item.element_set.include?(sb_range)
            # Confirmed that it's a spellbook item, but...
            # If no pre-defined 'required' skill is set
            unless item.recover_sp == 0
              # Exit out if 'required' skill wasn't learned.
              return false unless self.skills.include?(item.recover_sp)
            end
            # Set/reset the target's spellbook array
            sb_class = []
            # Obtain spellbooks available for target class (if any)
            sb_class = SPBOOK_CLASSES[self.class_id] if SPBOOK_CLASSES.include?(self.class_id)
            # If matching spellbook for class
            if sb_class.include?(sb_range)     
              unless item.recover_sp == 0
                self.forget_skill(item.recover_sp) if self.skills.include?(item.recover_sp) && item.pdef_f > 0
              end             
              # Target learns skill
              self.learn_skill(item.recover_hp)
              # Set to effective flag
              effective = true
            end
            return effective
          end
        end
      end
    end
    # Perform the original call
    spbook_effect(item)
  end
end

Grafikal

Are ya done? or are you going to add some more cool stuff? Cause if you're done, you should post a new topic for it and explain all your edits and stuff. Good work on this :)