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.
[VXA] Equipment Stat Variance

0 Members and 1 Guest are viewing this topic.

*
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
Equipment Stat Variance
Version: 1.0.0
Author: modern algebra
Date: 26 December 2012

Version History


  • <Version 1.0> 2012.12.26 - Original Release

Description


This script allows you to set it so that the stats of equipment can change between equipment of the same type. For example, the party could find two hand axes, one having 15 ATK the other having 18 ATK.

Features

  • Allows you to set it so that the stats of some of your equipment vary randomly.

Instructions

Paste the script into its own slot in the Script Editor, above Main but below Materials. It also must be below the Item Instances Base script.

Script


Code: [Select]
#==============================================================================
#    Equipment Stat Variance
#    Version: 1.0.0
#    Author: modern algebra (rmrk.net)
#    Date: 26 December 2012
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#   
#    This script allows you to set it so that the stats of equipment can change
#   between equipment of the same type. For example, the party could find two
#   hand axes, one having 15 ATK the other having 18 ATK.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    This script REQUIRES the Item Instances Base script, which is at:
#
#      http://rmrk.net/index.php/topic,47427.0.html
#   
#    Paste this script into its own slot in the Script Editor, above Main but
#   below Materials. It must also be below the Item Instances Base script.
#
#    To set it so that an equippable item varies in any particular stat, use
#   put of the following codes into the note field of the item:
#
#            \var_mhp[n]              \var_mat[n]
#            \var_mmp[n]              \var_mdf[n]
#            \var_atk[n]              \var_agi[n]
#            \var_def[n]              \var_luk[n]
#
#   where you replace n with the integer amount you want the stat to vary by.
#   Basically, the way the script works is that it will take a random number
#   between 0 and n and add it to the basic value for that equippable item that
#   you set in the database.
#
#  EXAMPLE:
#
#    If you have a hand axe with 15 ATK and 3 DEF, and you set the following
#   in its note field:
#
#      \var_atk[5]\var_def[2]
#
#   then any new instance of the hand axe will have between 15 and 20 ATK, and
#   between 3 and 5 DEF.
#==============================================================================

if $imported && $imported[:"MA_InstanceItemsBase 1.0.0"]

  $imported[:MA_ItemStatVariance] = true

  # Push the Variance code into the checks for instance items
  MA_INSTANCE_ITEMS_BASE[:regexp_array].push(/\\VAR_\S*?\[\s*\d+\s*\]/i)

#==============================================================================
# *** MAIIB_RPG_EquipItem
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - random_variance
#==============================================================================

module MAIIB_RPG_EquipItem
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Random Variance
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def random_variance
    @rand_vars = self.note.scan(/\\VAR_(\S*?)\[\s*(\d+)\s*\]/i) unless @rand_vars
    return @rand_vars
  end
end

#==============================================================================
# *** Game_IEquipItem
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - initialize
#    new method - eval_stat_variance
#==============================================================================

module Game_IEquipItem
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maisv_iniz_4ty5 initialize
  def initialize(*args)
    maisv_iniz_4ty5(*args) # Run Original Method
    data.random_variance.each { |stat, variance|
      eval_stat_variance(stat.downcase.to_sym, variance.to_i) }
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Evaluate Stat Variance
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def eval_stat_variance(stat, variance)
    stat = :"m#{stat}"if stat == :hp || stat == :mp
    ix = [:mhp, :mmp, :atk, :def, :mat, :mdf, :agi, :luk].index(stat)
    self.params[ix] = data.params[ix] + rand(variance + 1) if ix
  end
end

else
  msgbox("Item Stat Variance could not be installed because you either do not have Instance Items Base or because you have that script placed below the Item Stat Variance script.")
end

Credit


  • modern algebra

Support


Please post in this topic at RMRK.net if you have any questions, suggestions, error reports, or comments about this script. Please do not message me privately, as it is more efficient and useful to answer any concerns you have in the topic where others may benefit from our correspondence.

Known Compatibility Issues

This script REQUIRES Item Instances Base in order to work.

Spoiler for Yanfly's Ace Equip Engine:
There is a small bug in Yanfly's Ace Equip Engine. Although it works functionally, when scrolling through instances of the same item, differences in stats will not be shown unless it is the first one you select after looking at some other item. ekomega investigated the problem and determined that all you need to do to fix this error is to find line 1098 in Yanfly's script, which should look like this:

Code: [Select]
#--------------------------------------------------------------------------
  # overwrite method: update_help
  #--------------------------------------------------------------------------
  def update_help
    super
    return if @actor.nil?
    return if @status_window.nil?
   return if @last_item == item
    @last_item = item
    temp_actor = Marshal.load(Marshal.dump(@actor))
    temp_actor.force_change_equip(@slot_id, item)
    @status_window.set_temp_actor(temp_actor)
  end

All you need to do is comment out or delete the following line:

Code: [Select]
return if @last_item == item

As far as I know, that should not cause any problems re: lag, since I don't believe that method is called except when the help window is likely to require updating. However, if deleting the line altogether makes you nervous, then you can replace it with:

