Jay19

Veteran
Veteran
Joined
Dec 27, 2018
Messages
72
Reaction score
26
First Language
Français
Primarily Uses
N/A
Hello,
Once again I need help modifying a "Tips & Tricks" from Yanfly. But this time, it's more about solving a problem.
This is "Roaming Mend" which is a status effect, and whose definition given is as follows: When an ally affected by Roaming Mend is struck, it will heal that ally and then move to another random ally with the same effect. Roaming Mend can heal up to 4 allies this way.
Here's the spoiler for the state code:

Code:
<Custom Apply Effect>
// Set the default charges to 4.
this._roamingMendCharges = 4;
// Calculate the amount of the heal.
this._roamingMendHeal = user.mhp * 0.12;
this._roamingMendHeal = Math.round(this._roamingMendHeal);
// Sets the counter to display the charges.
this.setStateCounter(stateId, 'x' + 4);
</Custom Apply Effect>

<Custom Remove Effect>
// Removes the stored charge information.
this._roamingMendCharges = undefined;
// Removes the stored heal information.
this._roamingMendHeal = undefined;
</Custom Remove Effect>

<Custom Deselect Effect>
// Check if the target took HP damage and has more than 1 HP.
if (this.isHpEffect() && this.isDamage() && target.hp > 0) {
  // Get the stored healing value. If none, it will default to 1.
  var heal = target._roamingMendHeal || 1;
  // Plays an animation on the target.
  target.startAnimation(243);
  // Heals the target's HP.
  target.gainHp(heal);
  // Starts the healing popup on the target.
  target.startDamagePopup();
  // Clears the target's results.
  target.clearResult();
  // Calculates the next charge amount.
  var charges = target._roamingMendCharges - 1;
  // Removes the state from the target.
  target.removeState(stateId);
  // Check if there are more than 0 charges.
  if (charges > 0) {
    // Create an empty array.
    var members = [];
    // Loop through each of the target's alive allies.
    for (var i = 0; i < target.friendsUnit().aliveMembers().length; ++i) {
      // Set the potential variable to the current looped ally.
      var potential = target.friendsUnit().aliveMembers()[i];
      // If the ally doesn't exist, move onto the next.
      if (!potential) continue;
      // If the ally is the same as the target, move onto the next.
      if (potential === target) continue;
      // If the ally is already affected by a different Roaming Mend effect, move onto the next.
      if (potential.isStateAffected(40)) continue;
      // If the ally's HP is at zero (hence dead), move onto the next.
      if (potential.hp <= 0) continue;
      // Now that all checks have been cleared, put the potential ally into the members array.
      members.push(potential);
    }
    // Get a random member of the members array.
    var member = members[Math.floor(Math.random() * members.length)];
    // Check if the random member exists.
    if (member) {
      // Play an animation on that random member.
      member.startAnimation(244);
      // Move the Roaming Mend state onto that random member.
      member.addState(stateId);
      // The random member's charges get updated.
      member._roamingMendCharges = charges;
      // The healing amount gets transfered over to the random member.
      member._roamingMendHeal = heal;
      // Sets the charge counter for the random member.
      member.setStateCounter(stateId, 'x' + charges);
    }
  }
}
</Custom Deselect Effect>

Now here is my problem. The effect normally triggers when the character suffers a single target attack.
But there is a big problem when the character suffers an attack that affects the whole group. The effect sometimes triggers several times, and on several different allies.
It's like the attack didn't hit all the characters simultaneously, but hit them one by one.
Suddenly, the effect has time to bounce on another ally and retrigger again.
Sometimes it does on 2 or 3 characters, sometimes everything happens normally. I guess it depends on the order in which the characters are hit. But I remind you that we are talking about a multi-target attack. All characters must be hit at the same time, and the effect must only trigger once.
Anyone have a solution?
 

ShadowDragon

Realist
Veteran
Joined
Oct 8, 2018
Messages
6,021
Reaction score
2,356
First Language
Dutch
Primarily Uses
RMMV
I dont know much, but this part can be wrong either:
JavaScript:
<Custom Apply Effect>
// Set the default charges to 4.
this._roamingMendCharges = 4;
// Calculate the amount of the heal.
this._roamingMendHeal = user.mhp * 0.12;
this._roamingMendHeal = Math.round(this._roamingMendHeal);
// Sets the counter to display the charges.
this.setStateCounter(stateId, 'x' + 4);
</Custom Apply Effect>

which is maybe better this way?

JavaScript:
<Custom Apply Effect>
// Set the default charges to 4.
this._roamingMendCharges = 4;
// Calculate the amount of the heal.
this._roamingMendHeal = Math.round(user.mhp * 0.12);
// Sets the counter to display the charges.
this.setStateCounter(stateId, 'x' + 4);
</Custom Apply Effect>

as you use 2x "this._roamingMendHeal" which I dont know what
the exact impact is on it.

if you can target up to 4 actors, how many actors do you have in party?
or can the same actor get it twice in a random choice? as the random
actor isn't specified in the apply effect?
 

Jay19

