Earth Shield makes you immortal?

Zerothedarklord

Veteran
Veteran
Joined
Jun 25, 2013
Messages
149
Reaction score
24
First Language
English
Primarily Uses
From yanfly's tips & tricks series, he replicated the ability Earth Shield from world of warcraft.

<Custom Apply Effect>
// Get the current 50% value of the caster's MAT upon the state being applied as the Earth Shield Heal value.
target._earthShieldHeal = Math.floor(origin.mat * 0.50);
// Set the number of charges on the state to 9.
target.setStateCounter(stateId, 9);
</Custom Apply Effect>

<Custom Remove Effect>
// When removed, clear the stored heal value.
target._earthShieldHeal = undefined;
// When removed, clear the number of charges on the state.
target.removeStateCounter(stateId);
</Custom Remove Effect>

<Custom React Effect>
// If the received action is an HP effect and if it's a Heal...
if (this.isHpEffect() && value < 0) {
// ...then increase the heal by 20%.
value = Math.floor(value * 1.20);
// Then reduce the state's charges by -1.
target.addStateCounter(stateId, -1);
// If the state's charges reach 0 or less...
if (target.getStateCounter(stateId) <= 0) {
// ...then remove the state.
target.removeState(stateId);
}
}
</Custom React Effect>

<Custom Deselect Effect>
// Make a copy of the target's results.
var result = JsonEx.makeDeepCopy(target.result());
// Check if the target is alive and if the amount of damage received is above 0.
if (target.isAlive() && result.hpDamage > 0) {
// Set the amount of HP to heal equal to the stored Earth Shield Heal value.
var hpHealed = target._earthShieldHeal || 0;
// Make the target gain that much HP.
target.gainHp(hpHealed);
// Show the damage popup on the target.
target.startDamagePopup();
// Clear the target's results.
target.clearResult();
// Reduce the state's charges.
target.addStateCounter(stateId, -1);
// If the state's charges reach 0 or less...
if (target.getStateCounter(stateId) <= 0) {
// ...then remove the state.
target.removeState(stateId);
}
// Reset the target's results back to what they were before.
target._result = result;
}
</Custom Deselect Effect>

