VXA SCRIPTING ISSUE
Posts
Pages:
1
I'm curious how this works and how to manipulate it properly.
As I understand it, when you call Game_BattlerBase#xparam(id) it returns whatever it gets from that line above. Normally I thought it would need to be
but it seems as though the 'return' part is no longer necessary in VX Ace (and possibly VX too, I didn't script much with it.)
I want to change this slightly, so that the value returned is whatever comes from features_sum(FEATURE_XPARAM, xparam_id) plus another value. I want to do this without just overwriting the existing code.
What I have right now is
I know 'super' will call the code from the method in the parent class (or in this case, the parent of the parent class) but how do I use that information and add to it? Can I do something as simple as
or
Any help would be appreciated. VXAce may be more streamlined in code but my unfamiliarity with it is causing all sorts of road blocks for me.
class Game_BattlerBase def xparam(xparam_id) features_sum(FEATURE_XPARAM, xparam_id) end end
As I understand it, when you call Game_BattlerBase#xparam(id) it returns whatever it gets from that line above. Normally I thought it would need to be
return features_sum(FEATURE_XPARAM, xparam_id)
I want to change this slightly, so that the value returned is whatever comes from features_sum(FEATURE_XPARAM, xparam_id) plus another value. I want to do this without just overwriting the existing code.
What I have right now is
class Game_Actor < Game_Battler def xparam(xparam_id) super #... end end
I know 'super' will call the code from the method in the parent class (or in this case, the parent of the parent class) but how do I use that information and add to it? Can I do something as simple as
super += 1
i = super i += 1
Any help would be appreciated. VXAce may be more streamlined in code but my unfamiliarity with it is causing all sorts of road blocks for me.
re super += 1: You can't assign a value to a keyword method like that. Either your target assignment must be a variable or a method that has a way of retrieving the result of the method and a method with an assignment operator at the end of it.
ie
This works because the += is functionally equivalent to
Which calls the func and func= methods. There is no super= method and I don't think you can create one due to super being a reserved keyword.
The easiest way is just to return the result of super with
Or if you need to do seomthing more complex just store the result of super and do your arithmetic on it then then return it.
Also the return keyword being implied is new in Ace but not in VX (but it looks sloppy to me so I always explicitly state it)
ie
func += 5 def func return @x end def func=(value) return @x = value end
This works because the += is functionally equivalent to
func = func + 5
Which calls the func and func= methods. There is no super= method and I don't think you can create one due to super being a reserved keyword.
The easiest way is just to return the result of super with
return super + 1 + some_other_method(x, y)
Or if you need to do seomthing more complex just store the result of super and do your arithmetic on it then then return it.
i = super if i % 2 == 0 i++ else i += 2 end return i
Also the return keyword being implied is new in Ace but not in VX (but it looks sloppy to me so I always explicitly state it)
Thank you, GreatRedSpirit.
is exactly what I need. I just didn't know if super returned a value or not when return isn't explicit in the initial method.
return super + value
is exactly what I need. I just didn't know if super returned a value or not when return isn't explicit in the initial method.
Alright, I will post another issue I am having here in hopes you can give me a hand, GreatRedSpirit.
I'm currently running this code I made (with the notetag loading stuff 'borrowed' from Yanfly)
The code is working fine in all aspects, except the HP, MP, and TP aren't changing when the regenerate_hp/mp/tp functions are called.
I have Yanfly's Battle Engine installed so I can see Pop-ups, and the right values are being popped.
When I put
The first msgbox line prints "500" which is the correct initial HP
The second msgbox line prints "510" which is the correct HP after regen is applied (the notetag being used is <param hrg: +10>)
But the HP stat isn't adjusted in game, and when the regenerate_hp function is called again, it's 500 and 510 again (when it should be 510, 520)
Any help, GRS?
I'm currently running this code I made (with the notetag loading stuff 'borrowed' from Yanfly)
#============================================================================== # # ▼ Prexus Ace - Static Param Change # -- Last Updated: 2012.03.17 # -- Level: Normal # -- Requires: n/a # #============================================================================== $imported = {} if $imported.nil? $imported["PRX-StaticParamChange"] = true #============================================================================== # ▼ Updates # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # 2012.03.18 : Fixed Regen being affected as multiplier # 2012.03.17 : Initial draft finished # #============================================================================== # ▼ Introduction # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # This script adds functionality to 'Features' for static value increases. # It will allow you to have statistics changed by Actor, Class, Equipment, and # Status Effects be static values as opposed to percentages. # #============================================================================== # ▼ Instructions # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # To install this script, open up your script editor and copy/paste this script # to an open spot above Main. # # ----------------------------------------------------------------------------- # * Notetags # ----------------------------------------------------------------------------- # <param x: +y> # <param x: -y> # Add this notetag to an Actor, Class, Equipment, or Status Effect notetag and # replace x with one of the following parameters: # mhp (Max HP) # mmp (Max MP) # atk (Attack) # def (Defense) # mat (Magic Attack) # mdf (Magic Defense) # agi (Agility) # luk (Luck) # hrg (HP Regen) # mrg (MP Regen) # trg (TP Regen) # and replace y with any integer value. # You can have any number of these notetags for any number of parameter changes. # #============================================================================== # ▼ Compatibility # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # This script is made for RPG Maker VX Ace and designed to be as modular as # possible to avoid script conflicts. It is however possible that conflicts may # occur with other scripts that make changes/use of the Game_Actor class and its # parent classes (Game_Battler, Game_BattlerBase) # #============================================================================== module PRX module REGEXP module BASEITEM PARAM_MHP = /<(?:PARAM_MHP|param mhp):[ ]([\+\-]\d+)>/i PARAM_MMP = /<(?:PARAM_MMP|param mmp):[ ]([\+\-]\d+)>/i PARAM_ATK = /<(?:PARAM_ATK|param atk):[ ]([\+\-]\d+)>/i PARAM_DEF = /<(?:PARAM_DEF|param def):[ ]([\+\-]\d+)>/i PARAM_MAT = /<(?:PARAM_MAT|param mat):[ ]([\+\-]\d+)>/i PARAM_MDF = /<(?:PARAM_MDF|param mdf):[ ]([\+\-]\d+)>/i PARAM_AGI = /<(?:PARAM_AGI|param agi):[ ]([\+\-]\d+)>/i PARAM_LUK = /<(?:PARAM_LUK|param luk):[ ]([\+\-]\d+)>/i PARAM_HRG = /<(?:PARAM_HRG|param hrg):[ ]([\+\-]\d+)>/i PARAM_MRG = /<(?:PARAM_MRG|param mrg):[ ]([\+\-]\d+)>/i PARAM_TRG = /<(?:PARAM_TRG|param trg):[ ]([\+\-]\d+)>/i end # BASEITEM end # REGEXP end # PRX module DataManager #-------------------------------------------------------------------------- # alias method: load_database #-------------------------------------------------------------------------- class <<self; alias load_database_spc load_database; end def self.load_database load_database_spc load_notetags_spc end #-------------------------------------------------------------------------- # new method: load_notetags_spc #-------------------------------------------------------------------------- def self.load_notetags_spc groups = [$data_actors, $data_classes, $data_weapons, $data_armors, $data_states] for group in groups for obj in group next if obj.nil? obj.load_notetags_spc end end end end # DataManager class RPG::BaseItem #-------------------------------------------------------------------------- # public instance variables #-------------------------------------------------------------------------- attr_accessor :static_param #-------------------------------------------------------------------------- # common cache: load_notetags_spc #-------------------------------------------------------------------------- def load_notetags_spc @static_param = {} #--- self.note.split(/[\r\n]+/).each { |line| case line #--- when PRX::REGEXP::BASEITEM::PARAM_MHP @static_param[:MHP] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_MMP @static_param[:MMP] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_ATK @static_param[:ATK] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_DEF @static_param[:DEF] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_MAT @static_param[:MAT] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_MDF @static_param[:MDF] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_AGI @static_param[:AGI] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_LUK @static_param[:LUK] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_HRG @static_param[:HRG] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_MRG @static_param[:MRG] = $1.to_i when PRX::REGEXP::BASEITEM::PARAM_TRG @static_param[:TRG] = $1.to_i else next #--- end } # self.note.split end end # RPG::BaseItem class Game_Actor < Game_Battler #-------------------------------------------------------------------------- # ▼ combine exisiting param with static param change by id #-------------------------------------------------------------------------- def param(param_id) return super + static_param(param_id) end #-------------------------------------------------------------------------- # ▼ discover total static param change by id #-------------------------------------------------------------------------- def static_param(param_id) v = 0 case param_id when 0 # MHP feature_objects.each { |item| next unless item.static_param[:MHP]; v += item.static_param[:MHP]; } when 1 # MMP feature_objects.each { |item| next unless item.static_param[:MMP]; v += item.static_param[:MMP]; } when 2 # ATK feature_objects.each { |item| next unless item.static_param[:ATK]; v += item.static_param[:ATK]; } when 3 # DEF feature_objects.each { |item| next unless item.static_param[:DEF]; v += item.static_param[:DEF]; } when 4 # MAT feature_objects.each { |item| next unless item.static_param[:MAT]; v += item.static_param[:MAT]; } when 5 # MDF feature_objects.each { |item| next unless item.static_param[:MDF]; v += item.static_param[:MDF]; } when 6 # AGI feature_objects.each { |item| next unless item.static_param[:AGI]; v += item.static_param[:AGI]; } when 7 # LUK feature_objects.each { |item| next unless item.static_param[:LUK]; v += item.static_param[:LUK]; } end return v end #-------------------------------------------------------------------------- # ▼ discover total static xparam change by id #-------------------------------------------------------------------------- def static_xparam(xparam_id) v = 0 case xparam_id when 7 # HRG feature_objects.each { |item| next unless item.static_param[:HRG]; v += item.static_param[:HRG]; } when 8 # MRG feature_objects.each { |item| next unless item.static_param[:MRG]; v += item.static_param[:MRG]; } when 9 # TRG feature_objects.each { |item| next unless item.static_param[:TRG]; v += item.static_param[:TRG]; } end return v end #-------------------------------------------------------------------------- # ▼ Regenerate HP #-------------------------------------------------------------------------- def regenerate_hp super @result.hp_damage -= static_xparam(7) # HRG self.hp += static_xparam(7) # HRG end #-------------------------------------------------------------------------- # ▼ Regenerate MP #-------------------------------------------------------------------------- def regenerate_mp super @result.mp_damage -= static_xparam(8) # MRG self.hp += static_xparam(8) # MRG end #-------------------------------------------------------------------------- # ▼ Regenerate TP #-------------------------------------------------------------------------- def regenerate_tp super self.tp += static_xparam(9) # TRG end #-------------------------------------------------------------------------- # ▼ Regenerate all #-------------------------------------------------------------------------- def regenerate_all; super; end end # Game_Actor
The code is working fine in all aspects, except the HP, MP, and TP aren't changing when the regenerate_hp/mp/tp functions are called.
I have Yanfly's Battle Engine installed so I can see Pop-ups, and the right values are being popped.
When I put
#-------------------------------------------------------------------------- # ▼ Regenerate HP #-------------------------------------------------------------------------- def regenerate_hp super msgbox self.hp @result.hp_damage -= static_xparam(7) # HRG self.hp += static_xparam(7) # HRG msgbox self.hp end
The first msgbox line prints "500" which is the correct initial HP
The second msgbox line prints "510" which is the correct HP after regen is applied (the notetag being used is <param hrg: +10>)
But the HP stat isn't adjusted in game, and when the regenerate_hp function is called again, it's 500 and 510 again (when it should be 510, 520)
Any help, GRS?
... NEVERMIND. Fuck I am stupid. The mistake is right fucking there -_-.
It's not a logic mistake, I just have the MP regen affected HP instead of MP, and it just happens to be a negating number so I don't see an effect change.
Thanks anyways, GRS. If you do see the code and see anything that I should be changing, let me know. <3
It's not a logic mistake, I just have the MP regen affected HP instead of MP, and it just happens to be a negating number so I don't see an effect change.
Thanks anyways, GRS. If you do see the code and see anything that I should be changing, let me know. <3
The biggest problem is that you didn't put your code in code ruby tags! This needs to be remedied next time you post a script. It looks like the @hp_damage -= and the self.hp += means you're applying the regen twice but I don't remember all the stuff VX does with @hp_damage (and Ace even less) so I could be wrong. Otherwise it looks good
Pages:
1