iPhone App Directory
RPG Maker VX
 
Gallery Members Search Calendar Help


Welcome Guest ( Log In | Register )

Collapse

>Announcement

Keep an eye out for the upcoming 3rd Quarter Contest!
 
Reply to this topicStart new topic
> Equipment Requirements by Ayene
Rating 5 V
Ayene
post Mar 20 2012, 09:53 AM
Post #1


Klam Reporter ^^
Group Icon


Type: Undisclosed
Alignment: Neutral Good




Equipment Requirements [VX]
by Ayene


Introduction:
The script allows you to set requirements for weapon and armor. For instance, outfitting a hero with two-handed axe would be possible only after reaching a specific level or having adequate statistics. Also added an option that allows to require certain skills.

Features:
- quite simple configuration,
- window displaying which stats are too low and which skills are needed,
- showing of the required skill can be turn on/off.

Screenshots:
Spoiler:

How to Use:
To use the script insert tag into the "Notes" box located in the Weapon or Armor tab of the database:
CODE
<stat_require LV, MAXHP, MAXMP, ATK, DEF, SPI, AGI>
where:
LV - required actor's level
MAXHP - maximum HP
MAXMP - maximum MP
ATK - Attack
DEF - Defence
SPI - Spirit
AGI - Agility

For example:
If you want a character to equip a weapon at level 6, provided that it has 120 max HP, 40 Attack, 70 Defence, add in the specified weapon's "Note" box:
CODE
<stat_require 6, 120, 0, 40, 70, 0, 0>

To set that the specified armor can be equipped only after gaining certain skill(s), add in "Note" box:
CODE
<skill_require ID, ID, ...>
where:
ID - required skill(s) ID(s)

For example:
To equip an weapon, that "requires" skills ID 10 and 40:
CODE
<skill_require 10, 40>

Script:
Spoiler:
CODE
#===================================================================
# Equipment Requirements [VX]
# by Ayene
# 27.01.2010 ver 1.2
# www.ultimateam.pl
#===================================================================
# Opis:
# The script allows you to set requirements for weapon and armor.
# For instance, outfitting a hero with two-handed axe would be possible
# only after reaching a specific level or having adequate statistics.
# Also added an option that allows to require certain skills.
#
# Instruction:
# To use the script insert tag into the "Notes" box located in the
# Weapon or Armor tab of the database:
#   <stat_require LV, MAXHP, MAXMP, ATK, DEF, SPI, AGI>,
# where:
# LV - required actor's level
# MAXHP - maximum HP
# MAXMP - maximum MP
# ATK - Attack
# DEF - Defence
# SPI - Spirit
# AGI - Agility
#
# For example:
# If you want a character to equip a weapon at level 6, provided that
# it has 120 max HP, 40 Attack, 70 Defence,
# add in the specified weapon's "Note" box:
#   <stat_require 6, 120, 0, 40, 70, 0, 0>
#
# Next, to equip an armor, which "requires" adequate agility:
# <stat_require 0, 0, 0, 0, 0, 0, 50>
#
# To set that the specified armor can be equipped only after gaining
# certain skill(s), add in "Note" box:
# <skill_require ID, ID, ...>
# where:
# ID - required skill(s) ID(s)

# For example:
# To equip an weapon, that "requires" skills ID 10 and 40:
# <skill_require 10, 40>
#===================================================================
module AYENE
  module ItemSpec
    ITEM_SPEC = /<(?:STAT_REQUIRE|stat_require)\s*(\d+)\s*, \s*(\d+), \s*(\d+), \s*(\d+), \s*(\d+), \s*(\d+), \s*(\d+)>/i
    WEAPON_TEXT = "To equip this weapon you need:"
    ARMOR_TEXT = "To equip this armor you need:"    
    ACC_TEXT = "To equip this accessory you need:"
    PARAM_NAMES = ["Level", "Max HP", "Max MP", "Attack", "Defence", "Spirit", "Agility", "Skills:"]  
    SKILL_SPEC = /<(?:SKILL_REQUIRE|skill_require)[ ]*(\d+(?:[ ]*,[ ]*\d+)*)>/i
    SHOW_SKILL_REC = true  # Show which skill is needed? (true/false)
  end
end

