Skill Teaching Equipment & Items
Version: 2.0b
Author: modern algebra
Date: February 20, 2010
Version History
- <Version 2.0b> 02.20.2010 - Fixed error that, if a skill was learned through natural means while an equipped item already taught the skill, then the skill would disappear upon unequip.
- <Version 2.0> 06.28.2008 - New configuration, as well as multiple skills per Item
- <Version 1.0> 01.27.2008 - Original release
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 Version 2.0:
- Configuration is done in the Notes Field of the respective items. See the instructions for details
- One item, weapon, or armor can now teach more than one skill
- You can now set a level requirement for the weapons, armors, or items to teach the skill. So, if you want a Long Sword to teach Fire, but you want the actor to be level 10 before he gets it, the script can now perform that task.
Original:
- Allows items to teach actors skills permanently
- Allows weapon and armor to teach the actor skills for as long as he has the respective equipment equipped
- Very intuitive configuration; it is easy to set up
Screenshots
N/A for this type of script
Instructions
Insert this script just above Main.
To configure this script, merely go into the item, weapon, or armor in the database. In the Notes Field, put in this code:
\ls[skill_id, level_min]
where skill_id is the ID of the skill you want the item to teach and level_min is optional and makes it so that the skill the item teaches is only taught if the actor is at least that level. If it's left blank, it is assumed that there is no level requirement.
You can put in as many of these as you like, so if, for example, an item has this in it's notes:
\ls[5]
\ls[8, 7]
Then that item would teach skill 5 no matter what level the actor is, and once the actor reaches level 7 will teach skill 8. The script will take every instance of that code regardless of what else is in the Note Field
Script
#==============================================================================
# Skill Teaching Equipment & Items
# Version 2.0b
# Author: modern algebra (rmrk.net)
# Date: February 20, 2010
#~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Instructions:
# Insert this script just above Main.
#
# To configure this script, merely go into the item, weapon, or armor in the
# database. In the Notes Field, put in this code:
#
# \ls[skill_id, level_min]
#
# where skill_id is the ID of the skill you want the item to teach and
# level_min is optional and makes it so that the skill the item teaches
# is only taught if the actor is at least that level. If it's left blank,
# it is assumed that there is no level requirement.
#
# You can put in as many of these as you like, so if, for example, an item
# has this in it's notes:
#
# \ls[5]
# \ls[8, 7]
#
# Then that item would teach skill 5 no matter what level the actor is, and
# once the actor reaches level 7 will teach skill 8. The script will take
# every instance of that code regardless of what else is in the Note Field
#==============================================================================
# ** RPG::BaseItem
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# new method - skill_ids
#==============================================================================
class RPG::BaseItem
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Skill IDs
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def skill_ids
# Only works for Item, Weapon, and Armor
return if self.class == RPG::Skill
learn_skills = []
# Dissect Note
text = self.note.dup
while text[/\\ls\[(\w+),*\s*(\d*?)\]/i] != nil
text.sub! (/\\ls\[(\w+),*\s*(\d*?)\]/i) { '' }
learn_skills.push ([$1.to_i, $2.to_i])
end
return learn_skills
end
end
#==============================================================================
# ** Game_Actor
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# aliased methods - change_equip, setup, level_up
#==============================================================================
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_equipment_change change_equip
def change_equip (equip_type, item, test = false)
unless test
last_item = equips[equip_type]
# Forget the skills from what was previously equipped
skill_ids = last_item.nil? ? [] : last_item.skill_ids
skill_ids.each { |skill_id|
forget_skill (skill_id[0]) if @unnatural_skills.include? (skill_id[0])
@unnatural_skills.delete (skill_id[0])
}
end
# Run original method
ma_skill_teaching_items_equipment_change (equip_type, item, test)
unless test
last_item = equips[equip_type]
# Learn the skills from current_equipment
skill_ids = last_item.nil? ? [] : last_item.skill_ids
skill_ids.each { |skill_id|
unless skill_learn? ($data_skills[skill_id[0]]) || self.level < skill_id[1]
@unnatural_learning = true
learn_skill (skill_id[0])
@unnatural_learning = false
end
}
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)
for item in equips
next if item.nil?
item.skill_ids.each { |skill_id|
next if skill_learn? ($data_skills[skill_id[0]]) || self.level < skill_id[1]
@unnatural_learning = true
learn_skill (skill_id[0])
@unnatural_learning = false
}
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Level Up
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modalg_skl_teacher_equip_actor_lvlup level_up
def level_up
modalg_skl_teacher_equip_actor_lvlup
# Check Equipment and learn skills if not already learned
equips.each { |item|
next if item == nil
item.skill_ids.each { |skill_id|
unless skill_learn? ($data_skills[skill_id[0]]) || self.level < skill_id[1]
@unnatural_learning = true
learn_skill (skill_id[0])
@unnatural_learning = false
end
}
}
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Learn Skill
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_lrnskll_eqpmnt_8ik2 learn_skill
def learn_skill (skill_id, *args)
if @unnatural_learning
@unnatural_skills.push (skill_id) unless @unnatural_skills.include? (skill_id)
elsif skill_learn? (skill_id)
@unnatural_skills.delete (skill_id)
end
ma_lrnskll_eqpmnt_8ik2 (skill_id, *args)
end
end
#==============================================================================
# ** Game_Battler (Skill Teaching modification)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# aliased methods - item_test, item_effect
#==============================================================================
class Game_Battler
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Item Test
# user : person using item
# item : the item being used
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_skill_teaching_items_test_item item_test
def item_test (user, item)
effective = ma_skill_teaching_items_test_item (user, item)
if self.class != Game_Enemy
item.skill_ids.each { |skill_id|
effective |= !skill_learn? ($data_skills[skill_id[0]]) && self.level > skill_id[1]
}
end
return effective
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Application of Item Effects
# item : item
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_skill_teaching_items_effect_item item_effect
def item_effect (user, item)
# Run original method
ma_skill_teaching_items_effect_item (user, item)
item.skill_ids.each { |skill_id|
learn_skill (skill_id[0]) if self.class != Game_Enemy && self.level > skill_id[1]
}
end
end
Credit
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.
Demo
See attached.
Author's Notes
This script was requested by ryu009 (for weapons, at least: I decided to expand upon his request though).
This script by
modern algebra is licensed under a
Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.