MV Change Battlers Parameters With a Damage Formula

I am trying to make a move that swaps the agility stat of the user and target

There exists a "a.setMp()" but nothing for setting some of the other parameters...


Looking in the rpg_objects.js i find the code

Game_BattlerBase.prototype.setMp = function(mp) {
this._mp = mp;
this.refresh();
};

but when i add something like this under it it doesn't work...

Game_BattlerBase.prototype.setAgi = function(agi) {
this.param(6) = agi;
this.refresh();
};

How do i make a function for setting agility in the damage formula?
I am trying to make a move that swaps the agility stat of the user and target

There exists a "a.setMp()" but nothing for setting some of the other parameters...


Looking in the rpg_objects.js i find the code

Game_BattlerBase.prototype.setMp = function(mp) {
this._mp = mp;
this.refresh();
};

but when i add something like this under it it doesn't work...

Game_BattlerBase.prototype.setAgi = function(agi) {
this.param(6) = agi;
this.refresh();
};

How do i make a function for setting agility in the damage formula?
The simple answer is, you don't.

The setMp function is setting a value to a object that is already just a number.

this.param() is a function, not a value, and the function returns a value, specifically the total value of the param called (6). You can't set it equal to something else because it's only job is to report to you (or whatever is asking) what the value of param(6) is. In order to change that value, you'd need to change the function that this.param(paramId) does in the first place, to check for a state, or something, and return a specific value if that state is present, or the original value if it is not.

In order for that to work, you'd need to set the state on the battler when the skill is cast, and use something like YEP_BuffsStatesCore to add a variable to the battler to set what their agi should be, and then alias the this.param(paramId) function to return that value instead of the real value if the state is present.

This is an overly complicated way to do it, as well. The system was not made to set base parameters to flat values. One of yanfly's plugins does allow you to have states that raise and lower params by a flat amount, and you could probably use that to do a math calculation and then modify agi by a specific amount to swap the stats of two battlers, but then you'd need to think about what happens in situations where the state is removed, the battler's stats change, or someone died, as messing this up could result in the target never recovering their original agi values, for example.
The simple answer is, you don't.

The setMp function is setting a value to a object that is already just a number.

this.param() is a function, not a value, and the function returns a value, specifically the total value of the param called (6). You can't set it equal to something else because it's only job is to report to you (or whatever is asking) what the value of param(6) is. In order to change that value, you'd need to change the function that this.param(paramId) does in the first place, to check for a state, or something, and return a specific value if that state is present, or the original value if it is not.

In order for that to work, you'd need to set the state on the battler when the skill is cast, and use something like YEP_BuffsStatesCore to add a variable to the battler to set what their agi should be, and then alias the this.param(paramId) function to return that value instead of the real value if the state is present.

This is an overly complicated way to do it, as well. The system was not made to set base parameters to flat values. One of yanfly's plugins does allow you to have states that raise and lower params by a flat amount, and you could probably use that to do a math calculation and then modify agi by a specific amount to swap the stats of two battlers, but then you'd need to think about what happens in situations where the state is removed, the battler's stats change, or someone died, as messing this up could result in the target never recovering their original agi values, for example.
Well that's a disappointment.

I'll look at YEP_BuffsStatesCore
So the simple answer is you don't need a plugin - MV supports changing the values of parameters, obviously, as they change when you level up and such.

The function to do so is addParam(paramID, value) where paramID is starting at 0 and going in order, such as you see the parameters in the class tab of the database; and value is the amount you want to add to the parameter.

So, looking across the parameters in the class tab, Agility is 6. Then you would do the swapping. So, something like:
Code:
var temp=a.paramBase(6);
a.addParam(6, b.paramBase(6)-temp);
b.addParam(6, temp-b.paramBase(6));
That should result in swapping the base parameter values of the attacker and defender.

However, I encourage you to consider what Ramza said and reconsider this into some kind of state or other effect - altering the permanent parameters on the fly (and repeatedly, via skill use) can have unintended and destructive effects on your game.
So the simple answer is you don't need a plugin - MV supports changing the values of parameters, obviously, as they change when you level up and such.

The function to do so is addParam(paramID, value) where paramID is starting at 0 and going in order, such as you see the parameters in the class tab of the database; and value is the amount you want to add to the parameter.

So, looking across the parameters in the class tab, Agility is 6. Then you would do the swapping. So, something like:
Code:
var temp=a.paramBase(6);
a.addParam(6, b.paramBase(6)-temp);
b.addParam(6, temp-b.paramBase(6));
That should result in swapping the base parameter values of the attacker and defender.

However, I encourage you to consider what Ramza said and reconsider this into some kind of state or other effect - altering the permanent parameters on the fly (and repeatedly, via skill use) can have unintended and destructive effects on your game.
I think this is going to be the best answer I am going to get.

Original thread: https://forums.rpgmakerweb.com/threads/change-battlers-parameters-with-a-damage-formula.139934/