RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[SOLVED][VXA] Item/Weapon/Armor/Skill Extra Params and S Params

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 89
How would I reference the ex-param and sp-params of an item/weapon/armor/skill?
Spoiler for:
Specifically, I am trying to modify the Yanfly Engine Ace scripts, Yanfly Item Menu.

If there is a way to access xparams already in YEA, can someone tell me how to do that? Otherwise, what would the best way to go about accessing item/weapon/armor/skill extra-param and s-param values? Would defining something like $item.params[param_id] for xparams and sparams be possible, or would something else be needed?

(I also asked at http://yanflychannel.wordpress.com/rmvxa/menu-scripts/ace-item-menu/#comment-5948)

Solved Code (Requires both optional YEA scripts and MA's script below placed above the item menu script). Note the following was optimized for 1028x768 resolution VXA project.

Spoiler for:
Code: [Select]
module YEA
  module ITEM
   
    # The following adjusts the vocabulary used for each X Param.
    XPARAMS_LIST = [
      "Hit Rate",       #:hit,
      "Evasion",        #:eva,
      "Critical Hit",   #:cri,
      "Critical Evade", #:cev,
      "Magic Evasion",  #:mev,
      "Magic Reflect",  #:mrf,
      "Counter Rate",   #:cnt,
      "HP Regen",       #:hrg,
      "SP Regen",       #:mrg,
      "EP Regen",       #:trg,
    ]

    # The following adjusts the vocabulary used for each S Param.
    SPARAMS_LIST = [
      "Target Rate",    #:tgr,
      "Guard Rate",     #:grd,
      "Recovery",       #:rec,
      "Item Boost",     #:pha,
      "SP Cost Rate",   #:mcr,
      "TP Charge",      #:tcr,
      "Physical Damage",#:pdr,
      "Magical Damage", #:mdr,
      "Floor Damage",   #:fdr,
      "EXP Rate",       #:exr,
    ]

    # For YEA Parameters, not yet implemented.
    YPARAMS_LIST = [
      [:hcr, "HP Cost Rate"],    # Requires YEA - Skill Cost Manager
      [:tcr_y, "EP Cost Rate"],    # Requires YEA - Skill Cost Manager
      [:cdr, "Cooldown Rate"],   # Requires YEA - Skill Restrictions
      [:wur, "Warmup Rate"],     # Requires YEA - Skill Restrictions
    ]

  end # ITEM
end # YEA

#==============================================================================
# ? Window_ItemStatus
#==============================================================================

class Window_ItemStatus < Window_Base
 
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(dx, dy, item_window)
    super(dx, dy, Graphics.width - dx, fitting_height(8))
    @item_window = item_window
    @item = nil
    refresh
  end
 
  #--------------------------------------------------------------------------
  # update
  #--------------------------------------------------------------------------
  def update
    super
    update_item(@item_window.item)
  end
 
  #--------------------------------------------------------------------------
  # update_item
  #--------------------------------------------------------------------------
  def update_item(item)
    return if @item == item
    @item = item
    refresh
  end
 
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    reset_font_settings
    return draw_empty if @item.nil?
    contents.font.size = YEA::ITEM::STATUS_FONT_SIZE
    draw_item_image
    draw_item_stats
    draw_item_effects
  end
 
  #--------------------------------------------------------------------------
  # draw_empty
  #--------------------------------------------------------------------------
  def draw_empty
    colour = Color.new(0, 0, 0, translucent_alpha/2)
    rect = Rect.new(1, 1, 94, 94)
    contents.fill_rect(rect, colour)
    dx = 96; dy = 0
    dw = (contents.width - 96) / 4
    for i in 0...28
      draw_background_box(dx, dy, dw)
      dx = (dx >= (96 + (3 * dw))) ? 96 : dx + dw
      dy += line_height if dx == 96
    end
  end
 
  #--------------------------------------------------------------------------
  # draw_background_box
  #--------------------------------------------------------------------------
  def draw_background_box(dx, dy, dw)
    colour = Color.new(0, 0, 0, translucent_alpha/2)
    rect = Rect.new(dx+1, dy+1, dw-2, line_height-2)
    contents.fill_rect(rect, colour)
  end
 
  #--------------------------------------------------------------------------
  # draw_item_image
  #--------------------------------------------------------------------------
  def draw_item_image
    colour = Color.new(0, 0, 0, translucent_alpha/2)
    rect = Rect.new(1, 1, 94, 94)
    contents.fill_rect(rect, colour)
    if @item.image.nil?
      icon_index = @item.icon_index
      bitmap = Cache.system("Iconset")
      rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
      target = Rect.new(0, 0, 96, 96)
      contents.stretch_blt(target, bitmap, rect)
    else
      bitmap = Cache.picture(@item.image)
      contents.blt(0, 0, bitmap, bitmap.rect, 255)
    end
  end
 
  #--------------------------------------------------------------------------
  # draw_item_stats
  #--------------------------------------------------------------------------
  def draw_item_stats
    return unless @item.is_a?(RPG::Weapon) || @item.is_a?(RPG::Armor)
    dx = 96; dy = 0
    dw = (contents.width - 96) / 4
    for i in 0...8
      draw_equip_param(i, dx, dy, dw)
      dx = (dx >= (96 + (3 * dw))) ? 96 : dx + dw
      dy += line_height if dx == 96
    end
    # X Params
    for i in 0...10
      draw_ex_equip_param(i, dx, dy, dw, 1)
      dx = (dx >= (96 + (3 * dw))) ? 96 : dx + dw
      dy += line_height if dx == 96
    end
    # Y Params
    for i in 0...10
      draw_ex_equip_param(i, dx, dy, dw, 2)
      dx = (dx >= (96 + (3 * dw))) ? 96 : dx + dw
      dy += line_height if dx == 96
    end
  end
 
  #--------------------------------------------------------------------------
  # draw_equip_param
  #--------------------------------------------------------------------------
  def draw_equip_param(param_id, dx, dy, dw)
    draw_background_box(dx, dy, dw)
    change_color(system_color)
    draw_text(dx+4, dy, dw-8, line_height, Vocab::param(param_id))
    if $imported["YEA-EquipDynamicStats"]
      draw_percentage_param(param_id, dx, dy, dw)
    else
      draw_set_param(param_id, dx, dy, dw)
    end
  end

  #--------------------------------------------------------------------------
  # draw_ex_equip_param
  #--------------------------------------------------------------------------
  def draw_ex_equip_param(param_id, dx, dy, dw, which)
    draw_background_box(dx, dy, dw)
    change_color(system_color)
    text = YEA::ITEM::XPARAMS_LIST[param_id] if which == 1
    text = YEA::ITEM::SPARAMS_LIST[param_id] if which == 2
    draw_text(dx+4, dy, dw-8, line_height, text)
    draw_ex_param(param_id, dx, dy, dw, which)
  end

  #--------------------------------------------------------------------------
  # draw_ex_param
  #--------------------------------------------------------------------------
  def draw_ex_param(param_id, dx, dy, dw, which)
    if $imported["MA-Params"]
      value = @item.xparams[param_id] if which == 1
      value = @item.sparams[param_id] if which == 2
      change_color(param_change_color(value), value != 0)
      text = (value * 100).to_f.group + "%"
      text = "+" + text if value > 0
      draw_text(dx+4, dy, dw-8, line_height, text, 2)
      return 0
    end
  end
  #--------------------------------------------------------------------------
  # draw_percentage_param
  #--------------------------------------------------------------------------
  def draw_percentage_param(param_id, dx, dy, dw)
    if @item.per_params[param_id] != 0 && @item.params[param_id] != 0
      text = draw_set_param(param_id, dx, dy, dw)
      dw -= text_size(text).width
      draw_percent_param(param_id, dx, dy, dw)
    elsif @item.per_params[param_id] != 0 && @item.params[param_id] == 0
      draw_percent_param(param_id, dx, dy, dw)
    else
      draw_set_param(param_id, dx, dy, dw)
    end
  end
 

« Last Edit: November 04, 2012, 05:56:11 PM by noian »
>Current Project: Time Killer 2<
Description: Random, plotless project designed to kill spare time. No storyline, just a building to explore.

Status: Fascinated by how appalling the default database is balance wise.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, assuming that item is an instance of a subclass of RPG::BaseItem, then the following should collect all the x-params:

Code: [Select]
xparams = item.features.select { |feature| feature.code == 22 }

Each entry of the xparams array will be an RPG::BaseItem::Feature object, and you can retrieve its ID with the the #data_id method and its value with the #value method.

Similarly, you could get the sparams with:

Code: [Select]
sparams = item.features.select { |feature| feature.code == 23 }

If you wanted to create methods for it in RPG::BaseItem itself, you could do something like this:

Code: [Select]
class RPG::BaseItem
  def xparams
    ary = Array.new(10, 0)
    features.each { |feature|
      next unless feature.code == 22
      ary[feature.data_id] += feature.value
    }
    return ary
  end
  def sparams
    ary = Array.new(10, 0)
    features.each { |feature|
      next unless feature.code == 23
      ary[feature.data_id] += feature.value
    }
    return ary
  end
end

That code isn't tested, but when those methods are called they should give you an array with 10 entries, each corresponding to the value this item gives to the particular parameter, the indices for which are:

Quote
  # X Params
  0 # HIT  HIT rate
  1 # EVA  EVAsion rate
  2 # CRI  CRItical rate
  3 # CEV  Critical EVasion rate
  4 # MEV  Magic EVasion rate
  5 # MRF  Magic ReFlection rate
  6 # CNT  CouNTer attack rate
  7 # HRG  Hp ReGeneration rate
  8 # MRG  Mp ReGeneration rate
  9 # TRG  Tp ReGeneration rate
 
  # S Params
  0 # TGR  TarGet Rate
  1 # GRD  GuaRD effect rate
  2 # REC  RECovery effect rate
  3 # PHA  PHArmacology
  4 # MCR  Mp Cost Rate
  5 # TCR  Tp Charge Rate
  6 # PDR  Physical Damage Rate
  7 # MDR  Magical Damage Rate
  8 # FDR  Floor Damage Rate
  9 # EXR  EXperience Rate

**
Rep: +0/-0Level 89
Well, assuming that item is an instance of a subclass of RPG::BaseItem, then the following should collect all the x-params:

........removed long quote
Thanks a bunch modern algebra! You wouldn't happen to know any good documentation links to point me to? I have a bunch of more tweaks to make to YEA (also have to figure out how to get the 4 new YEA params to show up, but I probably need to brush up on documentation first to understand the YEA scripts so I know how they are defined).
« Last Edit: November 04, 2012, 05:49:50 PM by noian »
>Current Project: Time Killer 2<
Description: Random, plotless project designed to kill spare time. No storyline, just a building to explore.

Status: Fascinated by how appalling the default database is balance wise.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, the Help file is pretty decent for the default scripts, but as for Yanfly's scripts, the only documentation are the instructions that come with them. As far as I remember, they are usually fairly detailed.