#===================================================================
# ** RPG::BaseItem
#===================================================================
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :spec_params
  #--------------------------------------------------------------------------
  # * Requirements Initialization
  #--------------------------------------------------------------------------
  def equip_req_ini
    @spec_params = {}
    (0..6).each{|i| @spec_params[i] = 0}
    @spec_params[7] = []
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when AYENE::ItemSpec::ITEM_SPEC
        @spec_params[0] = $1.to_i
        @spec_params[1] = $2.to_i
        @spec_params[2] = $3.to_i
        @spec_params[3] = $4.to_i
        @spec_params[4] = $5.to_i
        @spec_params[5] = $6.to_i
        @spec_params[6] = $7.to_i
      end
    }
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when AYENE::ItemSpec::SKILL_SPEC
        $1.scan(/\d+/).each { |num|
          skill_id = num.to_i
          @spec_params[7].push(skill_id) if $data_skills[skill_id] != nil
        }
      end
    }
  end
end

#===================================================================
# ** RPG::Weapon
#===================================================================
class RPG::Weapon < RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Requirements Text
  #--------------------------------------------------------------------------
  def eqreq_text
    return AYENE::ItemSpec::WEAPON_TEXT
  end
end

#===================================================================
# ** RPG::Armor
#===================================================================
class RPG::Armor < RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Requirements Text
  #--------------------------------------------------------------------------
  def eqreq_text
    case kind
    when 3
      return AYENE::ItemSpec::ACC_TEXT
    else
      return AYENE::ItemSpec::ARMOR_TEXT
    end  
  end
end

#===================================================================
# ** Game_Actor
#===================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Determine if Item can be Equipped (Actor's Parameters)
  #--------------------------------------------------------------------------
  def equip_allowed?(item)
    return true if (item.spec_params[0] <= level && item.spec_params[1] <= base_maxhp &&
    item.spec_params[2] <= base_maxmp && item.spec_params[3] <= base_atk &&
    item.spec_params[4] <= base_def && item.spec_params[5] <= base_spi &&
    item.spec_params[6] <= base_agi) && equip_skill_allowed?(item)
    return false
  end
  #--------------------------------------------------------------------------
  # * Determine if Item can be Equipped (Actor's Skills )
  #--------------------------------------------------------------------------
  def equip_skill_allowed?(item)  
    item.spec_params[7].each{|skill_id|
      return false if !skill_learn?($data_skills[skill_id])  
    }
    return true
  end
end

#===================================================================
# ** Game_Interpreter
#===================================================================
class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Aliased Definitions
  #--------------------------------------------------------------------------
  alias aye_eqreq_command_315 command_315
  alias aye_eqreq_command_316 command_316
  alias aye_eqreq_command_317 command_317
  alias aye_eqreq_command_318 command_318
  #--------------------------------------------------------------------------
  # * Check Equipment
  #      actor     : actor
  #--------------------------------------------------------------------------
  def check_change_equip(actor)
    for i in 0..4
      item = actor.equips[i]
      actor.change_equip(i, nil) if !item.nil? && !actor.equip_allowed?(item)
    end
  end
  #--------------------------------------------------------------------------
  # * Change EXP
  #--------------------------------------------------------------------------
  def command_315
    aye_eqreq_command_315
    iterate_actor_id(@params[0]) do |actor|
      check_change_equip(actor)  
    end  
  end
  #--------------------------------------------------------------------------
  # * Change Level
  #--------------------------------------------------------------------------
  def command_316
    aye_eqreq_command_316
    iterate_actor_id(@params[0]) do |actor|
      check_change_equip(actor)  
    end
  end  
  #--------------------------------------------------------------------------
  # * Change Parameters
  #--------------------------------------------------------------------------
  def command_317
    aye_eqreq_command_317
    iterate_actor_id(@params[0]) do |actor|
      check_change_equip(actor)  
    end
  end  
  #--------------------------------------------------------------------------
  # * Change Skills
  #--------------------------------------------------------------------------
  def command_318
    aye_eqreq_command_318
    iterate_actor_id(@params[0]) do |actor|
      check_change_equip(actor)  
    end
  end
end

