=begin #=============================================================================== Title: Utils: Equip Checks Author: Hime Date: Oct 26, 2013 -------------------------------------------------------------------------------- ** Change log Oct 26, 2013 - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script provides a set of convenience script calls for your checking equips. You can check actors based on their ID, or based on their position in the party. For example, you can check if an actor has a certain weapon or armor equipped. In addition to checking specific weapons or armors, you can check whether certain weapon types or armor types are equipped, or even when an equip type is equipped. Not only can you check whether a single equip is equipped, you can check if any equip from a list of equips is equipped, or whether all equips from a list of equips is equipped. -------------------------------------------------------------------------------- ** Installation Place this script below Materials and above Main -------------------------------------------------------------------------------- ** Usage All script calls take an "index", which can be either the actor ID or the party index. The actor ID is based on the database ID of the actor, and uses positive indices. If you pass in a 1, you will check actor 1. The party index is based on the position in the party, and you use negative indices. For example, if you pass in a -1, it will check the current first actor in the party. The ID of the weapons and armors can be looked up in the database. The ID of the weapon types and armor types can be looked up in the terms. The following script calls check whether a certain equip is equipped. weapon_equipped?(index, weapon_id) - true if weapon is equipped armor_equipped?(index, armor_id) - true if armor is equipped wtype_equipped?(index, wtype_id) - true if weapon type is equipped atype_equipped?(index, atype_id) - true if armor type is equipped The following script calls check whether any equip from a list of ID's is equipped. Pass the ID's in the form [1,2,3] any_weapon_equipped?(index, weapon_ids) any_armor_equipped?(index, armor_ids) any_wtype_equipped?(index, wtype_ids) any_atype_equipped?(index, atype_ids) The following script calls check whether all equips from a list of ID's is equipped. Pass the ID's in the form [1,2,3]. Note the plural in the method names all_weapons_equipped?(index, weapon_ids) all_armors_equipped?(index, armor_ids) all_wtypes_equipped?(index, wtype_ids) all_atypes_equipped?(index, atype_ids) -------------------------------------------------------------------------------- ** Examples To check whether the second member of the party has either weapon 1, 3, or 8 equipped, use any_weapon_equipped?(-2, [1,3,8]) To check whether the third actor has all of armors 1, 12, and 34 equipped, use all_armors_equipped?(3, [1, 12, 34]) #=============================================================================== =end $imported = {} if $imported.nil? $imported["TH_UtilsEquipChecks"] = true #=============================================================================== # ** Rest of script #=============================================================================== class Game_Interpreter def get_actor(index) if index < 0 index = index.abs - 1 return $game_party.all_members[index] else return $game_actors[index] end end #----------------------------------------------------------------------------- # Returns true if the actor has the weapon equipped #----------------------------------------------------------------------------- def weapon_equipped?(index, weapon_id) actor = get_actor(index) return false unless actor return actor.weapons.any? {|weapon| weapon.id == weapon_id} end #----------------------------------------------------------------------------- # Returns true if the actor has the armor equipped #----------------------------------------------------------------------------- def armor_equipped?(index, armor_id) actor = get_actor(index) return false unless actor return actor.armors.any? {|armor| armor.id == armor_id} end #----------------------------------------------------------------------------- # Returns true if the actor has the weapon type equipped #----------------------------------------------------------------------------- def wtype_equipped?(index, wtype_id) actor = get_actor(index) return false unless actor return actor.weapons.any? {|weapon| weapon.wtype_id == wtype_id} end #----------------------------------------------------------------------------- # Returns true if the actor has the armor type equipped #----------------------------------------------------------------------------- def atype_equipped?(index, atype_id) actor = get_actor(index) return false unless actor return actor.armors.any? {|armor| armor.atype_id == atype_id} end #----------------------------------------------------------------------------- # Returns true if any weapon from a list of armors is equipped #----------------------------------------------------------------------------- def any_weapon_equipped?(index, weapon_ids) actor = get_actor(index) return false unless actor return !(actor.weapons.collect {|weapon| weapon.id} & weapon_ids).empty? end #----------------------------------------------------------------------------- # Returns true if any armor from a list of armors is equipped #----------------------------------------------------------------------------- def any_armor_equipped?(index, armor_ids) actor = get_actor(index) return false unless actor return !(actor.armors.collect {|armor| armor.id} & armor_ids).empty? end def any_wtype_equipped?(index, wtype_ids) actor = get_actor(index) return false unless actor return !(actor.weapons.collect {|w| w.wtype_id} & wtype_ids).empty? end def any_atype_equipped?(index, atype_ids) actor = get_actor(index) return false unless actor return !(actor.armors.collect {|w| w.atype_id} & atype_ids).empty? end def all_weapons_equipped?(index, weapon_ids) actor = get_actor(index) return false unless actor return (weapon_ids - actor.weapons.collect {|w| w.id }).empty? end def all_armors_equipped?(index, armor_ids) actor = get_actor(index) return false unless actor return (armor_ids - actor.armors.collect {|a| a.id}).empty? end def all_wtypes_equipped?(index, wtype_ids) actor = get_actor(index) return false unless actor return (wtype_ids - actor.weapons.collect {|w| w.wtype_id}).empty? end def all_atypes_equipped?(index, atype_ids) actor = get_actor(index) return false unless actor return (atype_ids - actor.armors.collect {|a| a.atype_id}).empty? end end