Hello! First of all, thanks for reading and trying to help.
Turns out I'm trying to create a state, with the help of YEP Buff & States Core. The state, called "Hot Potato", lasts 5 turns, with the following behavior: At the end of each turn, the state is transferred to another living character who does not already have that state, carrying the same number of turns remaining for it as the person who transferred it had. When the state expires due to its turns reaching 0, the user loses 1/3 of his maximum health, and if they are not defending (using "Guard"), the "Burn" status is also applied.
I was trying to look at some ready-made Tips & Tricks for inspiration (specifically, Roaming Mend), and came up with this:
The thing is that the effects are totally inconsistent. Sometimes I see how the state is applied and instantly removed from all characters upon passing the first turn; other times it is transferred to another character, but with a lower number of turns remaining than it should be; and other times, whether it has been transferred previously or not, it stays on the same character even though the remaining turns decrease...
I suspect this is because, as the code stands, when the status is transferred to someone at the end of the turn, they re-execute their own Turn End Effect, therefore, it is transferred to another character and removed from the current one, and so on and so forth, and maybe the seemingly random behavior is because of different timings?...
How could we fix this? By adding some failsafes? Or I'm just approaching this wrong? I'm not very good at JavaScript. Is there any way to do what I'm looking for? Many thanks again.
Turns out I'm trying to create a state, with the help of YEP Buff & States Core. The state, called "Hot Potato", lasts 5 turns, with the following behavior: At the end of each turn, the state is transferred to another living character who does not already have that state, carrying the same number of turns remaining for it as the person who transferred it had. When the state expires due to its turns reaching 0, the user loses 1/3 of his maximum health, and if they are not defending (using "Guard"), the "Burn" status is also applied.
I was trying to look at some ready-made Tips & Tricks for inspiration (specifically, Roaming Mend), and came up with this:
JavaScript:
<Custom Turn End Effect>
var potatoId = 73;
// Create an empty array.
var members = [];
// Loop through each of the target's alive allies.
for (var i = 0; i < target.friendsUnit().aliveMembers().length; ++i) {
// Set the potential variable to the current looped ally.
var potential = target.friendsUnit().aliveMembers()[i];
// If the ally doesn't exist, move onto the next.
if (!potential) continue;
// If the ally is the same as the target, move onto the next.
if (potential === target) continue;
// If the ally is already affected by a different Potato effect, move onto the next.
if (potential.isStateAffected(potatoId)) continue;
// If the ally's HP is at zero (hence dead), move onto the next.
if (potential.hp <= 0) continue;
// Now that all checks have been cleared, put the potential ally into the members array.
members.push(potential);
}
// Get a random member of the members array.
var member = members[Math.floor(Math.random() * members.length)];
// Check if the random member exists.
if (member) {
// Play an animation on that random member.
member.startAnimation(3);
// Move the Potato state onto that random member.
member.addState(potatoId);
var turns = user.stateTurns(potatoId);
member.setStateTurns(potatoId, turns);
user.removeState(potatoId)
}
</Custom Turn End Effect>
<Custom Leave Effect>
var dmg = Math.floor(user.mhp / 3);
user.gainHp(-dmg);
user.startDamagePopup();
user.clearResult();
if (user.isDead()) {
user.performCollapse();
} else {
user.performDamage();
}
userisActor() ? SoundManager.playActorDamage() : SoundManager.playEnemyDamage();
var burnId = 18;
if (!user.isStateAffected(2)) {
user.addState(burnId);
user.startAnimation(67);
}
<Custom Leave Effect>
The thing is that the effects are totally inconsistent. Sometimes I see how the state is applied and instantly removed from all characters upon passing the first turn; other times it is transferred to another character, but with a lower number of turns remaining than it should be; and other times, whether it has been transferred previously or not, it stays on the same character even though the remaining turns decrease...
I suspect this is because, as the code stands, when the status is transferred to someone at the end of the turn, they re-execute their own Turn End Effect, therefore, it is transferred to another character and removed from the current one, and so on and so forth, and maybe the seemingly random behavior is because of different timings?...
How could we fix this? By adding some failsafes? Or I'm just approaching this wrong? I'm not very good at JavaScript. Is there any way to do what I'm looking for? Many thanks again.