The code functions perfectly fine, however, if the recipient has low health, instead of dying, their HP is set to the value the shield is intended to heal. Does anyone know how this could be modified to ensure HP is above 0 before applying the heal, such that if it isn't, the character dies instead of surviving at the intended heal amount?
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
1,917
Reaction score
923
First Language
Spanish
Primarily Uses
RMVXA
I believe that has to do with the core function of the plugin and how it applies the heal.
after effects should always be applied after the main calculation, so if Yanfly poked into the main battle (MV's) loop or replaced it in some way, then the effect could be being applied before the calculation ends (therefore, not considering *death* until the very end)
 

Zerothedarklord

Veteran
Veteran
Joined
Jun 25, 2013
Messages
149
Reaction score
24
First Language
English
Primarily Uses
I believe that has to do with the core function of the plugin and how it applies the heal.
after effects should always be applied after the main calculation, so if Yanfly poked into the main battle (MV's) loop or replaced it in some way, then the effect could be being applied before the calculation ends (therefore, not considering *death* until the very end)
So TL : DR: all hope is lost, this is not something that can be fixed?
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
1,917
Reaction score
923
First Language
Spanish
Primarily Uses
RMVXA
depends on how the system itself is designed (as opposed to: it depending on the way you configure the parameters)
if the system is wired to always consider the additions before death, then you'll have to change that by changing the core, and I doubt Yanfly is gonna allow that.
 

Simientes

Villager
Member
Joined
Dec 18, 2019
Messages
16
Reaction score
1
First Language
Spanish
Primarily Uses
RMMV
maybe a way to add something like "lethal damage detection" wich nullifies the dmg recived instead of healing? maybe also an hability that dispells some altered stats (like poison, therefore the reciever wont die)

oor maybe set the healing to full hp if you aren't supposed to die doesn't really matter how much hp do you have right?

i'm really curious but I can't think beyond the "noob" espectrum haha
 

Zerothedarklord

Veteran
Veteran
Joined
Jun 25, 2013
Messages
149
Reaction score
24
First Language
English
Primarily Uses
figured out how to fix it.
after the line <custom deselect effect>, I added the following:


if (target.hp <= 0 || target.isDead()) {
target.removeState(30);
}

(30 being the state ID I used for the effect)
I will post the full, modified code for anyone who may be interested, and again, change all instances of (30) to
whatever your state's ID is.

<Custom Apply Effect>

// Get the current 50% value of the caster's MAT upon the state being applied as the Earth Shield Heal value.

target._earthShieldHeal = Math.floor(origin.mhp / 20 * target.elementRate(12));

// Set the number of charges on the state to 9.

target.setStateCounter(30, 10);

</Custom Apply Effect>



<Custom Remove Effect>

// When removed, clear the stored heal value.

target._earthShieldHeal = undefined;

// When removed, clear the number of charges on the state.

target.removeStateCounter(30);

</Custom Remove Effect>



<Custom React Effect>

// If the received action is an HP effect and if it's a Heal...

if (this.isHpEffect() && value < 0) {

// ...then increase the heal by 20%.

value = Math.floor(value * 1.20);

// Then reduce the state's charges by -1.

target.addStateCounter(30, -1);

// If the state's charges reach 0 or less...

if (target.getStateCounter(30) <= 0) {

// ...then remove the state.

target.removeState(30);

}

}

</Custom React Effect>



<Custom Deselect Effect>

// Make a copy of the target's results.

if (target.hp <= 0 || target.isDead()) {

target.removeState(30);

}

var result = JsonEx.makeDeepCopy(target.result());

// Check if the target is alive and if the amount of damage received is above 0.

if (target.isAlive() && result.hpDamage > 0) {

// Set the amount of HP to heal equal to the stored Earth Shield Heal value.

var hpHealed = target._earthShieldHeal || 0;

// Make the target gain that much HP.

target.gainHp(hpHealed);

// Show the damage popup on the target.

target.startDamagePopup();

// Clear the target's results.

target.clearResult();

// Reduce the state's charges.

target.addStateCounter(30, -1);

// If the state's charges reach 0 or less...

if (target.getStateCounter(30) <= 0) {

// ...then remove the state.

target.removeState(30);

}

// Reset the target's results back to what they were before.

target._result = result;

}

</Custom Deselect Effect>
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
1,917
Reaction score
923
First Language
Spanish
Primarily Uses
RMVXA
usually hp <= 0 implies .isDead()...... but....
¯\_(ツ)_/¯
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,241
Reaction score
6,784
First Language
German
Primarily Uses
RMMV
usually hp <= 0 implies .isDead()
not if the game makes use of immortal states, which is something a lot of games do due to the problem with troop triggers on HP conditions at battleend.
And I think a lot of yanfly's action sequences also use an internal immortal tag to allow the action sequences to finish after skill effects already took place.

So that code probably needs to handle both options for those cases.
 

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

Latest Threads

Latest Profile Posts

Kid : "MOOOMM! My poop is bloody red!" Me, an intellectual : "There's worm parasite inside your body. You gonna die soon."
Caught a guy trying to break into our house today. Appearantly he intended to burgle our neighbor (a 94yo widow) but picked the wrong house. Faced with two angry males he was quick to give up without a fight...
I just joined the club of nerds making their own Excel-Sheets to calculate HP / MP / EXP.. parameter curves
Me: "Finally finished most of my game backlog. Probably time to do some gamedev" | Steam: *offer sales*
If I recorded while I created (what I think is) a small plugin, would you be interested enough in the process to watch it?

Forum statistics

Threads
94,596
Messages
922,205
Members
124,472
Latest member
Lanzy
Top