yanfly buff states core "Buff Allies on Death"

I making a skill which applies a state to the user for 5 turns. The state should activate another skill that is applied to the rest of the party upon the users death granted that the previous state was applied.

so skill==>state==>death==>skill.

I was going to use a custom apply effect in the state note box to check if the player has knockout state. Then activate skill. If anybody knows how to write this short code please help me out thanks.
It would help if you filled us in on what the skill after death does.
It would help if you filled us in on what the skill after death does.
the skill after death makes it to where the rest of the party has 100% evasion for 3 turns.
I think this snippet targets 1 of your allies at random...
Code:
  var group = target.friendsUnit().aliveMembers();
  group.splice(group.indexOf(target), 1);
  var member = group[Math.floor(Math.random() * group.length)];
  member.addstate(stateId);
Hopefully someone w/ a better understanding of JS will chime in...
A skill needs a user, and you want the user to be the guy who just got KO'd, which is a bit unusual. 😅

Rather than invoking a skill, maybe just apply the 100% evasion state directly to all living allies, e.g.
JavaScript:
if (user.isStateAffected(123)) {
  user.friendsUnit().aliveMembers().forEach(function(m) {
    m.addState(456);
    m.startAnimation(789);
  });
}
I haven't tested, but I think that'll work inside a <Custom Apply Effect> notetag on your knockout state. Notes:
  • Replace 123 with the ID of your 5-turn "activate-on-death" state.
  • Replace 456 with the ID of your 3-turn "100% evasion" state.
  • Replace 789 with an animation ID to play on affected allies (or just delete that line entirely).
Exactly, there's no need for a skill itself. All you need is a state for the Evasion.
A skill needs a user, and you want the user to be the guy who just got KO'd, which is a bit unusual. 😅

Rather than invoking a skill, maybe just apply the 100% evasion state directly to all living allies, e.g.
JavaScript:
if (user.isStateAffected(123)) {[/INDENT]
[INDENT]  user.friendsUnit().aliveMembers().forEach(function(m) {[/INDENT]
[INDENT]    m.addState(456);[/INDENT]
[INDENT]    m.startAnimation(789);[/INDENT]
[INDENT]  });[/INDENT]
[INDENT]}
I haven't tested, but I think that'll work inside a <Custom Apply Effect> notetag on your knockout state. Notes:
  • Replace 123 with the ID of your 5-turn "activate-on-death" state.
  • Replace 456 with the ID of your 3-turn "100% evasion" state.
  • Replace 789 with an animation ID to play on affected allies (or just delete that line entirely).
Code:
<Custom Apply Effect>
if (user.isStateAffected(39)) {
  user.friendsUnit().aliveMembers().forEach(function(m) {
    m.addState(19);
    m.startAnimation(53);
  });
}
</Custom Apply Effect>

I put this in the knockout state but the state is not added after the character's death.
Oh, whoops! By default the death state removes all other states on application, so this check will never pass:
JavaScript:
if (user.isStateAffected(39)) {
I think you'll need something that either allows certain states to persist on death, or an alternative method that doesn't check for the state itself. I just quickly tested something with only Buffs & States Core and it seems to work OK for me:
  • Put something like this in the notebox of your "buff allies on death" state:
    Code:
    <Custom Apply Effect>
    user._kobuff = true;
    </Custom Apply Effect>
    
    <Custom Remove Effect>
    delete user._kobuff;
    </Custom Remove Effect>

  • Then change the condition on your death state to check for the _kobuff flag (or whatever you may have called it) rather than the state:
    Code:
    <Custom Apply Effect>
    if (user._kobuff) {
      user.friendsUnit().aliveMembers().forEach(function(m) {
        m.addState(19);
        m.startAnimation(53);
      });
      delete user._kobuff;
    }
    </Custom Apply Effect>
    Turns out the remove effect doesn't proc when removed by State Resist or death, so the flag has to be removed manually in the death state's <Custom Apply Effect> tag. 😮‍💨
I keep getting this error. This is in my death state
Code:
State #1 will be automatically added when
HP reaches 0

<Custom Apply Effect>
if (user.All for one) {
  user.friendsUnit().aliveMembers().forEach(function(m) {
    m.addState(19);
    m.startAnimation(53);
  });
  delete user.All for one;
}
</Custom Apply Effect>

This is in my death buff state
Code:
<Custom Apply Effect>
user.All for one = true;
</Custom Apply Effect>

<Custom Remove Effect>
delete user.All for one;
</Custom Remove Effect>

Its definitely not a conflict with the plugin.
you're not supposed to have spaces...
"All for one" the engine will read that as 3 separate things. I assume you're trying to say:
if (user.isStateAffected(#)) {

replace "#" w/ the state ID of your state.

You can't just assume the engine knows what "All for one" means since u didn't tell it so w/ a var and also its got spaces, so it really just sees "All" and then it thinks "for" is a totally separate function or w/e.

Edit: I highly recommend opening up Yanfly's sample project and delve into all the stuff he puts in the noteboxes to get a feel for formatting/syntax. You're also surely to find inspiration as well!
Yep, don't use spaces in names when you're writing code/script. Try replacing all instance of this:
JavaScript:
user.All for one
...with this:
JavaScript:
user.allForOne
...or, if you're set on having "spaces", you could use underscores instead:
JavaScript:
user.All_for_one

The name doesn't matter that much anyway, since it shouldn't appear to the player in-game. 🙂
A thread sharing abilities like this would be cool, like the action sequence one
Yep, don't use spaces in names when you're writing code/script. Try replacing all instance of this:
JavaScript:
user.All for one
...with this:
JavaScript:
user.allForOne
...or, if you're set on having "spaces", you could use underscores instead:
JavaScript:
user.All_for_one

The name doesn't matter that much anyway, since it shouldn't appear to the player in-game. 🙂
Yeah its working now.

you're not supposed to have spaces...
"All for one" the engine will read that as 3 separate things. I assume you're trying to say:
if (user.isStateAffected(#)) {

replace "#" w/ the state ID of your state.

You can't just assume the engine knows what "All for one" means since u didn't tell it so w/ a var and also its got spaces, so it really just sees "All" and then it thinks "for" is a totally separate function or w/e.

Edit: I highly recommend opening up Yanfly's sample project and delve into all the stuff he puts in the noteboxes to get a feel for formatting/syntax. You're also surely to find inspiration as well!
[/QU
you're not supposed to have spaces...
"All for one" the engine will read that as 3 separate things. I assume you're trying to say:
if (user.isStateAffected(#)) {

replace "#" w/ the state ID of your state.

You can't just assume the engine knows what "All for one" means since u didn't tell it so w/ a var and also its got spaces, so it really just sees "All" and then it thinks "for" is a totally separate function or w/e.

Edit: I highly recommend opening up Yanfly's sample project and delve into all the stuff he puts in the noteboxes to get a feel for formatting/syntax. You're also surely to find inspiration as well!
yeah I seen many of Yanfly codes and I use them for special action sequences most the time it's pretty complicated for me. I have trouble to understand, but I'm slowly learning.

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-buff-states-core-buff-allies-on-death.122551/