Code: [Select]
return if @last_item.equal?(item)

Many thanks to ekomega for discovering and fixing this incompatibility.

Demo


I do not think a demo is necessary, but if you disagree then let me know.

Author's Notes


This is mostly just a sample script to demonstrate one way in which scripters can use the modules in Item Instances Base to help create their script.

Terms of Use


I adopt RMRK's default Terms of Use.
« Last Edit: December 29, 2012, 07:05:09 PM by modern algebra »

**
Rep:
Level 50
RMRK Junior
Thanks for the script!

I'm using Yanfly's Ace Equip Engine, and when I am trying to select an item in the Equip menu, it doesn't display the accurate stats of each item when there are multiple copies.  When equipped, the stat is accurate and variable, as desired.  But in the selection menu, it only displays the stat increase for the item that was first viewed.  I doucle-checked and I am sure that Ace Equip Engine is the problem, as the problem disappears without Ace Equip Engine installed.  Moving the scripts around, above and below, has no effect.
 
So for example, I have a list of 3 hand-axes, which have a stat variance, and some other weapons, like so:

weapon1
hand-axe1
hand-axe2
hand-axe3
weapon3

When I move down from weapon1 to hand-axe1 (by moving the cursor, pushing the down button, etc.), it will show the stat difference between weapon1 and hand-axe1 normally.  But when I move down from hand-axe1 to hand-axe 2, it will still show the stat values of hand-axe1, even if hand-axe2 is different.  Same for moving down to hand-axe3.  But when I get down to weapon3, weapon3 shows normally.  Then when I scroll back up to hand-axe 3 from weapon3, it shows the stats for hand-axe3 normally.  And when I move from hand-axe3 up to hand axe-2, it shows hand-axe3's stats even if hand-axe2 is different. 

So there's an issue, for me, on proper display of stats that depends on scrolling between items and it only displaying the stats for the first variable item that was highlighted in the sequence of variable items, but it properly displays the item stats when scrolling between a non-variable and a variable item.  It does not happen when scrolling between two different variable item types, such as hand-axes and battle-axes (both of which having varying stats).

I am not sure if you do compatability or anything, but if you could point me in the right direction on how to solve this, that would be great enough.  Thanks!


EDIT UPDATE:  Okay, in Ace Equip Engine, starting at line 1016, is class Window_EquipItem < Window_ItemList .  I figured the problem was here, in how it identified items, etc.

Further down in this section, starting at line 1098 is:

Code: [Select]
#--------------------------------------------------------------------------
  # overwrite method: update_help
  #--------------------------------------------------------------------------
  def update_help
    super
    return if @actor.nil?
    return if @status_window.nil?
   return if @last_item == item
    @last_item = item
    temp_actor = Marshal.load(Marshal.dump(@actor))
    temp_actor.force_change_equip(@slot_id, item)
    @status_window.set_temp_actor(temp_actor)
  end

This seemed like a good place to look, because the problem seemed to be the window wasn't updating properly.  I thought the problem was with the line "return if @last_item == item"  because the script is not configured to properly tell if the item really is new with the new database ids, and maybe the window wasn't updating because it thought the items were the same.  So I commented that line out to "# return if @last_item == item", and it solved the problem.

This is a question for an advanced scripter -- I'm not sure why Yanfly would be checking to see if the new item is the same as the old item, since there isn't really a way to scroll between the same item twice (unless you write a script that differentiates them, like item stat variance), and even if you did scroll between the same item twice, why not just update anyway?   It would be great if someone could try and maybe explain this?  Or maybe I have no idea what I'm talking about and stumbled on a solution by accident.  Are there any repercussions to my change?

Anyway, problem solved (hopefully without introducing another error).  FYI for others who experience a similar issue.
« Last Edit: December 27, 2012, 06:57:54 PM by ekomega »

*
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
Thanks for doing all that. That was a very thorough troubleshooting, and I am impressed that you persisted and solved the problem.

As for your question, I suspect Yanfly was being careful and thinking that update_help is called every frame. If that's the case, then without that check, the window will refresh every frame, even when the cursor is not moving. As such, the purpose of the check was probably to reduce lag.

But my understanding of the structure is that update_help is only called at specific times, so I think you should be fine by just commenting it out.

**
Rep:
Level 50
RMRK Junior
Thanks for the reply.  I didn't notice any lag, so I guess it's a non-issue. 

Also, thanks for the compliment.  I tried to be thorough at first because if I'm asking for help, I should clearly explain what the problem is.  And then I followed through in case I didn't know what I was doing, and someone had to follow my logic and figure out how I messed up  ;).  I didn't think I'd be able to figure it out on my own.

I've seen plenty of posts by people with no posting history where they ask really short questions that are incredibly demanding, and I don't want to be that guy.  And... I'm an engineer.  :zwink:

*
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, it's certainly appreciated! :)

*
Rep: +0/-0Level 55
RMRK Junior
Great script! It's be nice if there was a way to include the actual (post-variance) stats in item descriptions through a text code or something in your special message codes script.