MV [YEP Buffs and States Core] Scaling State Counter

It seems I have been misinformed. target.gainHP is not a function.
No, you've fallen for the classic blunder of writing gainHp() with an upper case P when it is actually a lower case p. I did this more than once and almost despaired 😅
Do I put in the same equation or will it automatically recognize it should take the value of the last bit of damage?
startDamagePopup() does not require any parameters. gainHp(x) also stores its value in a property on the battler which then gets used by the damage popup.
No, you've fallen for the classic blunder of writing gainHp() with an upper case P when it is actually a lower case p. I did this more than once and almost despaired 😅

startDamagePopup() does not require any parameters. gainHp(x) also stores its value in a property on the battler which then gets used by the damage popup.
If it doesn't take parameters then why does it have parentheses?
the parenthesis it to call to the function, else it doesn't call it.

if you would write:

target.startDamagePopup it does nothing as it is not a function,
using target.startDamagePopup() us calling the function to use it 🙂
If it doesn't take parameters then why does it have parentheses?
It's how JavaScript distinguishes whether you mean to refer to an object or a function. This is standard in all C-based languages (amongst others).
It's how JavaScript distinguishes whether you mean to refer to an object or a function. This is standard in all C-based languages (amongst others).
I didn't know that. I guess that makes sense.
There is one thing that I'm not entirely sure is doable. I want a state to trigger a spread to the target's teammates.

For example:

<Custom Turn End Effect>
if (target.isStateAffected(lightning)){
let stack = (target.getStateCounter(lightning));
teammate.addStateCounter(lightning,stack);
teammate.addHp(stack*10*teammate.elementRate(lightning));
teammate.startDamagePopup();
}
</Custom Turn End Effect>
That should be doable. There exists a function battler.friendsUnit() which will return either $gameParty or $gameTroop depending on whether the battler is an actor or an enemy.
How do you want to determine the specific teammate to which the state spreads? Random? All teammates?
That should be doable. There exists a function battler.friendsUnit() which will return either $gameParty or $gameTroop depending on whether the battler is an actor or an enemy.
How do you want to determine the specific teammate to which the state spreads? Random? All teammates?
Ideally, it should be able to apply a random chance to all teammates. I don't so much mind if it can't use a chance function.
It's pretty easy to slap a random chance in there. Though I am not entirely sure if you want the random chance to be individually rolled for each teammate or once for all of them.
JavaScript:
//roll once for entire team
if(Math.random() <= x)
  target.friendsUnit().members().forEach(mate => {if(target != mate){/*your code here*/}});

//roll for each mate individually
target.friendsUnit().members().forEach(mate => {if(target != mate && Math.random() <= x){/*your code here*/}});
Reolace x with a number. For example 0.25 for x would equal a 25% chance.
Oh boy, this looks complicated. Can we break down what each part of this line does?
The latter, as I want to roll for each member individually.

The main thing I'm confused by is target != mate. Wouldn't that exclude everyone? I typed in the code without the stuff about mate because I'm not entirely sure what it does. On the other hand, I'm not sure what scope would be used for the .gainHp function, since I'm pretty sure target would still refer to the source in this case.

<Custom Turn End Effect> if (target.isStateAffected(8)){ let stack = target.getStateCounter(8); target.friendsUnit().members().forEach( if (Math.random()<=.5){ ???.gainHp(-state*20*???.elementRate(7)); } ); } </Custom Turn End Effect>
As previously discussed battler.friendsUnit() will give either $gameParty or $gameTroop, whichever one is appropriate. In either case the unit will have a function called unit.members() that will give us an array with all members that are part of that unit (during battle we will only get actual battle members, not benched members).
On second thought we should probably use unit.aliveMembers() instead. That will automatically exclude any dead members from the above mentioned array.
In javascript arrays have the built-in function array.forEach(). This function takes another function as its argument and executes it once for each element of the array.
I declared this function using the shorthand arrow function.
JavaScript:
x => {/*some code here*/}

//the above is shorthand for the following
new function(x){/*some code here*/}
x (or as I called it above 'mate') is the name of the current element of the array for which forEach is currently executing the function.
JavaScript:
//Example
[1,3,5].forEach(x => console.log(x));
//Expected Output:
//1
//3
//5

