Ally take damage for party

Hello, everyone!!!! I have been looking thru the forums and other suggestions, but cant find an answer.

I am trying to make a state or skill that will let a actor take damage for the active party. I looked into it and "substitute" only works for actors that has less than 25% HP and the "Aura of sacrifice" doesnt work for RPG MZ and Visustella. Been looking into the scripting but unsure how to start it.

Summary:
- Need a skill/state that will let an actor take any damage done to party be taken by the actor that used the skill or the state is applied on
You can still use the Substitute trait.
You'd just have to change it from 25 to 100 percent.
If you aren't going to use the 25% one, editing the core script should be a simple matter.
"Aura of sacrifice" doesnt work for RPG MZ and Visustella
doesnt it? all the parts to it afaik have equivalents between VS battle core and the skills and states plugin. the aura effect itself comes from the latter and the notetags for running JS as a battler takes damage from a skill comes from the former. youd need to change the note tag names, but all of the js besides the startAnimation() at the end should still be usable as is
You can still use the Substitute trait.
You'd just have to change it from 25 to 100 percent.
If you aren't going to use the 25% one, editing the core script should be a simple matter.
I read on another forum MZ script editor automatically gets updated and you will need to readd it after each updates. Do you know how to edit it, never seen core scripts?

doesnt it? all the parts to it afaik have equivalents between VS battle core and the skills and states plugin. the aura effect itself comes from the latter and the notetags for running JS as a battler takes damage from a skill comes from the former. youd need to change the note tag names, but all of the js besides the startAnimation() at the end should still be usable as is
No idea which note tag your talking about. I see the variable which I know can be changed, but unsure which one your talking bout

<Custom React Effect>
// Check if the action dealt HP damage
if (this.isHpEffect() && value > 0) {
// Get the target's allies
var members = target.friendsUnit().aliveMembers();
// Get the Aura's Origin State ID
var auraOriginId = 246;
// Make the origin user undefined
var auraOriginUser = undefined;
// Loop through each member
for (var i = 0; i < members.length; ++i) {
// Get the currently looped member
var member = members;
// Check if the member exists, isn't the target, and is the aura holder
if (member && member !== target && member.isStateAffected(auraOriginId)) {
// Set the origin user to that member
auraOriginUser = member;
// Break the loop
break;
}
}
// Check if the origin user exists
if (auraOriginUser) {
// Calculate the amount of reduction
var reduction = Math.ceil(0.50 * value);
// Set the damage to the target to 0.
value = 0;
// Make the origin user take damage instead.
auraOriginUser.gainHp(-reduction);
// Display an animation on the origin user.
auraOriginUser.startAnimation(2);
// Make the origin user display a damage popup.
auraOriginUser.startDamagePopup();
// Check if the origin user is dead
if (auraOriginUser.isDead()) {
// Collapse the origin user if dead
auraOriginUser.performCollapse();
}
// Clear the origin user's results
auraOriginUser.clearResult();
}
}
</Custom React Effect>
This is the original code you'd edit:
JavaScript:
BattleManager.checkSubstitute = function(target) {
    return target.isDying() && !this._action.isCertainHit();
};

The easiest was to fix it as you want would be to remove the hp check:
JavaScript:
BattleManager.checkSubstitute = function(target) {
    !this._action.isCertainHit();
};

As long as there is a battler that has the substitute trait, it will work.
You could copy the code above into a text editor and save it as a .js file and put it in your plugin folder.

Now, if you ever need the original hp check to work in your game, you'd have to do things a bit differently.
I read on another forum MZ script editor automatically gets updated and you will need to readd it after each updates
its not automatic, but yes. if you update your core scripts, any personal changes you made to the files will be overwritten and youll have to keep track of them and make them once more. This is one of the reasons why its recommended to have any change you make to the engine be done through a plugin as opposed to adding it to the core script files. Unlike MV, MZ development hasnt ended yet and may be subject to more updates in the future.

