[SOLVED]Need help with a state using Yanfly Buff & State core

Status
Not open for further replies.

HumanNinjaToo

The Cheerful Pessimist
Veteran
Joined
Apr 18, 2013
Messages
1,226
Reaction score
603
First Language
English
Primarily Uses
RMMV
I have created a state that adds a damage shield to the actor based on their luk stat. It works as is. The problem I'm having is coming up with a way to make the state stack. Currently, when the state is reapplied, it just resets the state counter to the original formula of Math.floor(user.luk * 2)

Technically this is okay, it is what I originally wanted. However, if possible I'd like to make it so that the state counter will add itself to whatever the current value is. So lets say the actors luk stat is 20, the state is applied and the actor will receive a damage shield of 40 = luk * 2. Lets say the actor takes 5 damage, so the state counter (the damage shield) is reduced to 35. If I reapply the state to the actor the next turn, the state counter returns to 40 (= luk * 2). Instead what I would like to happen is the state counter change to 75 (the original 35 plus another 40 based on the formula of Math.floor(user.luk * 2)).

Below is the states note tag box contents

Code:
<Custom Apply Effect>
// The number of damage before the shield wears off.
user._Protect = Math.floor(target.luk * 2);
// Set the state counter to display damage shield amount left.
user.setStateCounter(stateId, user._Protect);
</Custom Apply Effect>

<Custom Remove Effect>
// Remove the damage needed to expire the shield.
user._Protect = undefined;
// Reset the state counter.
user.setStateCounter(stateId, 0);
</Custom Remove Effect>

<Custom React Effect>
// Check if the action deals HP damage.
if (this.isHpEffect() && value > 0) {
  // Play an animation on the target.
  target.startAnimation(53);
  // Calculate the amount of HP to reduce.
  var reduce = Math.min(value, target._Protect);
  // Reduce that from the value.
  value -= reduce;
  // Reduce that value from the shield amount.
  target._Protect -= reduce;
  // Set the state counter to reflect the new damage shield amount left
  target.setStateCounter(stateId, target._Protect);
  // Create a text to display.
  var text = "<CENTER>" + target.name() + "'s protection aura blocks " + reduce + " damage."
  // Set the wait time.
  var wait = 90;
  // Display the text.
  BattleManager.addText(text, wait);
}
// Check if the damage shield is exhausted
if (target._Protect <= 0) {
  // Then remove the state.
  target.removeState(stateId);
}
</Custom React Effect>
I've been trying to figure this out for a day or so and I'm stumped. Hopefully someone can help me, thanks in advance.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,117
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
Maybe try something like this for your Apply tag~
Code:
<Custom Apply Effect>
// Existing value, otherwise zero
user._Protect = user._Protect || 0;
// Add 2 * luk
user._Protect += user.luk * 2;
// Set state counter, for display
user.setStateCounter(stateId, user._Protect);
</Custom Apply Effect>
 

HumanNinjaToo

The Cheerful Pessimist
Veteran
Joined
Apr 18, 2013
Messages
1,226
Reaction score
603
First Language
English
Primarily Uses
RMMV
That worked exactly how I needed it, thank you!

I had tried doing something similar to this the other day. Either I had a typo or I did something else wrong, but when it didn't work I just moved on. My method had given my a counter of 'NaN' I don't remember exactly how I wrote it before, but regardless, thanks so much for the help @caethyril

edit: this is solved and can be closed
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,867
Reaction score
5,240
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,038
Messages
1,018,466
Members
137,821
Latest member
Capterson
Top