Debuff in RMMV

darkcaesar

Villager
Member
Joined
Apr 29, 2013
Messages
10
Reaction score
1
First Language
Indonesian
Primarily Uses
Hello everyone, I'm trying to learn how to utilize javascript in RMMV


However I have a problem regarding increasing or decreasing parameter when using a skill.


For example, I would like to create a stacking decrease defense to the enemy.


Usually you just can do something like this, right?


target.def = target.def - someNumber;


However, that code does not work. The result is always NaN when I use console.log. I don't know what's wrong.


Then, I looked at one of Yanfly Tips and Tricks and I realize that he was using addDebuff.


I really want to know how debuff works in RMMV. This is my code:


<Custom Apply Effect>
target._stackingBreak = target._stackingBreak || 0;
target._stackingBreak += 1;
var defRatio = target._stackingBreak * 0.2;
var defReduct = Math.floor(defRatio * target.def);

//This is working (I use console.log to return the value)
var currentDefense = target.def - defReduct;

//These are not working (The target.def won't change its value)
target.def -= defReduct;
target.def = currentDefense;
</Custom Apply Effect>


The plugin I used is Yanfly Buff and State Core


Thanks for the help!
 

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,787
Reaction score
939
First Language
Chinese
Primarily Uses
N/A
It's because target.def is a getter rather than a setter:


def: { get: function() { return this.param(3); }, configurable: true },


This is how Game_BattlerBase.prototype.param actually works:


Game_BattlerBase.prototype.param = function(paramId) {
var value = this.paramBase(paramId) + this.paramPlus(paramId);
value *= this.paramRate(paramId) * this.paramBuffRate(paramId);
var maxValue = this.paramMax(paramId);
var minValue = this.paramMin(paramId);
return Math.round(value.clamp(minValue, maxValue));
};


Where Game_BattlerBase.prototype.paramRate and Game_BattlerBase.prototype.paramBuffRate are these:


Game_BattlerBase.prototype.paramRate = function(paramId) {
return this.traitsPi(Game_BattlerBase.TRAIT_PARAM, paramId);
};

Game_BattlerBase.prototype.paramBuffRate = function(paramId) {
return this._buffs[paramId] * 0.25 + 1.0;
};


Typically debuffs with paramId is implemented by setting Game_BattlerBase.prototype._buffs[paramId] as negative, which is done via Game_BattlerBase.prototype.decreaseBuff:


Game_BattlerBase.prototype.decreaseBuff = function(paramId) {
if (!this.isMaxDebuffAffected(paramId)) {
this._buffs[paramId]--;
}
};


Where Game_BattlerBase.prototype.isMaxDebuffAffected is this:

Code:
Game_BattlerBase.prototype.isMaxDebuffAffected = function(paramId) {
    return this._buffs[paramId] === -2;
};
 

darkcaesar

Villager
Member
Joined
Apr 29, 2013
Messages
10
Reaction score
1
First Language
Indonesian
Primarily Uses
It's because target.def is a getter rather than a setter:



def: { get: function() { return this.param(3); }, configurable: true },


This is how Game_BattlerBase.prototype.param actually works:



Game_BattlerBase.prototype.param = function(paramId) {
var value = this.paramBase(paramId) + this.paramPlus(paramId);
value *= this.paramRate(paramId) * this.paramBuffRate(paramId);
var maxValue = this.paramMax(paramId);
var minValue = this.paramMin(paramId);
return Math.round(value.clamp(minValue, maxValue));
};


Where Game_BattlerBase.prototype.paramRate and Game_BattlerBase.prototype.paramBuffRate are these:



Game_BattlerBase.prototype.paramRate = function(paramId) {
return this.traitsPi(Game_BattlerBase.TRAIT_PARAM, paramId);
};

Game_BattlerBase.prototype.paramBuffRate = function(paramId) {
return this._buffs[paramId] * 0.25 + 1.0;
};


Typically debuffs with paramId is implemented by setting Game_BattlerBase.prototype._buffs[paramId] as negative, which is done via Game_BattlerBase.prototype.decreaseBuff:



Game_BattlerBase.prototype.decreaseBuff = function(paramId) {
if (!this.isMaxDebuffAffected(paramId)) {
this._buffs[paramId]--;
}
};


Where Game_BattlerBase.prototype.isMaxDebuffAffected is this:



Game_BattlerBase.prototype.isMaxDebuffAffected = function(paramId) {
return this._buffs[paramId] === -2;
};
Ah I see, I didn't know that it was a getter.


So, how can I set the parameter then? 


Is it using the decreaseBuff function?
 

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,787
Reaction score
939
First Language
Chinese
Primarily Uses
N/A
Yes, it's the default approach.


The number of debuff levels you can have is defined by :


Game_BattlerBase.prototype.isMaxDebuffAffected


And the power of each debuff is defined by:

Code:
Game_BattlerBase.prototype.paramBuffRate
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,038
Members
137,568
Latest member
invidious
Top