Neoz Kaho   07-04-2012, 05:14 AM
#1
Equipment Requirements XP

สคริปต์เขียนโดย : Ayene
ลิงค์ต้นฉบับ : http://forums.rpgmakerweb.com/index.php?...rements-xp


รายละเอียด :
อยากกำหนดไหมว่าของนี้มันเทพจนต้องบังคับว่าต้องสถานะแบบนี้ๆ ถึงจะใส่ได้ อยากจำกัดไหมครับว่าของประเภทนี้มีเกณฑ์ขั้นต่ำ ถ้าไม่เข้าข่ายแบบนี้อดใส่ จะได้ไม่เกิดปัญหาเอาของเทพยัดให้ตัวเลเวลต่ำแล้วมันเทพเกินไป สคริปต์นี้ช่วยคุณได้!!

สกรีนช๊อต :
[Image: screenfp.png]

วิธีการใช้งาน :
เวลาใช้งานให้กำหนดค่าของสคริปต์ตามนี้ครับ
Code:
WEAPON [weapon ID] = [lv, maxhp, maxsp, str, dex, agi, int, [skill_id, skill_id, ...]]
ให้ใส่ไปเลยว่าเอาค่าเท่าไหร่บ้างในวงเล็บ แต่อาจจะไม่ชัดเจนเท่าไหร่ ดูตัวอย่างกันดีกว่า

สมมติว่าบังคับให้อาวุธ ID ที่ 2 ใส่ได้ตอนเลเวล 6 เท่านั้น และต้องมี Max HP 120 Strength 40 Int 70 ก็ใส่แบบนี้
Code:
WEAPON [2] = [6, 120, 0, 40, 0, 0, 70, []]

ลองอีกอันคราวนี้เป็นเกราะบ้าง ต้องการสกิล ID 10 และ 40 ก็ใส่ไปว่า
Code:
ARMOR [3] = [0, 0, 0, 0, 70, 0, 0, [10, 40]]
เท่านี้ก็บังคับล่ะว่าเกราะ ID3 นี้ต้องใช้สกิลนี้ได้ถึงจะสวมได้



โค๊ดสคริปต์
Code:
#===================================================================
# Equipment Requirements [XP]
# by Ayene
# 26.03.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 simply configure requirements below (separately for each
# weapon and armor), according to the formula:
#
# WEAPON [weapon ID] = [lv, maxhp, maxsp, str, dex, agi, int, [skill_id, skill_id, ...]]
#
# For example:
# If you want a character to equip a weapon ID 2 at level 6, provided that
# it has 120 max HP, 40 strength, 70 intelligence,
# type in configuration below:
# WEAPON [2] = [6, 120, 0, 40, 0, 0, 70, []]

# Next, to equip an armor ID 3, which "requires" adequate agility
# and knowledge of the skill ID 10 and 40, type:
# ARMOR [3] = [0, 0, 0, 0, 70, 0, 0, [10, 40]]
#
#===================================================================

# CONFIGURATION
module AYENE
  module EQUIP_REQ

   WEAPON = []
   ARMOR = []

# ~~~~~~~~~~~~~~~~~BRONIE~~~~~~~~~~~~~~~~

  # WEAPON [weapon ID] = [lv, maxhp, maxsp, str, dex, agi, int, [skill_id, skill_id, ...]]

  WEAPON[1] = [2, 10, 10, 10, 10, 10, 10, [4]]  
  WEAPON[3] = [3, 500, 20, 0, 0, 0, 0, []]

# ~~~~~~~~~~~~~~~~PANCERZE~~~~~~~~~~~~~~~~

  # ARMOR [armor ID] = [lv, maxhp, maxsp, str, dex, agi, int, [skill_id, skill_id, ...]]

  ARMOR[2] = [1, 300, 0, 0, 0, 0, 0, []]
  ARMOR[3] = [3, 400, 0, 0, 0, 0, 0, []]
        
  ACC_TEXT = "Your stats are too low to equip this item."
  PARAM_NAMES = ["Level", "Max HP", "Max SP", "Strength", "Dexterity", "Agility", "Intelligence", "Skills:"]  

  SHOW_SKILL_REQ = true  # Show which skill is needed?

  WLH = 32  # Line Height in Requirements Window
  end
end

#===================================================================
# Game_Actor
#===================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Determine if Item can be Equiped (Actor's Parameters)
  #      stat   : stats
  #--------------------------------------------------------------------------
  def equip_allowed?(stat)
        return true if stat[0] <= level && stat[1] <= base_maxhp &&
                  stat[2] <= base_maxsp && stat[3] <= base_str &&
                  stat[4] <= base_dex && stat[5] <= base_agi &&
                  stat[6] <= base_int && equip_skill_allowed?(stat)
        return false
  end
  #--------------------------------------------------------------------------
  # * Determine if Item can be Equiped (Actor's Skills )
  #      stat   : stats
  #--------------------------------------------------------------------------
  def equip_skill_allowed?(stat)        
        return true if stat[7].empty?
        stat[7].each{|skill_id|
          return false if !skill_learn?(skill_id)      
        }
        return true
  end
end

