The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: pacdiggity on April 15, 2011, 04:42:28 PM

Title: Advanced Equipment Sets
Post by: pacdiggity on April 15, 2011, 04:42:28 PM
Advanced Equipment Sets
Version: 2.0
Author: Welfare-Daddy Pacman (based on a script by Lettuce)
Date: April 16, 2011

Version History



Planned Future Versions


Description


The maker can create similar items of equipment in the database, and can choose to give the player a bonus for collecting them. This script allows you to decide which of these items give the player a stats boost, which stat it boosts and by how much.

A special thing about these sets is that the sets add up, meaning that if you equip 2 peices from set 1 and 3 pieces from set 2, you get both of the boosts for the sets. It also displays the equipment set name on any equipped items in the status, equipment and item windows.

Features


Screenshots

Quite not very applicable. It's plug-and-play, basically.

Instructions

Detailed instructions are in the script, follow them closely. Put this script below materials and under main in the script editor.

Script


Code: [Select]
=begin
Equipment Sets Bonus
Version 1.0
By Welfare-Daddy Pacman (based on a script by Lettuce)

Description: The maker can create similar items of equipment in the database,
and can choose to give the player a bonus for collecting them. This script
allows you to decide which of these items give the player a stats boost, which
stat it boosts and by how much.

A special thing about these sets is that the sets add up, meaning that if you
equip 2 peices from set 1 and 3 pieces from set 2, you get both of the boosts
for the sets.

Instructions: Configuration with instructions begins at line 25, and ends at
line 104.
Support: Just find me on RMRK.net, I'm on pretty much every night.
=end

#-------------------------------------------------------------------------------
# EDITING SECTION A - EQUIPMENT SETS LIST
#-------------------------------------------------------------------------------

# Add more sets like this.
#          SetID => [weaponID,armor1ID, armor2ID, armor3ID, armor4ID]
# It is intended that the weapon, obviously, is the weapon of the set; armor1
# is a shield, armor2 is a head armor, armor3 is a body armor and armor4 is an
# accesory.
# Example:
#         1 => [1, 2, 3, 4, 5]
Sets = {
          1 => [1,2,9,15,24],
          2 => [2,1,7,14,23],
          3 => []
          } # If you touch this, bad things will happen.
         
#-------------------------------------------------------------------------------
# EDITING SECTION B - EQUIPMENT SETS BONUS LIST
#-------------------------------------------------------------------------------

# These must be in the same order as the sets you created above.
# "Set_Bonus" with 1 as the key will be the bonus for Sets 1 above
# The attribute values are as follows:
# 1: attack , 2: defense , 3: spirit, 4: agi, 5: health, 6: magic, 7: critical,
# 8: evasion.
# ~!All values EXCEPT FOR HEALTH AND MAGIC are in percentage!~
# i.e. 1000 is 10 times the stat's base value.
#
# If you want the set to only offer a bonus for having 2 or more pieces
# equipped, just leave the first secondary bracket empty, i.e:
#         1 => [ [],
#                [4,20]
#                []
#                [7,10]
#                [8,10]
#                ]
# The format is as follows:
# SetID => [ [Attribute,Amount], # when 1 piece is equipped
#       [Attribute,Amount], # when 2 pieces are equipped
#       [Attribute,Amount], # when 3 pieces are equipped
#       [Attribute,Amount], # when 4 pieces are equipped
#       [Attribute,Amount] # when 5 pieces are equipped
#       ] # Make sure you include this last bracket.
Set_Bonus = { # Do not touch this.
          1 => [ [1,5], #if equiped with one of these(2,9,15,24), gets 5% ATK
                 [2,20], #if any 2 of these (2,9,15,24), gets 5% ATK and 20% DEF
                 [5,100], #3 pieces gives 100 extra HP etc etc
                 [6,20],
                 [7,30]
                 ], # Don't touch this...
          2 => [ [],
                 [3,1000],
                 [2,2000],
                 [5,1000],
                 [6,2000]
                 ], # or this...
          3 => [ [1,5],
                 [2,20],
                 [5,100],
                 [7,2000],
                 [8,50]
                 ] # ESPECIALLY not this...
} # Do not touch this either.

