The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: modern algebra on January 28, 2008, 03:19:56 AM

Title: Skill Teaching Equipment & Items (XP Edition)
Post by: modern algebra on January 28, 2008, 03:19:56 AM
Skill Teaching Equipment & Items
Version: 1.1
Author: modern algebra
Date: February 9, 2008


Version History



Description


This script allows you to assign skills to items, weapons and armors. When assigned to an item, it is possible to permanently learn the skill assigned when the item is used. For weapons and armors, you are able to learn the skill while the weapon or armor is equipped. Once the weapon or armor is unequipped, you will no longer have access to that skill.

Features


Screenshots

N/A for this type of script

Instructions

See inside the header for instructions

Script


Code: [Select]
#==============================================================================
#  Skill Teaching Equipment & Items
#  Version 1.0
#  Author: modern algebra (rmrk.net)
#  Date: January 27, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Instructions:
#     Insert this script just above Main. To configure your database, see the
#     Configuration Section at lines 29, 66, and 97 (by default; once you've
#     configured some of the data, this will change)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ** RPG
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Adds an additional stat, skill_id, to weapons, armors, and items
#==============================================================================

module RPG
#==============================================================================
# ** Item
#==============================================================================

class Item
  #
  attr_sec_reader :skill_id, 'get_stats (0)'
  attr_sec_reader :class_limits, 'get_stats (1)'
  attr_sec_reader :actor_limits, 'get_stats (2)'
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Stats
  #    parameter : 0 => skill ID, 1 => classes, 2 => actors
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def get_stats (parameter)
    learn_skill = 0
    class_limits, actor_limits = ['all'], ['all']
    case @id
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * CONFIGURATION
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #  It is very easy to configure the database. All that you need to do
    #  is write:
    #
    #     when <item ID>
    #       learn_skill = <skill_id>
    #       class_limits = [<class IDs that can use>]
    #       actor_limits = [<actor IDs that can use>]
    #
    #  For every item that you want to teach skills. To discover what the
    #  ID of an item or a skill is, look at the number directly to the left
    #  of their names in the Database. For the other 2, fill those in
    #  if only specific classes or actors can gain the skill. If you do not
    #  specify, it is assumed that any actor can use the item and gain the
    #  skill. There are two examples below. Feel free to delete them once
    #  you understand what you need to do.
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    when 1 # Potion
      learn_skill = 1 # Heal
      class_limits = [7]
    when 2 # High Potion
      learn_skill = 69 # Poison Edge
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * END CONFIGURATION
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    end
    return [learn_skill, class_limits, actor_limits][parameter]
  end
end 

#==============================================================================
# ** Weapon
#==============================================================================

class Weapon
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Skill ID
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def skill_id
    learn_skill = 0
    case @id
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * CONFIGURATION
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #
    #     when <weapon ID>
    #       learn_skill = <skill_id>
    #
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    when 1 # Bronze Sword
      learn_skill = 1 # Heal
    when 2 # Iron Sword
      learn_skill = 69 # Poison Edge
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * END CONFIGURATION
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    end
    return learn_skill
  end
end 

#==============================================================================
# ** Armor
#==============================================================================

class Armor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Skill ID
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def skill_id
    learn_skill = 0
    case @id
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * CONFIGURATION
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #
    #     when <armor ID>
    #       learn_skill = <skill_id>
    #
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    when 1 # Bronze Shield
      learn_skill = 1 # Heal
    when 2 # Iron Shield
      learn_skill = 69 # Poison Edge
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * END CONFIGURATION
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    end
    return learn_skill
  end
end
end

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Change Equipment
  #     equip_type : type of equipment
  #     id    : weapon or armor ID (If 0, remove equipment)
  #--------------------------------------------------------------------------
  alias ma_skill_teaching_items_change_equipment equip
  def equip (equip_type, id)
    # Forget the skill from what was previously equipped
    skill_id = 0
    case equip_type
    when 0; skill_id = $data_weapons[@weapon_id].skill_id if @weapon_id != 0
    when 1; skill_id = $data_armors[@armor1_id].skill_id if @armor1_id != 0
    when 2; skill_id = $data_armors[@armor2_id].skill_id if @armor2_id != 0
    when 3; skill_id = $data_armors[@armor3_id].skill_id if @armor3_id != 0
    when 4; skill_id = $data_armors[@armor4_id].skill_id if @armor4_id != 0
    end
    forget_skill (skill_id) if @unnatural_skills.include? (skill_id)
    @unnatural_skills.delete (skill_id)
    # Run original method
    ma_skill_teaching_items_change_equipment (equip_type, id)
    skill_id = 0
    case equip_type
    when 0; skill_id = $data_weapons[@weapon_id].skill_id if @weapon_id != 0
    when 1; skill_id = $data_armors[@armor1_id].skill_id if @armor1_id != 0
    when 2; skill_id = $data_armors[@armor2_id].skill_id if @armor2_id != 0
    when 3; skill_id = $data_armors[@armor3_id].skill_id if @armor3_id != 0
    when 4; skill_id = $data_armors[@armor4_id].skill_id if @armor4_id != 0
    end
    # Learn the skill from the weapon just equipped
    unless @skills.include? (skill_id) || skill_id == 0
      @unnatural_skills.push (skill_id)
      learn_skill (skill_id)
    end
  end
  #--------------------------------------------------------------------------
  # * Setup
  #     actor_id : actor ID
  #--------------------------------------------------------------------------
  alias ma_skill_teaching_items_actor_setup setup
  def setup(actor_id)
    @unnatural_skills = []
    # Run original method
    ma_skill_teaching_items_actor_setup (actor_id)
    # If there is a skill attached to weapon, learn it
    unless @weapon_id == 0
      skill_id = $data_weapons[@weapon_id].skill_id
      unless skill_id == 0 || @skills.include? (skill_id)
        @unnatural_skills.push (skill_id)
        learn_skill (skill_id)
      end
    end
    # If there are skills attached to the armors, learn them
    armor = [@armor1_id, @armor2_id, @armor3_id, @armor4_id]
    for armor_id in armor
      next if armor_id == 0
      skill_id = $data_armors[armor_id].skill_id
      next if skill_id == 0 || @skills.include? (skill_id)
      @unnatural_skills.push (skill_id)
      learn_skill (skill_id)
    end
  end
