Mysticphoenix   04-23-2014, 12:09 PM
#1
Author : Ayene
Website : http://forums.rpgmakerweb.com/index.php?...ements-xp/

Introduction
สคริปนี้จะทำให้เรากำหนด Requirement ของอาวุธ/ชุดเกราะได้ ว่าจะสวมใส่ได้เมื่อเลเวลเท่าไร, STR เท่าไร, INT เท่าไร, DEX เท่าไร, AGI เท่าไร, Level เท่าไร, ไปจนถึงกำหนดว่าต้องมีสกิลอะไรด้วย (สกิล Axe Mastery, Bow Mastery) นอกจากนั้น ระบบยังสามารถแสดงความต้องการได้ว่า stat ใดต่ำไป หรือต้องการ skill ใด ได้อีกด้วย

วิธีใช้
การตั้งค่านั้นง่ายมาก เพียงใส่โค้ดที่มีรูปแบบดังต่อไปนี้ไว้ที่ส่วนการตั้งค่าของสคริป

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

ตัวอย่าง
ถ้าอยากให้ อาวุธหมายเลข 2 สวมใส่ได้ที่ level 6 และต้องมี Max HP 120 เป็นอย่างต่ำ, STR 40 เป็นอย่างต่ำ, INT 70 เป็นอย่างต่ำ ก็ใส่โค้ดดังนี้
WEAPON [2] = [6, 120, 0, 40, 0, 0, 70, []]

ต่อไปเป็นตัวอย่างชุดเกราะ ถ้าอยากให้ เกราะหมายเลข 3 สวมใส่ได้เมื่อมี DEX 70 และต้องการ skill หมายเลข 10 และ 15 ก็ใส่โค้ดดังนี้

ARMOR [3] = [0, 0, 0, 0, 70, 0, 0, [10, 15]]

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) && [email protected]_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::<img src='http://forums.rpgmakerweb.com/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='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

เวอร์ชัน VX ก็มีนะ http://www.rpgmakervx.net/index.php?showtopic=54164
This post was last modified: 04-23-2014, 02:40 PM by Mysticphoenix.

[Image: webboard%20signature1_zpskhtut2jg.png]
การทำอาหารที่อร่อยที่สุด และเดือดร้อนชาวบ้านมากที่สุด กำลังจะเริ่มขึ้น
  
Users browsing this thread: 1 Guest(s)
Powered By MyBB, © 2002-2024 MyBB Group.
Made with by Curves UI.