#===================================================================
# ** Window_EquipReq
#===================================================================
class Window_EquipReq < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #      item     : item
  #      data     : parameters (array)
  #      actor    : actor
  #      skill    : skill
  #--------------------------------------------------------------------------
  def initialize(item, data, actor, skill)  
    if skill.empty? or !AYENE::ItemSpec::SHOW_SKILL_REC
      height = (data.size+1) / 2 * WLH + WLH + 32
    else
      height = (data.size+1) / 2 * WLH + WLH + 32 + WLH * [skill.size, 7].min
    end    
    super(42, 180 - height/2, 460, height)
    self.back_opacity = 255
    self.contents.font.color = crisis_color
    self.contents.draw_text(4, 0, self.width - 40, WLH, item.eqreq_text, 1)
    x = 10
    y = WLH  
    data.each_with_index{|array, i|  
      self.contents.font.color = system_color
      self.contents.draw_text(x+i%2*240, y+i/2*WLH, 200, WLH, AYENE::ItemSpec::PARAM_NAMES[array[0]].to_s, 0)    
      self.contents.font.color = normal_color
      self.contents.draw_text(x+120+i%2*240, y+i/2*WLH, 40, WLH, array[1].to_s, 2)
    }
    if !skill.empty? and AYENE::ItemSpec::SHOW_SKILL_REC
      size = (data.size+1)/2*WLH
      self.contents.font.color = system_color
      self.contents.draw_text(x, y+size, 200, WLH, AYENE::ItemSpec::PARAM_NAMES[7].to_s, 0)  
      self.contents.font.color = normal_color
      skill.each_with_index{|id, i|    
        self.contents.draw_text(x+140, y+size+WLH*i, 200, WLH, "- #{$data_skills[id].name}", 0)      
      }
    end
  end
end

#===================================================================
# ** Window_EquipItem
#===================================================================
class Window_EquipItem < Window_Item
  #--------------------------------------------------------------------------
  # * Determine if item is enabled
  #--------------------------------------------------------------------------
  def enable?(item)
    return @actor.equip_allowed?(item)
  end
end

#===================================================================
# ** Scene_Title
#===================================================================
class Scene_Title < Scene_Base
  #--------------------------------------------------------------------------
  # * Aliased Definitions
  #--------------------------------------------------------------------------
  alias aye_eqreq_sctit_loaddata load_database
  #--------------------------------------------------------------------------
  # * Load Database (aliased)
  #--------------------------------------------------------------------------
  def load_database
    aye_eqreq_sctit_loaddata
    for group in [$data_weapons, $data_armors]
      for obj in group
        next if obj.nil?
        obj.equip_req_ini
      end
    end
  end
end

#===================================================================
# ** Scene_Equip
#===================================================================
class Scene_Equip < Scene_Base
  #--------------------------------------------------------------------------
  # * Aliased Definitions
  #--------------------------------------------------------------------------
  alias aye_eqreq_sceq_update update
  alias aye_eqreq_sceq_upditsel update_item_selection
  #--------------------------------------------------------------------------
  # * Update Frame (aliased)
  #--------------------------------------------------------------------------
  def update      
    if @eqreq_window != nil
      update_eqreq_window
    else
      aye_eqreq_sceq_update
    end    
  end  
  #--------------------------------------------------------------------------
  # * Update Item Selection (aliased)
  #--------------------------------------------------------------------------
  def update_item_selection
    @item = @item_window.item
    if @item != nil and !@actor.equip_allowed?(@item) and Input.trigger?(Input::C)
      Sound.play_buzzer
      @item_window.active = false    
      show_eqreq_window
    else
      aye_eqreq_sceq_upditsel
      if Input.trigger?(Input::C)
        for i in 0..4
          item = @actor.equips[i]
          @actor.change_equip(i, nil) if !item.nil? && !@actor.equip_allowed?(item)
        end
        @equip_window.refresh
        for item_window in @item_windows
          item_window.refresh
        end
      end      
    end        
  end  
  #--------------------------------------------------------------------------
  # * Show Requirements Window
  #--------------------------------------------------------------------------
  def show_eqreq_window
    @frame = 0
    data = []
    @item.spec_params.each {|type, value|          
      data.push([type, value]) if value > 0 if type < 7  
    }
    data.sort!{|a,b| a[0] <=> b[0]}  
    skill = @item.spec_params[7]  
    @eqreq_window = Window_EquipReq.new(@item, data, @actor, skill)      
  end
  #--------------------------------------------------------------------------
  # * Update Requirements Window
  #--------------------------------------------------------------------------
  def update_eqreq_window
    @frame < 200 ? @frame += 1 : @frame = 0
    if @frame == 200 or Input.trigger?(Input::C) or Input.trigger?(Input::B)
      @eqreq_window.dispose
      @eqreq_window = nil    
      @item_window.active = true    
    end
  end
end

Credit:
- Ayene

Author's Notes:
I hope I didn't make any language mistakes smile.gif
Go to the top of the page
 
+Quote Post
   
