Skill Teaching Equipment & Items
Version: 1.1
Author: modern algebra
Date: February 9, 2008
Version History
- Version 1.1: Added the feature that you can set skill teaching items to only work on specific actors and classes. 02/09/08
- Version 1.0: Original release. 01/27/08
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
- NEW in v. 1.1 -> You can now make it so that skill teaching items can only teach to specific actors or classes
- Allows items, weapons, and armors to teach actors skills
- Very intuitive configuration; it is easy to set up
Screenshots
N/A for this type of script
Instructions
See inside the header for instructions
Script
#==============================================================================
# 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, included below. It must be inserted into your script editor in order for this script to work.
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
- modern algebra, for the script
- Zeriab, for his attr_sec_reader module addon
Thanks
- ryu009, for requesting the script
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).