RPG Maker MV: Modified Yanfly T&T (Roaming Mend + Holy Prism Splice)

I was working on a skill for my game today which essentially is a single target spell for the healer that can be used against an enemy to deal damage or on an ally to heal hp. I wanted to do something unique for that spell as well so I decided to apply a state to it. I wanted it to thematically make sense, it should have different effects for enemies and for allies.

Below is the state I came up with by splicing together Yanfly's Roaming Mend State with some of the code from Holy Prism.

It took me around two hours to get this working properly as I am relatively inexperienced with JS. I thought I'd share it with others, I know many of you could probably figure out how to do this much more rapidly and efficiently than me but I still felt like sharing.

Anyways if you want to use it in your game just create a state (remove on battle end and remove some number of turns) and paste the code below into the state notebox.

How it works: The state is applied to an enemy or ally. When applied to an enemy if that enemy takes damage all enemies take damage and the state is moved from that enemy to a random party ally. If that ally then takes damage the whole party is healed and the state is moved to a random enemy where the original effect takes place. I have it set up with 3 charges so that one effect happens twice and the other once.

What you Should Change: Change anything in the code below that is bolded to whatever suits your game.

Who to Thank: Yanfly as this is all his code, just modified and spliced together.

Required Plugins: YEP Battle Engine Core, YEP Damage Core, YEP Skill Core, YEP Buffs and States Core, YEP Selection Control



-------------------------State Code Below-------------------------------

<Custom Apply Effect>

// Set the default charges to 3 .

this._roamingMendCharges = 3;

// Calculate the amount of the heal.

this._roamingMendHeal = origin.mdf + (Math.ceil(origin.mmp * .1));

// Sets the counter to display the charges.

this.setStateCounter(stateId, 'x' + 3);

</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 React 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;

//Check if target is actor (If not actor run this)
if (!b.isActor()) {

var members = target.friendsUnit().aliveMembers();

// Loop through those members.

for (var i = 0; i < members.length; ++i) {

// Get the current member.

var member = members;

// If the member exists...

if (member) {

// Modify the damage received relative to the Holy element.

var dmg = -heal * member.elementRate(12);

// Make the member take damage.

member.gainHp(dmg);

// Start the damage popup.

member.startDamagePopup();

// Clear the results.

member.clearResult();

// Start an animation.

member.startAnimation(171);

// Check if the member is dead.

if (member.isDead()) {

// If it is, make it collapse.

member.performCollapse();

}

}

}

var charges = target._roamingMendCharges - 1;

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.opponentsUnit().aliveMembers().length; ++i) {

// Set the potential variable to the current looped ally.

var potential = target.opponentsUnit().aliveMembers();

// If the ally doesn't exist, move onto the next.

if (!potential) 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(171);

// 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);

}

}


//If Actor Run this
} else {

var members = target.friendsUnit().aliveMembers();

// Loop through each member.

for (var i = 0; i < members.length; ++i) {

// Get the current member.

var member = members;

// If the member exists...

if (member) {

// ...then the member recovers HP.

member.gainHp(heal);

// Start the damage popup.

member.startDamagePopup();

// Clear the results.

member.clearResult();

// Start an animation.

member.startAnimation(41);

}

}

// 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.opponentsUnit().aliveMembers().length; ++i) {

// Set the potential variable to the current looped ally.

var potential = target.opponentsUnit().aliveMembers();

// If the ally doesn't exist, move onto the next.

if (!potential) 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 React Effect>

Original thread: https://forums.rpgmakerweb.com/threads/rpg-maker-mv-modified-yanfly-t-t-roaming-mend-holy-prism-splice.88233/