The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: Tsunokiette on June 16, 2008, 01:43:34 AM

Title: Equipment Requisites
Post by: Tsunokiette on June 16, 2008, 01:43:34 AM
Equipment Requisites
Version: 2.0
Author: Tsunokiette
Date: June 15, 2008

Version History



Planned Future Versions


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


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 for 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]]]
    #---------------------------------------------------------------------------

The requisites themselves are added directly after the instructions you add into Game_Actor

Script



Spoiler for How to "install":
Go to Game_Actor in the Script Editor

Find this in the beginning -

Code: [Select]
  #--------------------------------------------------------------------------
  # * 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_id

And add this after it

Code: [Select]
    #---------------------------------------------------------------------------
    # * 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

Code: [Select]
  #--------------------------------------------------------------------------
  # * 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
  end

And replace it with this:

Code: [Select]
  #--------------------------------------------------------------------------
  # * 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

Credit



Thanks


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.
Title: Re: Equipment Requisites
Post by: Leventhan on June 16, 2008, 03:14:46 AM
Nice script!
I never thought of something like this. ;8
+rep
Title: Re: Equipment Requisites
Post by: modern algebra on June 27, 2008, 05:45:24 PM
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.
Title: Re: Equipment Requisites
Post by: Tsunokiette on June 27, 2008, 09:06:25 PM
That's fine by me, sounds cool.  :)
If the RGSS 2.0 was divided into a more detailed hierarchy then this could have been done with a simple alias lol.

EDIT : I like how you wrote your version, much easier to use lol. I've still got a lot to learn, but that's okay. I recently took out an old C++ book I have and am trying to learn it again seeing as I'm a bit older and it should be much easier to learn it.
Title: Re: Equipment Requisites
Post by: modern algebra on June 27, 2008, 11:51:30 PM
I just noticed the Notes section a little while ago - it's the reason I wrote the script up :P
Title: Re: Equipment Requisites
Post by: epson777341 on July 08, 2008, 04:43:26 PM
Would this work for guns? Like, for example, You can't fire the gun unless you have bullets?
Title: Re: Equipment Requisites
Post by: Tsunokiette on July 09, 2008, 02:46:44 AM
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.
Title: Re: Equipment Requisites
Post by: Felix Flywheel on October 20, 2009, 08:05:03 PM
When is there gonna be a script to where you gotta be a specific actor/class in order to use the item/equipment?  >_>; 
Title: Re: Equipment Requisites
Post by: Tsunokiette on December 20, 2009, 03:47:14 PM
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.
Title: Re: Equipment Requisites
Post by: DJPark on April 16, 2010, 02:02:34 AM
it says error at line 475: NoMethodError occurred. undefined method 'each' for nil:NilClass when i try to use this