#===================================================================
# Window_Help
#===================================================================
class Window_EquipReq < Window_Base
  include AYENE::EQUIP_REQ
  #--------------------------------------------------------------------------
  # * Object Initialization
  #      item      : item
  #      data      : parameters (array)
  #      actor    : actor
  #      skill    : skill
  #--------------------------------------------------------------------------
  def initialize(item, data, actor, skill)      
        if skill.empty? or !SHOW_SKILL_REQ
          height = (data.size+1) / 2 * WLH + WLH + 32
        else
          height = (data.size+1) / 2 * WLH + WLH + 32 + WLH * [skill.size, 7].min
        end      
        super(100, 200 - height/2, 460, height)
        self.contents = Bitmap.new(width - 32, height - 32)
        self.z = 1000
        self.opacity = 255
        self.contents.font.color = crisis_color
        self.contents.draw_text(4, 0, self.width - 40, WLH, ACC_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, 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 SHOW_SKILL_REQ
          size = (data.size+1)/2*WLH
          self.contents.font.color = system_color
          self.contents.draw_text(x, y+size, 200, WLH, 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

#===================================================================
# Scene_Equip
#===================================================================
class Scene_Equip
  include AYENE::EQUIP_REQ
  #--------------------------------------------------------------------------
  # * Aliased Definitions
  #--------------------------------------------------------------------------
  alias ayene_item_stats_sceq_update update
  alias ayene_item_stats_sceq_update_item update_item
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update    
        @req_window != nil ? update_spec_selection : ayene_item_stats_sceq_update
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when item window is active)
  #--------------------------------------------------------------------------
  def update_item
        @stat = nil
        item = @item_window.item
        case item
        when RPG::Weapon
          @stat = WEAPON[item.id]
        else
          @stat = ARMOR[item.id]
        end
        unless @stat == nil  
          if Input.trigger?(Input::C) && !@actor.equip_allowed?(@stat)
                $game_system.se_play($data_system.buzzer_se)      
                @item_window.active = false
                show_spec_window  
                return
          end
        end
        ayene_item_stats_sceq_update_item
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when requirements window is active)
  #--------------------------------------------------------------------------
  def update_spec_selection
        @frame < 100 ? @frame += 1 : @frame = 0
        if @frame == 100 or Input.trigger?(Input::C) or Input.trigger?(Input::B)
          @req_window.dispose
          @req_window = nil      
          @item_window.active = true      
        end
  end
  #--------------------------------------------------------------------------
  # * Show Requirements Window
  #--------------------------------------------------------------------------
  def show_spec_window
        @frame = 0
        data = []
        @stat.each_with_index {|value, type|
          data.push([type, value]) if value > 0 if type < 7  
        }      
        data.sort!{|a,b| a[0] <=> b[0]}
        skill = @stat[7]
        @req_window = Window_EquipReq.new(@item, data, @actor, skill)    
  end
end

#===================================================================
# Game_Interpreter
#===================================================================
class Interpreter
  include AYENE::EQUIP_REQ
  #--------------------------------------------------------------------------
  # * Aliased Definitions
  #--------------------------------------------------------------------------
  alias aye_command_315 command_315
  alias aye_command_316 command_316
  alias aye_command_317 command_317
  alias aye_command_318 command_318
  #--------------------------------------------------------------------------
  # * Change EXP
  #--------------------------------------------------------------------------
  def command_315
        aye_command_315
        iterate_actor(@parameters[0]) do |actor|
          check_change_equip(actor)  
        end  
  end
  #--------------------------------------------------------------------------
  # * Change Level
  #--------------------------------------------------------------------------
  def command_316
        aye_command_316
        iterate_actor(@parameters[0]) do |actor|
          check_change_equip(actor)  
        end
  end  
  #--------------------------------------------------------------------------
  # * Change Parameters
  #--------------------------------------------------------------------------
  def command_317
        aye_command_317
        iterate_actor(@parameters[0]) do |actor|
          check_change_equip(actor)  
        end
  end
  #--------------------------------------------------------------------------
  # * Change Skills
  #--------------------------------------------------------------------------
  def command_318
        aye_command_318
        iterate_actor(@parameters[0]) do |actor|
          check_change_equip(actor)  
        end
  end
  #--------------------------------------------------------------------------
  # * Check Equipment
  #      actor     : actor
  #--------------------------------------------------------------------------
  def check_change_equip(actor)  
        for i in 0..4
          case i
          when 0
                item = $data_weapons[actor.weapon_id]
                stat = WEAPON[item.id]
          when 1
                item = $data_armors[actor.armor1_id]
                stat = ARMOR[item.id]
          when 2
                item = $data_armors[actor.armor2_id]
                stat = ARMOR[item.id]
          when 3
                item = $data_armors[actor.armor3_id]
                stat = ARMOR[item.id]
          when 4
                item = $data_armors[actor.armor4_id]
                stat = ARMOR[item.id]
          end
          actor.equip(i, 0) if !stat.nil? && !actor.equip_allowed?(stat)          
        end
  end
end
This post was last modified: 07-04-2012, 05:15 AM by Neoz Kaho.

[Image: 7wDGQYA.png][Image: 76561197983021669.png]
  
Users browsing this thread: 1 Guest(s)
Powered By MyBB, © 2002-2024 MyBB Group.
Made with by Curves UI.