Hey all, it's me again. I've spent a couple hours working on my most complicated state yet, and even though I wasn't sure if I could even get it to work with my very limited knowledge, I actually managed to work it out. What this state does is that it resists death once and then spreads to another target when the affected target dies. Here's my code for it:
After getting this to work, I thought "Hey, maybe this is not the best way to do this, but it works. What else can I do with this?" The first idea I had was to make it so that instead of just jumping to another target, it jumps to two other targets so that it's actually like a spreading plague. So, I modified it like this:
The idea was that if I remove the random target I had already selected from the array and make another random selection from the new array, I should have two unique targets. But as you can guess, it's not working. I'm getting an error that suggests my second target returns as undefined. What am I doing wrong here?
Sidenote: I've been posting these questions on MV support but should I be posting them in JS support instead?
JavaScript:
<Custom Apply Effect>
target.deathResist = (1);
</Custom Apply Effect>
<Custom React Effect>
if (target.deathResist == 1) {
if (this.isDamage() && value >= target.hp) {
value = (target.hp - 1);
target.deathResist = (0);
}
} else {
if (this.isDamage() && value >= target.hp) {
var group = [];
var group2 = target.friendsUnit().aliveMembers();
group2.forEach(element =>
{
if (!element.isStateAffected(105)){
group.push(element);
}
});
if (group.length > 0) {
var randomTarget = group[Math.floor(Math.random() * group.length)];
randomTarget.addState(105);
}
}
}
</Custom React Effect>
After getting this to work, I thought "Hey, maybe this is not the best way to do this, but it works. What else can I do with this?" The first idea I had was to make it so that instead of just jumping to another target, it jumps to two other targets so that it's actually like a spreading plague. So, I modified it like this:
JavaScript:
<Custom Apply Effect>
target.deathResist = (1);
</Custom Apply Effect>
<Custom React Effect>
if (target.deathResist == 1) {
if (this.isDamage() && value >= target.hp) {
value = (target.hp - 1);
target.deathResist = (0);
}
} else {
if (this.isDamage() && value >= target.hp) {
var group = [];
var group2 = target.friendsUnit().aliveMembers();
group2.forEach(element =>
{
if (!element.isStateAffected(105)){
group.push(element);
}
});
if (group.length > 0) {
var randomTarget = group[Math.floor(Math.random() * group.length)];
var index = group.indexOf(randomTarget);
if (index > -1) {
var group3 = group.splice(index, 1);
}
var randomTarget2 = group3[Math.floor(Math.random() * group.length)];
randomTarget.addState(105);
randomTarget2.addState(105);
}
}
}
</Custom React Effect>
The idea was that if I remove the random target I had already selected from the array and make another random selection from the new array, I should have two unique targets. But as you can guess, it's not working. I'm getting an error that suggests my second target returns as undefined. What am I doing wrong here?
Sidenote: I've been posting these questions on MV support but should I be posting them in JS support instead?