#-------------------------------------------------------------------------------
# EDITING SECTION C - EQUIPMENT SET NAMES
#-------------------------------------------------------------------------------

# This one is simple. Just set it up like this:
# SetID => "Set Name"
Set_Names = { # Do not touch this.
  1 => "Super Set",
  2 => "Basic set",
  3 => "Ultimate set"
} # I will find and eat you if you touch this.
# If you are wondering about the point of this feature, it displays the set name
# on the status, item and equipment screens under any equipment that is in a
# set.

#-------------------------------------------------------------------------------
# END EDITING SECTION - DO NOT TOUCH UNLESS YOU ARE A SCRIPTER
# AND EVEN THEN IT'S NOT THAT COOL.
#-------------------------------------------------------------------------------

class Game_Actor < Game_Battler
  attr_accessor   :bonus_set
  attr_accessor   :bonus_set_pieces
  alias pacman_eq_bonus_setup setup
  def setup(actor_id)
    pacman_eq_bonus_setup(actor_id)
    @bonus_set = []
    for i in 1..Sets.size
      weapons = [nil,Sets[i][0]]
      armors = [Sets[i][1],Sets[i][2],Sets[i][3],Sets[i][4]]
      if Sets[i].include?(@weapon_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor4_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor3_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor2_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor1_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
    end
    @bonus_set_pieces = []
    for i in 0...@bonus_set.size
      @bonus_set_pieces.push(0)
    end
    if !@bonus_set.empty?
      for i in 0...@bonus_set.size
        weapons = [nil,Sets[@bonus_set[i]][0]]
        armors = [Sets[@bonus_set[i]][1],Sets[@bonus_set[i]][2],
                  Sets[@bonus_set[i]][3],Sets[@bonus_set[i]][4]]
        @bonus_set_pieces[i] += weapons.include?(@weapon_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor1_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor2_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor3_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor4_id) ? 1 : 0
      end
    end
  end
 
  alias pacman_eq_bonus_atk atk
  alias pacman_eq_bonus_def def
  alias pacman_eq_bonus_spi spi
  alias pacman_eq_bonus_agi agi
  alias pacman_eq_bonus_maxhp maxhp
  alias pacman_eq_bonus_maxmp maxmp
  alias pacman_eq_bonus_cri cri
  alias pacman_eq_bonus_eva eva
 
  def atk
    default_val = pacman_eq_bonus_atk
    final_val = default_val
    n = 100
    if !@bonus_set.empty?
      for j in 0...@bonus_set.size
      for i in 0...@bonus_set_pieces[j]
        if Set_Bonus[@bonus_set[j]][i] != nil
          if Set_Bonus[@bonus_set[j]][i][0] == 1
            n +=Set_Bonus[@bonus_set[j]][i][1]
          end
        end
      end
    end
      final_val *= n
      final_val /= 100
    else
      final_val = default_val
    end
    return final_val
  end
  def def
    default_val = pacman_eq_bonus_def
    final_val = default_val
    n = 100
    if !@bonus_set.empty?
      for j in 0...@bonus_set.size
      for i in 0...@bonus_set_pieces[j]
        if Set_Bonus[@bonus_set[j]][i] != nil
          if Set_Bonus[@bonus_set[j]][i][0] == 2
            n +=Set_Bonus[@bonus_set[j]][i][1]
          end
        end
      end
    end
    final_val *= n
      final_val /= 100
    else
      final_val = default_val
    end
    return final_val
  end
  def spi
    default_val = pacman_eq_bonus_spi
    final_val = default_val
    n = 100
    if !@bonus_set.empty?
      for j in 0...@bonus_set.size
      for i in 0...@bonus_set_pieces[j]
        if Set_Bonus[@bonus_set[j]][i] != nil
          if Set_Bonus[@bonus_set[j]][i][0] == 3
            n +=Set_Bonus[@bonus_set[j]][i][1]
          end
        end
      end
    end
    final_val *= n
      final_val /= 100
    else
      final_val = default_val
    end
    return final_val
  end
  def agi
    default_val = pacman_eq_bonus_agi
    final_val = default_val
    n = 100
    if !@bonus_set.empty?
      for j in 0...@bonus_set.size
      for i in 0...@bonus_set_pieces[j]
        if Set_Bonus[@bonus_set[j]][i] != nil
          if Set_Bonus[@bonus_set[j]][i][0] == 4
            n +=Set_Bonus[@bonus_set[j]][i][1]
          end
        end
      end
    end
    final_val *= n
      final_val /= 100
    else
      final_val = default_val
    end
    return final_val
  end
 
  def maxhp
    default_val = pacman_eq_bonus_maxhp
    final_val = default_val
    n = 100
    if @bonus_set
    if !@bonus_set.empty?
      for j in 0...@bonus_set.size
      for i in 0...@bonus_set_pieces[j]
        if Set_Bonus[@bonus_set[j]][i] != nil
          if Set_Bonus[@bonus_set[j]][i][0] == 5
            n += Set_Bonus[@bonus_set[j]][i][1]
          end
        end
      end
    end
      final_val *= n
      final_val /= 100
    else
      final_val = default_val
    end
    end
    return final_val
  end
 
  def maxmp
    default_val = pacman_eq_bonus_maxmp
    final_val = default_val
    n = 100
    if @bonus_set
    if !@bonus_set.empty?
      for j in 0...@bonus_set.size
      for i in 0...@bonus_set_pieces[j]
        if Set_Bonus[@bonus_set[j]][i] != nil
          if Set_Bonus[@bonus_set[j]][i][0] == 6
            n +=Set_Bonus[@bonus_set[j]][i][1]
          end
        end
      end
    end
    final_val *= n
      final_val /= 100
    else
      final_val = default_val
    end
    end
    return final_val

  end
 
  def cri
    default_val = pacman_eq_bonus_cri
    final_val = default_val
    n = 100
    if !@bonus_set.empty?
      for j in 0...@bonus_set.size
      for i in 0...@bonus_set_pieces[j]
        if Set_Bonus[@bonus_set[j]][i] != nil
          if Set_Bonus[@bonus_set[j]][i][0] == 7
            n +=Set_Bonus[@bonus_set[j]][i][1]
          end
        end
      end
    end
    final_val *= n
      final_val /= 100
    else
      final_val = default_val
    end
    return final_val
  end
 
  def eva
    default_val = pacman_eq_bonus_eva
    final_val = default_val
    n = 100
    if !@bonus_set.empty?
      for j in 0...@bonus_set.size
      for i in 0...@bonus_set_pieces[j]
        if Set_Bonus[@bonus_set[j]][i] != nil
          if Set_Bonus[@bonus_set[j]][i][0] == 8
            n +=Set_Bonus[@bonus_set[j]][i][1]
          end
        end
      end
    end
    final_val *= n
      final_val /= 100
    else
      final_val = default_val
    end
    return final_val
  end
 

    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
   
    @bonus_set = []
    for i in 1..Sets.size
      weapons = [nil,Sets[i][0]]
      armors = [Sets[i][1],Sets[i][2],Sets[i][3],Sets[i][4]]
      if Sets[i].include?(@weapon_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor4_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor3_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor2_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor1_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
    end
    @bonus_set_pieces = []
    for i in 0...@bonus_set.size
      @bonus_set_pieces.push(0)
    end
    if !@bonus_set.empty?
      for i in 0...@bonus_set.size
        weapons = [nil,Sets[@bonus_set[i]][0]]
        armors = [Sets[@bonus_set[i]][1],Sets[@bonus_set[i]][2],
                  Sets[@bonus_set[i]][3],Sets[@bonus_set[i]][4]]
        @bonus_set_pieces[i] += weapons.include?(@weapon_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor1_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor2_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor3_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor4_id) ? 1 : 0
      end
    end
   
  end 
end

class Window_Base < Window
  def draw_item_name(item, x, y, enabled = true)
      if item != nil
        is_set = false
        set_no = 0
        if item.is_a?(RPG::Weapon)

          for i in 1..Sets.size
            weapons = []
            weapons.push(Sets[i][0])
            if weapons.include?(item.id)
              is_set = true
              set_no = i
            end
          end
        end
        if item.is_a?(RPG::Armor)

          for i in 1..Sets.size
            armors = []         
            armors.push(Sets[i][1])
            armors.push(Sets[i][2])
            armors.push(Sets[i][3])
            armors.push(Sets[i][4])
            if armors.include?(item.id)
              is_set = true
              set_no = i
            end
          end
        end
        draw_icon(item.icon_index, x, y, enabled)
        self.contents.font.color = normal_color
        self.contents.font.color.alpha = enabled ? 255 : 128
        set_word = ""
        if is_set then set_word = "[" + Set_Names[set_no] + "]" end
        self.contents.font.size = Font.default_size
        self.contents.draw_text(x + 24, y, 172, WLH, item.name)
        self.contents.font.color = crisis_color
        self.contents.font.size = 12
        self.contents.draw_text(x + 28, y+12, 172, WLH, set_word)
        self.contents.font.color = normal_color
        self.contents.font.size = Font.default_size
      end
  end
end


Credit



Thanks


Support


Just find me here, I'm on for SO long each day... Post here or PM me.

Known Compatibility Issues

This script rewrites def change_equip(equip_type, item, test=false).
If you have any other script that does something with def change_equip (alias or rewrite), it will not work until unless you stick this snippet in that script before the end of the def change_equip method.
Code: [Select]
@bonus_set = []
    for i in 1..Sets.size
      weapons = [nil,Sets[i][0]]
      armors = [Sets[i][1],Sets[i][2],Sets[i][3],Sets[i][4]]
      if Sets[i].include?(@weapon_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor4_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor3_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor2_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor1_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
    end
    @bonus_set_pieces = []
    for i in 0...@bonus_set.size
      @bonus_set_pieces.push(0)
    end
    if !@bonus_set.empty?
      for i in 0...@bonus_set.size
        weapons = [nil,Sets[@bonus_set[i]][0]]
        armors = [Sets[@bonus_set[i]][1],Sets[@bonus_set[i]][2],
                  Sets[@bonus_set[i]][3],Sets[@bonus_set[i]][4]]
        @bonus_set_pieces[i] += weapons.include?(@weapon_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor1_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor2_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor3_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor4_id) ? 1 : 0
      end
   

Demo


I hardly doubt you'd need one.

Author's Notes


I script because I get bored. Good scripts are made when I get SUPER BORED. I am confident in saying that this is a SUPER BORED script.

Restrictions

Lettuce requests credit for his work, and I also appreciate it. So, credit both of us. He exhibits no problem for usage in commercial projects, and neither do I, but please let me know if you are using this in a commercial project.
:ccbysa: :rmvx:
For indie games.  :nespad:
Title: Re: Advanced Equipment Sets
Post by: pacdiggity on April 16, 2011, 12:34:52 AM
Compatibility patch is up: if you have any other script that rewrites or aliases def equip_change(equip_type, item, test=false), stick the patch before the "end" of that method. If you can't be bothered looking back up, the code is in this spoiler.
Spoiler for Code:
Code: [Select]
@bonus_set = []
    for i in 1..Sets.size
      weapons = [nil,Sets[i][0]]
      armors = [Sets[i][1],Sets[i][2],Sets[i][3],Sets[i][4]]
      if Sets[i].include?(@weapon_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor4_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor3_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor2_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
      if Sets[i].include?(@armor1_id)
        @bonus_set.push(i) if !@bonus_set.include?(i)
      end
    end
    @bonus_set_pieces = []
    for i in 0...@bonus_set.size
      @bonus_set_pieces.push(0)
    end
    if !@bonus_set.empty?
      for i in 0...@bonus_set.size
        weapons = [nil,Sets[@bonus_set[i]][0]]
        armors = [Sets[@bonus_set[i]][1],Sets[@bonus_set[i]][2],
                  Sets[@bonus_set[i]][3],Sets[@bonus_set[i]][4]]
        @bonus_set_pieces[i] += weapons.include?(@weapon_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor1_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor2_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor3_id) ? 1 : 0
        @bonus_set_pieces[i] += armors.include?(@armor4_id) ? 1 : 0
      end
   
If you're having trouble finding where to put this, just let me know.
Happy gaming, RMRK. ;)
Title: Re: Advanced Equipment Sets
Post by: wsensor on April 16, 2011, 09:30:52 PM
Would you be able to make a patch for this to work with additional armor slot extensions?


Examples
KGC Equip Extension
Yez Equipment Overhaul
Yem Equipment Overhaul

DerVVulfman Multi-Slot Equipment VX

I think there are one or two others but I can't remember.


All of these allow for adding extra armor slots (Types do not really matter just checking the extra slots.)
Title: Re: Advanced Equipment Sets
Post by: pacdiggity on April 17, 2011, 03:47:17 AM
Hmm... I don't know if I can do that soon, as I'm about to lose my computer.
Can you post or PM me the scripts or a link to them? I know I have KGC and YEM somewhere... but I can't remember which computer they're on. I'll see what I can do.
Title: Re: Advanced Equipment Sets
Post by: wsensor on April 19, 2011, 04:19:11 PM
I attached 3 of the scripts.
In YEZ equipment overhall their is the fallowing lines these show how it detects some stuff (unequippable stuff)
Spoiler for:
Code: [Select]
  def purge_unequippable(test = false)
    return if $game_temp.in_battle
    @purge_on = true
    for i in 0..4
      change_equip(i, nil, test) unless equippable?(equips[i])
      if equips[i].is_a?(RPG::Armor)
        type = equip_type[i-1]
        if equips[i].kind != YEZ::EQUIP::TYPE_RULES[type][1]
          change_equip(i, nil, test)
        end
      end
    end
    if extra_armor_number != 0
      for i in 5..armor_number
        change_equip(i, nil, test) unless equippable?(equips[i])
        if equips[i].is_a?(RPG::Armor)
          type = equip_type[i-1]
          if equips[i].kind != YEZ::EQUIP::TYPE_RULES[type][1]
            change_equip(i, nil, test)
          end
        end
      end
    end
    @purge_on = false
  end

In kgc equip extension this seems to have it detect if their are extra armor slots.
Spoiler for:
Code: [Select]
  alias class_id_equal_KGC_EquipExtension class_id=
  def class_id=(class_id)
    class_id_equal_KGC_EquipExtension(class_id)

    return if extra_armor_number == 0  # ????????

    # ?????????????
    for i in 5..armor_number
      change_equip(i, nil) unless equippable?(equips[i])
    end
  end

In yem equipment overhaul their is the fallowing lines these show how it detects some stuff (unequippable stuff)
Spoiler for:
Code: [Select]
  #--------------------------------------------------------------------------
  # new method: purge_unequippable
  #--------------------------------------------------------------------------
  def purge_unequippable(test = false)
    return if $game_temp.in_battle
    @purge_on = true
    for i in 0..4
      change_equip(i, nil, test) unless equippable?(equips[i])
      if equips[i].is_a?(RPG::Armor)
        type = equip_type[i-1]
        if equips[i].kind != YEM::EQUIP::TYPE_RULES[type][1]
          change_equip(i, nil, test)
        end
      end
    end
    if extra_armor_number != 0
      for i in 5..armor_number
        change_equip(i, nil, test) unless equippable?(equips[i])
        if equips[i].is_a?(RPG::Armor)
          type = equip_type[i-1]
          if equips[i].kind != YEM::EQUIP::TYPE_RULES[type][1]
            change_equip(i, nil, test)
          end
        end
      end
    end
    @purge_on = false
  end

For Dervvulfman's script:
http://houseslasher.com/index.php?showtopic=39
Theres 5 microsoft office .doc format links or a demo link.


The main problems are that each of these scripts all are coded differently and would each need a patch.
Title: Re: Advanced Equipment Sets
Post by: pacdiggity on April 20, 2011, 02:18:17 AM
That would take me quite some time and I'm doing stuff today...
I'll get back to you on this one. I agree, each would need a different patch.