end

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Application of Item Effects
  #     item : item
  #--------------------------------------------------------------------------
  def item_effect (item)
    # Run original method
    effective = super (item)
    # If the item is a skill teacher, and if the actor does not already possess
    # the skill, and if his class and he are not restricted from using this
    # item to gain the skill
    if item.skill_id != 0 &&  (!@skills.include? (item.skill_id) || @unnatural_skills.include? (item.skill_id)) &&
         (item.class_limits.include? ('all') || item.class_limits.include? (@class_id)) &&
         (item.actor_limits.include? ('all') || item.actor_limits.include? (@actor_id))
      @unnatural_skills.delete (item.skill_id)
      learn_skill (item.skill_id)
      effective |= true
    end
    return effective
  end
end

This script uses the simple version of Zeriab's attr_sec_reader module addon (http://rmrk.net/index.php/topic,21582.0.html), included below. It must be inserted into your script editor in order for this script to work.

Code: [Select]
class Module
  def attr_sec_accessor(sym, default = 0)
    attr_writer sym
    attr_sec_reader sym, default
  end
 
  def attr_sec_reader(sym, default = 0)
    sym = sym.id2name
    string = "def #{sym};" +
             "  @#{sym} = #{default}  if @#{sym}.nil?;" +
             "  @#{sym};" +
             "end;"
    module_eval(string)
  end
end

Credit



Thanks


Support


Just post in this topic at rmrk for quick support

Known Compatibility Issues

Should be compatible with any script that does not perform the same function as this one. If any issues arise, I wwill be happy to fix them for you.

Author's Notes


This script was requested by ryu009 (for weapons, at least: I decided to expand upon his request though).

Title: Re: Skill Teaching Equipment & Items (XP Edition)
Post by: Sx2 on March 27, 2008, 10:12:14 PM
cool I'll defintely use this one

hmmm this reminds me of FFIX
Title: Re: Skill Teaching Equipment & Items (XP Edition)
Post by: Blulightning on July 23, 2008, 02:04:54 PM
Sweet, I added a load more to it and it works great
Title: Re: Skill Teaching Equipment & Items (XP Edition)
Post by: GoldenBoy on September 07, 2008, 01:54:51 PM
Where had this Code (second script) to go in?
New Script above Main or somewehre else?
Title: Re: Skill Teaching Equipment & Items (XP Edition)
Post by: modern algebra on September 07, 2008, 02:25:01 PM
Yes. And remember to put the module addon in as well.
Title: Re: Skill Teaching Equipment & Items (XP Edition)
Post by: ShadowOD on September 10, 2008, 08:45:42 PM
Is there a way to modify this so that you need experiance points to learn the skills. Ok makes no sence...

Right for instance FF9, You needed AP to learn the ability that was attached to the weapon ect.

I know there is a script like that but only on VX

Possible?

 :blizj:
Title: Re: Skill Teaching Equipment & Items (XP Edition)
Post by: modern algebra on September 11, 2008, 02:24:23 AM
Yeah, it's possible. I, however, do not intend to write that extension, at least not anytime soon. I haven't worked in XP for quite some time now, and I think the only script I intend to make are the ones for my own game and version 2 of my Grid Inventory System. So, sorry :(
Title: Re: Skill Teaching Equipment & Items (XP Edition)
Post by: ShadowOD on September 13, 2008, 12:09:42 PM
Alrighty then man, no worries  ;D

~Stay Cool~

 :blizj:
Title: Re: issues using this script
Post by: syperius on January 22, 2010, 04:46:38 AM
When tryin to load a previously saved game file I get this when trying to equip/unequip weapons
script "this sript" line 154, NoMethodError occured
undefined method 'include' for nil:NilClass

I get a similiar error further down the script around line 174 for using the items as well.

I mean besides that this script is excellent, and of course i already made a new game with a free shop and what not get to where i was before to continue testing with no issues what so ever. I thought I'd point that out for you. I was trying to edit this last night but my computer died on me.

BTW MA love your scripts, tis a true shame you're mostly done with XP, i would move on to VX if the tileset wasn't so static or has this gotten better?
Title: Re: Skill Teaching Equipment & Items (XP Edition)
Post by: Adrien on March 26, 2010, 03:03:40 AM
Need help:

what does this error mean? I just pasted this in and went to try it to see if its simmular to ff9

Title: Re: Skill Teaching Equipment & Items (XP Edition)
Post by: modern algebra on March 26, 2010, 11:54:11 AM
Quote
This script uses the simple version of Zeriab's attr_sec_reader module addon (http://rmrk.net/index.php/topic,21582.0.html), included below. It must be inserted into your script editor in order for this script to work.

Code: [Select]
class Module
  def attr_sec_accessor(sym, default = 0)
    attr_writer sym
    attr_sec_reader sym, default
  end
 
  def attr_sec_reader(sym, default = 0)
    sym = sym.id2name
    string = "def #{sym};" +
             "  @#{sym} = #{default}  if @#{sym}.nil?;" +
             "  @#{sym};" +
             "end;"
    module_eval(string)
  end
end