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 (http://rmrk.net/index.php/topic,47427.0.html) script.
Script
#==============================================================================
# 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
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 (http://rmrk.net/index.php/topic,47427.0.html) in order to work.
[spoiler=Yanfly's Ace Equip Engine]
There is a small bug in Yanfly's Ace Equip Engine (http://yanflychannel.wordpress.com/rmvxa/gameplay-scripts/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 (http://rmrk.net/index.php/topic,47428.msg539086.html#msg539086) 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:
#--------------------------------------------------------------------------
# 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)
endAll you need to do is comment out or delete the following line:
return if @last_item == itemAs 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:
return if @last_item.equal?(item)Many thanks to ekomega for discovering and fixing this incompatibility.
[/spoiler]
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 (http://rmrk.net/index.php/topic,47427.0.html) to help create their script.
Terms of Use
I adopt RMRK's default Terms of Use (http://rmrk.net/index.php/topic,45481.0.html).
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:
#--------------------------------------------------------------------------
# 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.
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.
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:
Well, it's certainly appreciated! :)
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.