Project667
post Mar 20 2012, 10:48 PM
Post #2



Group Icon


Type: Designer
Alignment: Chaotic Good




Thank you, I was looking for this for awhile!

Works great!

This post has been edited by Project667: Mar 20 2012, 10:48 PM


--------------------
QUOTE
Does this work in flash?


For making games, I use:
Spoiler:
Adobe Flash
Stencyl
RPG Maker VX (Quiet like it, need more experience.)
Unreal Engine 3
Unity 3d
Go to the top of the page
 
+Quote Post
   
Komyo
post Mar 23 2012, 09:32 AM
Post #3



Group Icon


Type: Writer
Alignment: Chaotic Neutral




You would not believe how long i have waited for someone to script this.
Words can't express my gratitude.


--------------------
Go to the top of the page
 
+Quote Post
   
nicolechan63
post May 4 2012, 12:23 PM
Post #4



Group Icon


Type: Undisclosed
Alignment: Unaligned




Really nice script !
Simple, looks great and quite informative smile.gif
Go to the top of the page
 
+Quote Post
   
kangaroocdub
post Jun 18 2012, 08:32 PM
Post #5


For just one second I felt whole.
Group Icon


Type: Writer
Alignment: Neutral Good




This is a very nice script indeed. I have yet to find any bugs with any other equipment enhancement scripts & SBS I am using. Thank you for sharing this.


--------------------
Spoiler:
I support



[
Go to the top of the page
 
+Quote Post
   
dra9onl3oy
post Aug 16 2012, 10:38 PM
Post #6



Group Icon


Type: Designer




Excellent script! This is just the kind of equipment system I intended to have in my game. Thanks for creating and posting it! I do have a question for you. Let's say an actor needs Agility 10 to equip a weapon but they are only at 5 Agility. When they gain a level and have now reached Agility 10 or higher, they can equip the weapon perfectly in my game. However, when I run the event, "Change Parameter, Actor #1, Increase by a constant of +5", the actor's agility now becomes 10, but they still cannot equip the item. I can't seem to figure out why the new Agility stat doesn't affect the weapon requirement. I tried different tests and made a skill that has a "States Change" set to "+" for Agility Up and after boosting the Agility to 10, the equipment requirement still did not recognize the change in Agility. Do you know why these examples don't work? The event for "Change Parameter" is more important for me to be recognized by the equipment requirement because it is a permanent increase in Agility, etc. But any help would be greatly appreciated!
Go to the top of the page
 
+Quote Post
   
Ayene
post Aug 20 2012, 04:53 PM
Post #7


Klam Reporter ^^
Group Icon


Type: Undisclosed
Alignment: Neutral Good




That is because 'Change Parameters' command adds to actor's agility not his base agility. Script compares the parameters required by equipment with actor's base parameters. I chose this solution to prevent situation that player uses potions to increase hero's params just to equip an armor, which he couldn't wear before. But in case you don't allow to use temporary potions in menu in your game, you can simply find in script part:
CODE
def equip_allowed?(item)
    return true if (item.spec_params[0] <= level && item.spec_params[1] <= base_maxhp &&
          item.spec_params[2] <= base_maxmp && item.spec_params[3] <= base_atk &&
          item.spec_params[4] <= base_def && item.spec_params[5] <= base_spi &&
          item.spec_params[6] <= base_agi) && equip_skill_allowed?(item)
    return false
  end

and change it with:
CODE
def equip_allowed?(item)
    return true if (item.spec_params[0] <= level && item.spec_params[1] <= self.maxhp &&
          item.spec_params[2] <= self.maxmp && item.spec_params[3] <= self.atk &&
          item.spec_params[4] <= self.def && item.spec_params[5] <= self.spi &&
          item.spec_params[6] <= self.agi) && equip_skill_allowed?(item)
    return false
  end


Script in first post has been updated. I totaly forgot about checking params in 'Scene_Equip' to prevent equipping just to increase params required f.ex. to equip new weapon.
Go to the top of the page
 
+Quote Post
   
dra9onl3oy
post Aug 22 2012, 11:20 PM
Post #8



Group Icon


Type: Designer




The change in script worked like a charm, thanks! I'm a beginner when it comes to scripts but I did notice that chunk of the code and thought that's what needed changing. So, I tried to replace "base_agil" to "current_agil" and other choice words to see if I could get lucky but to no avail. But anyway, thanks again for the help!

Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 30th September 2014 - 10:57 AM

RPGMakerVX.net is an Privacy Policy, Legal.