Veteran
Veteran
Joined
Dec 27, 2018
Messages
72
Reaction score
26
First Language
Français
Primarily Uses
N/A
Thank you for your answer, unfortunately the modification does not seem to change anything.
I realize that I had to modify the basic formula for a reason that is no longer relevant, so I am giving you the basic formula. But that doesn't change anything either.
To answer your question, there can be 6 players in total in combat. After doing tests, we would say that the same actor can receive the state several times (or in any case, the caster seems to be able to obtain the state several times)

Code:
<Custom Apply Effect>
// Set the default charges to 4.
this._roamingMendCharges = 4;
// Calculate the amount of the heal.
this._roamingMendHeal = origin.mat * 4;
// Sets the counter to display the charges.
this.setStateCounter(stateId, 'x' + 4);
</Custom Apply Effect>

<Custom Remove Effect>
// Removes the stored charge information.
this._roamingMendCharges = undefined;
// Removes the stored heal information.
this._roamingMendHeal = undefined;
</Custom Remove Effect>

<Custom Deselect Effect>
// Check if the target took HP damage and has more than 1 HP.
if (this.isHpEffect() && this.isDamage() && target.hp > 0) {
  // Get the stored healing value. If none, it will default to 1.
  var heal = target._roamingMendHeal || 1;
  // Plays an animation on the target.
  target.startAnimation(45);
  // Heals the target's HP.
  target.gainHp(heal);
  // Starts the healing popup on the target.
  target.startDamagePopup();
  // Clears the target's results.
  target.clearResult();
  // Calculates the next charge amount.
  var charges = target._roamingMendCharges - 1;
  // Removes the state from the target.
  target.removeState(stateId);
  // Check if there are more than 0 charges.
  if (charges > 0) {
    // Create an empty array.
    var members = [];
    // Loop through each of the target's alive allies.
    for (var i = 0; i < target.friendsUnit().aliveMembers().length; ++i) {
      // Set the potential variable to the current looped ally.
      var potential = target.friendsUnit().aliveMembers()[i];
      // If the ally doesn't exist, move onto the next.
      if (!potential) continue;
      // If the ally is the same as the target, move onto the next.
      if (potential === target) continue;
      // If the ally is already affected by a different Roaming Mend effect, move onto the next.
      if (potential.isStateAffected(stateId)) continue;
      // If the ally's HP is at zero (hence dead), move onto the next.
      if (potential.hp <= 0) continue;
      // Now that all checks have been cleared, put the potential ally into the members array.
      members.push(potential);
    }
    // Get a random member of the members array.
    var member = members[Math.floor(Math.random() * members.length)];
    // Check if the random member exists.
    if (member) {
      // Play an animation on that random member.
      member.startAnimation(97);
      // Move the Roaming Mend state onto that random member.
      member.addState(stateId);
      // The random member's charges get updated.
      member._roamingMendCharges = charges;
      // The healing amount gets transfered over to the random member.
      member._roamingMendHeal = heal;
      // Sets the charge counter for the random member.
      member.setStateCounter(stateId, 'x' + charges);
    }
  }
}
</Custom Deselect Effect>
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,024
Reaction score
3,194
First Language
English
Primarily Uses
RMMV
It's like the attack didn't hit all the characters simultaneously, but hit them one by one.
Because that is exactly what happens. There's no such thing as hitting simultaneously, every battler affected by an attack has all the effects of the attack resolved - how would the game know who to skip some effects for?

I dont know much, but this part can be wrong either:
I don't see how you changed anything except simply combining the two operations. That doesn't make any difference, except having one less line of code (which is a bit more efficient, but the original wasn't wrong in any way).

Anyone have a solution?
Try this. Set aside a game switch for this and then do:
Code:
<Custom Deselect Effect>
if (!$gameSwitches.value(X))
{
    // Put all the original code in here
    $gameSwitches.setValue(X, true);
}
</Custom Deselect Effect>

where X is the ID of the switch you want to use.

Then you need Yanfly's Auto Passive States. Make an empty state with no icon and put in its notetag:
Code:
<Custom Action End Effect>
$gameSwitches.setValue(X, false);
</Custom Action End Effect>

Then use the <Passive State: Y> where Y is the ID of that state, and put that in each enemy's notetags. That should make the roaming mend only trigger once per action.
 

Jay19

Veteran
Veteran
Joined
Dec 27, 2018
Messages
72
Reaction score
26
First Language
Français
Primarily Uses
N/A
Great idea you had. It works as I want it to. Thanks a lot.
For those who are interested, I just add the idea of giving the "Y" state to allied characters so as not to create a bug in the event of "confused" or "charmed" characters (if these states exist in your game).
Thanks again for your help ATT_Turan and ShadowDragon
 

Latest Threads

Latest Profile Posts

Variation two of my nameless protagonist- now with color!!
WIN_20220815_21_48_46_Pro.jpg
thoughts?
Fun question - how do you manage the scope of your projects? All of my projects seem to balloon until they pop and they are suddenly nonexistent!
no I did not just have to write a song three different times because my music software doesn't support tempo changes!!
I WILL defeat this demonic USB connection notification bug
ScreenShot_8_15_2022_6_22_24.png
Mike trying to dodge the Memory Pawns invading Bantam Street. I like how the filters I used on the map almost make it look like the street is wet in a sense.

Forum statistics

Threads
124,568
Messages
1,164,457
Members
163,387
Latest member
nicklish
Top