No idea which note tag your talking about. I see the variable which I know can be changed, but unsure which one your talking bout
Yanfly's Buffs & States Core plugin used the <Custom React Effect> notetag to run JS as a battler gets hit by an attack. The Visustella battle core has <JS Pre-Damage as Target> as a direct equivalent. the JS can use within the tags for the most part should be the same. afaik, only the line to play the animation needs to be changed as MZ's call for it is different.

then the aura system itself is a part of a recent update to the skills and states plugin. you might need to grab a new copy of it
its not automatic, but yes. if you update your core scripts, any personal changes you made to the files will be overwritten and youll have to keep track of them and make them once more. This is one of the reasons why its recommended to have any change you make to the engine be done through a plugin as opposed to adding it to the core script files. Unlike MV, MZ development hasnt ended yet and may be subject to more updates in the future.


Yanfly's Buffs & States Core plugin used the <Custom React Effect> notetag to run JS as a battler gets hit by an attack. The Visustella battle core has <JS Pre-Damage as Target> as a direct equivalent. the JS can use within the tags for the most part should be the same. afaik, only the line to play the animation needs to be changed as MZ's call for it is different.

then the aura system itself is a part of a recent update to the skills and states plugin. you might need to grab a new copy of it
So would it look like this: (red is my edits I think)

<JS Pre-Apply as Target>
// Check if the action dealt HP damage
if (this.isHpEffect() && value > 0) {
// Get the target's allies
var members = target.friendsUnit().aliveMembers();
// Get the Aura's Origin State ID
var auraOriginId = x(should be state being applied);
// Make the origin user undefined
var auraOriginUser = undefined;
// Loop through each member
for (var i = 0; i < members.length; ++i) {
// Get the currently looped member
var member = members;
// Check if the member exists, isn't the target, and is the aura holder
if (member && member !== target && member.isStateAffected(auraOriginId)) {
// Set the origin user to that member
auraOriginUser = member;
// Break the loop
break;
}
}
// Check if the origin user exists
if (auraOriginUser) {
// Calculate the amount of reduction
var reduction = Math.ceil(0.50 * value);
// Set the damage to the target to 0.
value = 0;
// Make the origin user take damage instead.
auraOriginUser.gainHp(-reduction);
// Display an animation on the origin user.
$dataAnimations[x].id;
// Make the origin user display a damage popup.
auraOriginUser.startDamagePopup();
// Check if the origin user is dead
if (auraOriginUser.isDead()) {
// Collapse the origin user if dead
auraOriginUser.performCollapse();
}
// Clear the origin user's results
auraOriginUser.clearResult();
}
}
<JS Pre-Apply as Target>
This is the original code you'd edit:
JavaScript:
BattleManager.checkSubstitute = function(target) {
    return target.isDying() && !this._action.isCertainHit();
};

The easiest was to fix it as you want would be to remove the hp check:
JavaScript:
BattleManager.checkSubstitute = function(target) {
    !this._action.isCertainHit();
};

As long as there is a battler that has the substitute trait, it will work.
You could copy the code above into a text editor and save it as a .js file and put it in your plugin folder.

Now, if you ever need the original hp check to work in your game, you'd have to do things a bit differently.
I put it in the plugin manager and it didnt work. Guess I'll try the note tags
I put it in the plugin manager and it didnt work.
he missed the return
Code:
return !this._action.isCertainHit();
I put it in the plugin manager and it didnt work. Guess I'll try the note tags
That's surprising, but ok.

Good luck.
he missed the return
Code:
return !this._action.isCertainHit();
Thank you was wondering why it didnt work.
he missed the return
Code:
return !this._action.isCertainHit();
went back and retested, but I am guessing there's no way to cover all party members?
*the code only blocks single targets

For example: If an enemy uses an "All Enemy" target attack?
*the code only blocks single targets
the code above didnt change that. all it did was remove the requirement for the target being below 25% hp. if your battlers arent substituting in for all enemy skills, then its likely that either the skill youre using to test is set to certain hit or you have a plugin interfering.

Original thread: https://forums.rpgmakerweb.com/threads/ally-take-damage-for-party.176503/