Chance of activating Guts effect

Lonewulf123

Veteran
Veteran
Joined
Oct 13, 2014
Messages
300
Reaction score
89
First Language
Enlish
As we all know, there's multiple ways of creating an "Endure" state in RPG Maker MV.

For those of you who don't know, an "Endure" or "Guts" state is a state where upon taking fatal damage, a character is revived or holds on with minimal HP. I'm using Yanfly's second chance code to replicate this in my game, however, I want to add an extra line of code that will give this effect a chance to occur depending on the characters luck stat.

I've been having trouble accomplishing this however, and would like some help.

Here are the endure codes:

<Custom React Effect>
// Check to see if the party is in battle.
if ($gameParty.inBattle()) {
// Sets the flag if the target has more than 1 HP at the time of death.
target._secondChance = target.hp > 1;
}
</Custom React Effect>

<Custom Respond Effect>
// Check to see if the party is in battle, has the Second Chance flag, and if the target is dead with 0 HP.
if ($gameParty.inBattle() && target._secondChance && target.hp <= 0) {
// Play the revival animation.
target.startAnimation(49);
// Set the target's HP to 1.
target.setHp(1);
}
</Custom Respond Effect>
<Category: Bypass Death Removal>

<Custom Deselect Effect>
// Check if the target's HP is 0 or is currently in the death state.
if (target.hp <= 0 || target.isDead()) {
// Play the auto-life animation on target.
target.startAnimation(49);
// Set the amount of HP recovered to 10%.
var rate = 0.10;
// Calculate the HP healed.
var heal = Math.floor(target.mhp * rate);
// Remove the Auto-Life state.
target.removeState(stateId);
// Heal the target.
target.gainHp(heal);
// Make the damage popup show for the heal.
target.startDamagePopup();
// Clear the target's results.
target.clearResult();
}
</Custom Deselect Effect>
Basically, I want to add a formula to calculate the chance of this effect happening. Something like if = a.luk / 2 . That way, a character with a high luck chance will have a better chance of activating the endure effect in battle.

Thank you for reading through my thread!
 

Maliki79

Veteran
Veteran
Joined
Mar 13, 2012
Messages
797
Reaction score
350
First Language
English
Primarily Uses
N/A
You can do this pretty easily by just adding code on one line:

Code:
<Custom React Effect>
// Check to see if the party is in battle.
if ($gameParty.inBattle()) {
// Sets the flag if the target has more than 1 HP at the time of death.
target._secondChance = target.hp > 1  && Math.randomInt(100) < target.luk / 2; //Note changes
}
</Custom React Effect>

<Custom Respond Effect>
// Check to see if the party is in battle, has the Second Chance flag, and if the target is dead with 0 HP.
if ($gameParty.inBattle() && target._secondChance && target.hp <= 0) {
// Play the revival animation.
target.startAnimation(49);
// Set the target's HP to 1.
target.setHp(1);
}
</Custom Respond Effect>
You'd have to find a good randomInt value to work within your game, but the logic is sound.
 

Lonewulf123

Veteran
Veteran
Joined
Oct 13, 2014
Messages
300
Reaction score
89
First Language
Enlish
So basically, (just to make sure I understand) this will generate a random number between 1 and 100. If the luck stat divided by two is more than that number, the second chance effect will activate?
 

Maliki79

Veteran
Veteran
Joined
Mar 13, 2012
Messages
797
Reaction score
350
First Language
English
Primarily Uses
N/A
technically, a number from 0 and 99, but yes for the rest.
It might be better to make two random calls.

Code:
target._secondChance = target.hp > 1  && Math.randomInt(100) < Math.randomInt(target.luk);
Something along those lines.
 

Lonewulf123

Veteran
Veteran
Joined
Oct 13, 2014
Messages
300
Reaction score
89
First Language
Enlish
Okay, I'll test this when I get a chance and get back to you.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,847
Messages
1,016,968
Members
137,561
Latest member
JaCrispy85
Top