RMMV Custom React Effect: in which order?

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
114
Reaction score
65
First Language
French
Primarily Uses
RMMV
Hello, my name is CHKNRAVE, and I'm obsessed with the Buffs and States Core. It really opens up what you can do with skills.

I'm using custom effects in most of my states, and I've been wondering something about the React effect.
It's a part that's really useful to change incoming damage, but what I want to know is in which order they're applied.
Does it have something to do with state ID? State priority? I have no idea.

Can somebody help me figure that out? Thanks in advance.

Bonus question: how do I point at the user of a skill, in the Custom Apply Effect of a state it just applied?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,936
Reaction score
1,386
First Language
EN
Primarily Uses
RMMZ
YEP Buffs & States Core iterates through the actor's states in order:
JavaScript:
Game_Action.prototype.onReactStateEffects = function(target, value) {
    var states = target.states();
    var length = states.length;
    for (var i = 0; i < length; ++i) {
      var state = states[i];
      if (!state) continue;
      value = this.reactStateEffects(target, state.id, value);
    }
    return value;
};
These states are typically sorted first descending by priority, then ascending by ID:
JavaScript:
Game_Battler.prototype.addState = function(stateId) {
    if (this.isStateAddable(stateId)) {
        if (!this.isStateAffected(stateId)) {
            this.addNewState(stateId);   // <- here!
            this.refresh();
        }
        this.resetStateCounts(stateId);
        this._result.pushAddedState(stateId);
    }
};

Game_BattlerBase.prototype.addNewState = function(stateId) {
    if (stateId === this.deathStateId()) {
        this.die();
    }
    var restricted = this.isRestricted();
    this._states.push(stateId);
    this.sortStates();   // <- here!
    if (!restricted && this.isRestricted()) {
        this.onRestrict();
    }
};

Game_BattlerBase.prototype.sortStates = function() {
    this._states.sort(function(a, b) {
        var p1 = $dataStates[a].priority;
        var p2 = $dataStates[b].priority;
        if (p1 !== p2) {
            return p2 - p1;   // <- higher-priority states bubble up
        }
        return a - b;   // <- equal priority states are sorted ascending by ID
    });
};

Game_BattlerBase.prototype.states = function() {   // references _states array
    return this._states.map(function(id) {
        return $dataStates[id];
    });
};
You can reference the battler who applied the state as origin. :)
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
114
Reaction score
65
First Language
French
Primarily Uses
RMMV
Thanks for the info, that's going to be super useful to change how final the final damage is.
So if I put a top-priority state that increases output damage, it'd apply first. But is there a way to make equipment add a certain counter to the state that handles base damage increase?
I feel like passive states from equipment would do the trick, but would I really need to do 1 state for every different damage increase?

Another idea: making a common event at the start of a fight that detects the equipment worn to add the right bonus damage counter to its wearer, which would be very tedious.
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,936
Reaction score
1,386
First Language
EN
Primarily Uses
RMMZ
I'm guessing (haven't tested) that you could put a passive state like this on every weapon you want to give bonus damage:
Code:
<Custom Battle Effect>
var count = parseInt(user.weapons()[0].meta.bonusDmg, 10) || 0;
user.setStateCounter(stateId, count);
</Custom Battle Effect>

<Custom Confirm Effect>
value += attacker.getStateCounter(stateId);
</Custom Confirm Effect>
Here I've made it reference a <bonusDmg: x> notetag on the first equipped weapon. The state counter gets set to that value and that value is used for additional damage whenever they land a skill.
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
114
Reaction score
65
First Language
French
Primarily Uses
RMMV
Of course, custom tags! Honestly, I thought detecting those would be a lot harder than that. According to the plugin's wiki article, the value variable seems to only appear in React, maybe readable (not writable) in Respond.
I already have a skill that increases final damage dealt by a percentage, and what I did was to make it apply another state in Confirm. That other state has a React effect that applies the damage increase based on what the user has for bonus damage, then removes itself from the target.

TL;DR of what's below: It works perfectly, now I'm pushing it further and showing how it's done in case somebody comes across this topic in the future.

Now I'm not very good at writing my own code, but I gave it a try anyway. I've got basic knowledge, Google, and clever copy-pasting skills.
JavaScript:
user.setStateCounter(20,0);
for (var i = 0; i < 5; i++) {
  user.addStateCounter(20, parseInt(user.equips()[i].meta.bonusDmg, 10) || 0);
}
These few lines in a Custom Battle Effect. What this modification does is that it doesn't just look for a bonusDmg tag in the user's weapon, but also in the rest of their equipment.

The state (#20 here) is set as a passive for all actors, it has an icon so I can see the counter for now, and it works like a charm.
I'm doing a battle test with 3 actors:
  • The first one has 3 pieces of equipment: a +10 bonusDmg weapon, a +15 bonusDmg off-hand, and a tagless piece of body equipment. His counter is 25 as planned.
  • The other 2 have no equipment at all, their counters are 0.
Fantastic. Let's push it further. The 2nd actor now has a skill that increases his own damage stat by 10 for 2 turns. No way around it, I'm using a state to properly apply the temporary effect.
<Custom Apply Effect>
user.addStateCounter(20, 10);
</Custom Apply Effect>

<Custom Leave Effect>
user.addStateCounter(20, -10);
</Custom Leave Effect>
And it works perfectly again.

Time to put this in practice, the variances are at 0%, the tags are added to make the damage increase work.
<Custom Confirm Effect>
value += user.getStateCounter(20);
</Custom Confirm Effect>
Well F me backwards, it's working as intended. So I've got another passive I can shorten into a single state, which is awesome.

Thank you so much for your help, and for what you taught me today.
 

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

Latest Threads

Latest Profile Posts

Thinking if i should post on the classifieds section...
Made another plugin showcase video! :kaojoy:
(Plugins and details inside the description of the YouTube video.) :LZScheeze:
Ami
Castle is my Biggest Fear :kaodes:. I just Managed make Part by Part (like the Entrance only),not the Entire Castle like in the RM Sample...
This video really speaks to me...

Stream will be live shortly with a session of the interactive text adenture! Feel free to drop by!

Forum statistics

Threads
104,369
Messages
1,005,888
Members
135,890
Latest member
vaobongdotbiz
Top