//the {} around console.log(x) can be omitted
//since the function consists of a single statement

Since we are talking about doing stuff to the target's teammates I presumed you wanted to exclude the target from the processing. That's why I added the if(target != mate){/*...*/} condition as the first statement of the function that I am passing to forEach. In this function you can refer to the currently processed teammate as 'mate' (though you can of course also choose any other name). So mate.startDamagePopup() and so on ...

Lastly a side-note: I'm not sure how javascript handles this, but I am fairly certain that you would actually need to type out 0.5 instead of shortening it to .5 in other programming languages.
As previously discussed battler.friendsUnit() will give either $gameParty or $gameTroop, whichever one is appropriate. In either case the unit will have a function called unit.members() that will give us an array with all members that are part of that unit (during battle we will only get actual battle members, not benched members).
On second thought we should probably use unit.aliveMembers() instead. That will automatically exclude any dead members from the above mentioned array.
In javascript arrays have the built-in function array.forEach(). This function takes another function as its argument and executes it once for each element of the array.
I declared this function using the shorthand arrow function.
JavaScript:
x => {/*some code here*/}

//the above is shorthand for the following
new function(x){/*some code here*/}
x (or as I called it above 'mate') is the name of the current element of the array for which forEach is currently executing the function.
JavaScript:
//Example
[1,3,5].forEach(x => console.log(x));
//Expected Output:
//1
//3
//5

//the {} around console.log(x) can be omitted
//since the function consists of a single statement

Since we are talking about doing stuff to the target's teammates I presumed you wanted to exclude the target from the processing. That's why I added the if(target != mate){/*...*/} condition as the first statement of the function that I am passing to forEach. In this function you can refer to the currently processed teammate as 'mate' (though you can of course also choose any other name). So mate.startDamagePopup() and so on ...

Lastly a side-note: I'm not sure how javascript handles this, but I am fairly certain that you would actually need to type out 0.5 instead of shortening it to .5 in other programming languages.
So mate is a scope similar to target and origin?
I think what you mean is correct? Though scope is a concept about where variables exist and you seem to use it synonymous with the concept of variables themselves?
I think what you mean is correct? Though scope is a concept about where variables exist and you seem to use it synonymous with the concept of variables themselves?
Eh, I mean like its where the function is being called from.
Yes and no. It is just a variable. In this case (because unit.members() will give us an array of Game_Battler objects) this variable will contain a Game_Battler object. Hence we can call all functions and access all properties that we normally can call/access with a Game_Battler object.
[1,3,5].forEach(x => console.log(x));
However in this example the variable just contains a number, not an object. We cannot call any functions of it or access any properties of it, because it doesn't have any.
Oh boy I really regret giving up because now I have no idea what I'm looking at. Okay, let me think about the order of operations for how I wanted this to work...

Every turn, the Lightning state would listen for the Fire state.
If the first state is present:
1. Set the variable "stack" to be the stack value of fire. ``let stack = target.getStateCounter(8);``
2. Consume fire stacks. ``target.removeState(8);``
3. Afflicts all team mates of the target, including themselves, with stacks of lightning.
3. Damage all teammates of the target, including themselves, with damage scaling with the stack.

Now I'm looking at the unfinished old code. Why is there Math.random?
Now I'm looking at the unfinished old code. Why is there Math.random?
I don't think anyone can answer "why" except for you. What it does is give each actor a 50% chance to take damage.
Code:
<Custom Turn End Effect>

if (target.isStateAffected(8)){

  let stack = target.getStateCounter(8);

  target.removeState(8);

  target.friendsUnit().gainHp(-state*20*target.FriendsUnit.elementRate(7));

  target.friendsUnit().addState(9);

  target.friendsUnit().addStateCounter(9,stack);

}

</Custom Turn End Effect>

This is the current state of it. It's deleting the fire, but not damaging or applying.

Original thread: https://forums.rpgmakerweb.com/threads/yep-buffs-and-states-core-scaling-state-counter.152077/