Some help with Yanfly's Buff and State Core

Hey, I think it's the proper place to post (not sure since I'm new here) but I'd need help for a lunatic mode of the said plugin.

Basically, I want to make a skill that give a poison to an enemy. If the enemy bear the poison as they die, a random foe will be chosen and given the state as well. (Think of something like infections)

So here's what I got:
<Reapply Ignore Turns>
<Custom Respond Effect>
//Check if the enemy is dead
if (user.hp <= 0) {
// Get a random enemy
var members = this.friendsUnit().aliveMembers();
members.splice(members.indexOf(target), 1);
var member = members[Math.floor(Math.random() * members.length)]
if (member) {
//Play an animation and pass over the infections
member.startAnimation(60);
member.addState(22);
member.setAtk(user.atk);
member.setDef(user.def);
member.setMat(user.mat);
user.performCollapse();}}
</Custom Respond Effect>

<Custom Action End Effect>
//Apply poison effect
var dmg = (115 + a.def * 90) + (a.atk * (0.50 + a.def * 0.005) + a.mat * (0.50 + a.def * 0.005)) * a.def;
user.gainHp(-Math.ceil(dmg * user.elementRate(8)));
user.startAnimation(146);
user.startDamagePopup();
//Check if the enemy is dead
if (user.hp <= 0) {
var members = this.friendsUnit().aliveMembers();
members.splice(members.indexOf(target), 1);
var member = members[Math.floor(Math.random() * members.length)];
if (member) {
//Play an animation and pass over the infections
member.startAnimation(60);
member.addState(22);
member.setAtk(user.atk);
member.setDef(user.def);
member.setMat(user.mat);
user.performCollapse();}}
</Custom Action End Effect>

This SHOULD be working, but I encounter two problems:

First, if I kill the foe without if falling for poison, like using a spell on it (first part), strictly nothing will happen. I'm trying to figure
out why, but can't seem to get it! I mean, it's literally the same as the second part without the poison.

Secondly, the most gruesome: in the second part, it only partly works. If an enemy dies from the poison, they will collapse and pass over the state to another enemy, sometimes even creating a chain. Sadly, there is ONE problem that pisses me off badly.
If there is only one other enemy when the infected enemy dies, this part never applies and I have no idea why.

if (member) {
member.startAnimation(60);
member.addState(22);
member.setAtk(user.atk);
member.setDef(user.def);
member.setMat(user.mat);
user.performCollapse();}}

The one before applies, I tried putting some random stuff in it and it does apply. So basically if there's only two enemies when the infected one dies, he just stay in place, never collapse nor pass over the state.

I think it's weird because I have a similar spell that hits one enemy then another random one. If the first hit killed the first enemy,
the randomly chosen enemy will take similar damages. I'm using a lunatic code very similar to it and never ever faced this problem, as it works perfectly if there are two enemies. Have a look:

<Post-Damage Eval>
var elementId = 3;
var damage = value;
if (target.hp <= 0){
var damage = damage * 2;}
var members = this.opponentsUnit().aliveMembers();
members.splice(members.indexOf(target), 1);
var member = members[Math.floor(Math.random() * members.length)];
if (member) {
member.startAnimation(141);
member.gainHp(-Math.ceil(damage * member.elementRate(elementId)));
member.startDamagePopup();
member.clearResult();
if (member.isDead()) {
member.performCollapse();}}
</Post-Damage Eval>

Could anyone look up to it? I'd really love to get some help on that.
hello, I think you need to put you transmition effect in your death state like yanfly do for the phoenix ring

Spoiler: yanfly phoenix ring
Hey, I tried that methods, but it sadly doesn't work for the only reason that other states are removed upon death, thus making it impossible for me to actually check the state and infect someone. Yanfly's video is about an item, and these stay after death... But thanks for your time anyway!
Hey, I think it's the proper place to post (not sure since I'm new here)
Unfortunately you were wrong, but that is no problem
Moved to: Plugin Support
Please give a link to the plugin, so that people don't need to search it for crosschecks
i really thought i was right qq

http://yanfly.moe/2015/12/25/yep-50-buffs-states-core/
Here's Yanfly's buff and state core.

I'm still mainly trying to figure out the problem number two. The number one is probably because states are removed upon death, making it never
really check in the first place... Does anyone have an idea how to turn around that? And well I'm still struggling with my script not working if there is only 2 enemies.
http://yanfly.moe/2016/04/03/yep-89-state-categories/

Yanfly's State Categories plugin allows states to remain on a target even after death. Just use <Category: Bypass Death Removal> in the state and it will remain after death.
Game_Battler.prototype.die() does 3 things.
  1. Set HP to 0
  2. Removes all buffs
  3. Removes all states
You could make a plug-in that overwrites this function and comments out the remove States part. If you do though, anyone brought back to life will likely still have whatever States they had when they died. Maybe you could also overwrite the revive() function and shift the code there.
http://yanfly.moe/2016/04/03/yep-89-state-categories/

Yanfly's State Categories plugin allows states to remain on a target even after death. Just use <Category: Bypass Death Removal> in the state and it will remain after death.

I used it, nothing happens... it's the same as before. :/

I tried with multiple Custom xx Effect and really nothing happens if the enemy doesn't die from the poison qq
<Reapply Ignore Turns>
<Category: Bypass Death Removal>
<Custom Deselect Effect>
//Check if the enemy is dead
if (user.hp <= 0) {
// Get a random enemy
var members = this.friendsUnit().aliveMembers();
members.splice(members.indexOf(target), 1);
var member = members[Math.floor(Math.random() * members.length)]
if (member) {
//Play an animation and pass over the infections
member.startAnimation(60);
member.addState(22);
member.setAtk(user.atk);
member.setDef(user.def);
member.setMat(user.mat);
user.performCollapse();}}
</Custom Deselect Effect>

Also, it seems that the foe won't pass over the poison if it is alone or with only one other member when it dies from the poison, not just when there are two of them... Just what is wrong with my script qq

Game_Battler.prototype.die() does 3 things.
  1. Set HP to 0
  2. Removes all buffs
  3. Removes all states
You could make a plug-in that overwrites this function and comments out the remove States part. If you do though, anyone brought back to life will likely still have whatever States they had when they died. Maybe you could also overwrite the revive() function and shift the code there.

I would just need something to be JUST before removing the state...
Hey, I've given up, this is too hard for me. The <Category: Bypass Death Removal> doesn't work at all and this actually makes me block in game
since I have to do skills/state in order. I've changed it for a smaller poison with other methods of spreading other than death. Regardless, thanks to everyone that helped me!
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/some-help-with-yanflys-buff-and-state-core.77610/