Equipment Requisites
Version: 2.0
Author: Tsunokiette
Date: June 15, 2008
Version History
- <Version 1.0> Fulfilled request
- <Version 2.0> Added option for multiple requisites and level as a requisite
Planned Future Versions
- No future editions planned unless additions are requested
Description
Allows the game designer to designate requisites for the equipment. Items will not be equipped unless all requisites are met, and will be unequipped if the item they require is unequipped.
Features
- Items can have a single requisite
- Items can have multiple requisites
- Items can also require a level
Screenshots
Screenshots are unnecessary for this type of script :x
Instructions
The instructions are included in the script, but I'll go ahead and include them here.
[spoiler=How to Use] #---------------------------------------------------------------------------
# * Equip Requisites (Tsunokiette | June 15, 2008)
# ~~~~~~~~~~~~~~~~~~~
# Example : [[3,1,4,5]]
# Explanation : '3' is the ID of the item you wish to equip
# '1' is the TYPE of the item you wish to equip
# '4' is the ID(s) of the item(s) required to equip the item
# - or the level the actor must be to equip
# '5' is the TYPE(s) of the item(s) required to equip the item
# - or indicates that a level is required
# TYPE : 1 = Weapon
# 2 = Armor 1 (Shield)
# 3 = Armor 2 (Helmet)
# 4 = Armor 3 (Body Armor)
# 5 = Armor 4 (Accessory)
# 6 = level
# ~~~~~~~~~~~~~~~~~~~
# To make multiple requisites, simply separate with a comma :
# [[3,1,4,5],[4,1,5,2],[1,2,3,4]] ... et cetera
# To make an item have multiple requisites, simply change the last two
# numbers into arrays with everything separated by a comma :
# [[3,1,[2,3,4,5],[1,2,3,4]]]
# You can make an item require an item AND a level by using the same method
# as stated above:
# [[3,1,[2,3,6],[1,2,57]]]
#---------------------------------------------------------------------------[/spoiler]
The requisites themselves are added directly after the instructions you add into Game_Actor
Script
[spoiler=How to "install"]
Go to Game_Actor in the Script Editor
Find this in the beginning -
#--------------------------------------------------------------------------
# * Setup
# actor_id : actor ID
#--------------------------------------------------------------------------
def setup(actor_id)
actor = $data_actors[actor_id]
@actor_id = actor_id
@name = actor.name
@character_name = actor.character_name
@character_index = actor.character_index
@face_name = actor.face_name
@face_index = actor.face_index
@class_id = actor.class_id
@weapon_id = actor.weapon_id
@armor1_id = actor.armor1_id
@armor2_id = actor.armor2_id
@armor3_id = actor.armor3_id
@armor4_id = actor.armor4_idAnd add this after it
#---------------------------------------------------------------------------
# * Equip Requisites (Tsunokiette | June 15, 2008)
# ~~~~~~~~~~~~~~~~~~~
# Example : [[3,1,4,5]]
# Explanation : '3' is the ID of the item you wish to equip
# '1' is the TYPE of the item you wish to equip
# '4' is the ID(s) of the item(s) required to equip the item
# - or the level the actor must be to equip
# '5' is the TYPE(s) of the item(s) required to equip the item
# - or indicates that a level is required
# TYPE : 1 = Weapon
# 2 = Armor 1 (Shield)
# 3 = Armor 2 (Helmet)
# 4 = Armor 3 (Body Armor)
# 5 = Armor 4 (Accessory)
# 6 = level
# ~~~~~~~~~~~~~~~~~~~
# To make multiple requisites, simply separate with a comma :
# [[3,1,4,5],[4,1,5,2],[1,2,3,4]] ... et cetera
# To make an item have multiple requisites, simply change the last two
# numbers into arrays with everything separated by a comma :
# [[3,1,[2,3,4,5],[1,2,3,4]]]
# You can make an item require an item AND a level by using the same method
# as stated above:
# [[3,1,[2,3,6],[1,2,57]]]
#---------------------------------------------------------------------------
@equip_requirements = []
#---------------------------------------------------------------------------
# End of Equip Requisites
#---------------------------------------------------------------------------And find this
#--------------------------------------------------------------------------
# * Change Equipment (designate object)
# equip_type : Equip region (0..4)
# item : Weapon or armor (nil is used to unequip)
# test : Test flag (for battle test or temporary equipment)
#--------------------------------------------------------------------------
def change_equip(equip_type, item, test = false)
last_item = equips[equip_type]
unless test
return if $game_party.item_number(item) == 0 if item != nil
$game_party.gain_item(last_item, 1)
$game_party.lose_item(item, 1)
end
item_id = item == nil ? 0 : item.id
case equip_type
when 0 # Weapon
@weapon_id = item_id
unless two_hands_legal? # If two hands is not allowed
change_equip(1, nil, test) # Unequip from other hand
end
when 1 # Shield
@armor1_id = item_id
unless two_hands_legal? # If two hands is not allowed
change_equip(0, nil, test) # Unequip from other hand
end
when 2 # Head
@armor2_id = item_id
when 3 # Body
@armor3_id = item_id
when 4 # Accessory
@armor4_id = item_id
end
endAnd replace it with this:
#--------------------------------------------------------------------------
# * Change Equipment (designate object)
# equip_type : Equip region (0..4)
# item : Weapon or armor (nil is used to unequip)
# test : Test flag (for battle test or temporary equipment)
#--------------------------------------------------------------------------
def change_equip(equip_type, item, test = false)
last_item = equips[equip_type]
#---------------------------------------------------------------------------
# * Don't allow equip if requirement is not met
#---------------------------------------------------------------------------
@equip_requirements.each do |requisite1|
if requisite1[0] == item.id
if requisite1[2].is_a?(Array)
for i in 0...requisite1[2].size
case requisite1[3][i]
when 1
return change_equip(equip_type,last_item,test) if @weapon_id != requisite1[2][i]
when 2
return change_equip(equip_type,last_item,test) if @armor1_id != requisite1[2][i]
when 3
return change_equip(equip_type,last_item,test) if @armor2_id != requisite1[2][i]
when 4
return change_equip(equip_type,last_item,test) if @armor3_id != requisite1[2][i]
when 5
return change_equip(equip_type,last_item,test) if @armor4_id != requisite1[2][i]
when 6
return change_equip(equip_type,last_item,test) if @level < requisite1[2][i]
end
end
else
case requisite1[3]
when 1
return change_equip(equip_type,last_item,test) if @weapon_id != requisite1[2]
when 2
return change_equip(equip_type,last_item,test) if @armor1_id != requisite1[2]
when 3
return change_equip(equip_type,last_item,test) if @armor2_id != requisite1[2]
when 4
return change_equip(equip_type,last_item,test) if @armor3_id != requisite1[2]
when 5
return change_equip(equip_type,last_item,test) if @armor4_id != requisite1[2]
when 6
return change_equip(equip_type,last_item,test) if @level < requisite[2]
end
end
end
end
#---------------------------------------------------------------------------
# End Equip Requisites (Equip Legal? Function)
#---------------------------------------------------------------------------
unless test
return if $game_party.item_number(item) == 0 if item != nil
$game_party.gain_item(last_item, 1)
$game_party.lose_item(item, 1)
end
item_id = item == nil ? 0 : item.id
case equip_type
when 0 # Weapon
@weapon_id = item_id
unless two_hands_legal? # If two hands is not allowed
change_equip(1, nil, test) # Unequip from other hand
end
when 1 # Shield
@armor1_id = item_id
unless two_hands_legal? # If two hands is not allowed
change_equip(0, nil, test) # Unequip from other hand
end
when 2 # Head
@armor2_id = item_id
when 3 # Body
@armor3_id = item_id
when 4 # Accessory
@armor4_id = item_id
end
#---------------------------------------------------------------------------
# * If an item is unequiped, unequip any items that required it
#---------------------------------------------------------------------------
@equip_requirements.each do |requisite2|
if requisite2[2].is_a?(Array)
for i in 0...requisite2[2].size
if requisite2[2][i] == last_item.id
case requisite2[1]
when 1
change_equip(0,nil,test) if @weapon_id == requisite2[0] and last_item.id != item_id
when 2
change_equip(1,nil,test) if @armor1_id == requisite2[0] and last_item.id != item_id
when 3
change_equip(2,nil,test) if @armor2_id == requisite2[0] and last_item.id != item_id
when 4
change_equip(3,nil,test) if @armor3_id == requisite2[0] and last_item.id != item_id
when 5
change_equip(4,nil,test) if @armor4_id == requisite2[0] and last_item.id != item_id
when 6
p "How the heck did you equip this if your level was too low?" if @level < requisite2[2][i]
end
end
end
else
if requisite2[2] == last_item.id
case requisite2[1]
when 1
change_equip(0,nil,test) if @weapon_id == requisite2[0] and last_item.id != item_id
when 2
change_equip(1,nil,test) if @armor1_id == requisite2[0] and last_item.id != item_id
when 3
change_equip(2,nil,test) if @armor2_id == requisite2[0] and last_item.id != item_id
when 4
change_equip(3,nil,test) if @armor3_id == requisite2[0] and last_item.id != item_id
when 5
change_equip(4,nil,test) if @armor4_id == requisite2[0] and last_item.id != item_id
when 6
p "How the heck did you equip this if your level was too low?" if @level < requisite2[2]
end
end
end
end
#---------------------------------------------------------------------------
# End Equip Requisites (Unquip Function)
#---------------------------------------------------------------------------
end[/spoiler]
Credit
Thanks
- Modern Algebra 2 (because he's cool and he helped me realize a mistake I made during early production)
- lorehunter for requesting the script
Support
If you encounter any errors, please let me know :x
Known Compatibility Issues
This script overwrites the change_equip method in Game_Actor. If another script modifies this, it will be overwritten and one of the two won't work. If this occurs then post the method, and I'll try to customize it for you.
Author's Notes
If a piece of equipment requires something, please include that fact in the description.
i.e. "A throwing star. Requires ninja gloves and level 57 to equip"
Otherwise the player will end up throwing a fit because he can't equip certain items and doesn't know why lol.
Nice job Tsuno. I didn't realize you had added level requirements until I already wrote a script that did it. Sorry about that. I think the two scripts are compatible anyway though, and the main focus of my script is stat requirements, not other equipment requirements, so though there is a little overlap, I don't think it's a big deal.
Anyway, good job with this script.
EDIT::
Damn, our scripts aren't compatible. :( I'd like to integrate the scripts if that's okay with you. You'd get co-author credits of course.
I just noticed the Notes section a little while ago - it's the reason I wrote the script up :P
Would this work for guns? Like, for example, You can't fire the gun unless you have bullets?
The only thing this script does is keep you from equipping something if the thing(s) it requires are not equipped. And unequips whenever the required item is unequipped.
When is there gonna be a script to where you gotta be a specific actor/class in order to use the item/equipment? >_>;
That's easy enough to do without a script. The database editor already allows you to decide which classes can use which equipment. As for specific actors... just make a duplicate of the class which is exactly the same and just add the piece of equipment to the list of equipment that class can use. That way you can't tell the difference between that character's class and another character who has the same class, but at the same time only that character can use the piece of equipment.
it says error at line 475: NoMethodError occurred. undefined method 'each' for nil:NilClass when i try to use this