MV Sunder Skill

So I'm having trouble creating a skill/state that decreases the target's DEF by half the user's ATK. This is what I got so far...
1st a simple skill that applies the "Sunder" state is created.
The Sunder state currently has this:
JavaScript:
<Custom Apply Effect>
var x = Math.round(this.stateOrigin(4).atk / 2);
target.minusDef(x);
</Custom Apply Effect>
<Custom Remove Effect>
var x = Math.round(this.stateOrigin(4).atk / 2);
target.addDef(x);
</Custom Remove Effect>

However, this has some issues. Mainly, what if the caster's ATK changes in between when Sunder was applied and when it was removed? I think variable(s) may have to be used, but then how would I account for multiple actors/units potentially using this same skill (thus overwriting earlier instances of the variable)?

Edit: Maybe I have to do something like, "if the caster is party member #1 use this variable, else if it's party member #2 use this other variable, else if etc..."?

Edit2: I tried another attempt, but I don't think it's right either...
JavaScript:
<Custom Apply Effect>
var x = Math.round(this.stateOrigin(4).atk / 2);
if this.stateOrigin(4).indexOf($gameParty.members()) == 0 {
  $gameVariables.setValue(41, x);
  target.minusDef(v[41]);
} else if this.stateOrigin(4).indexOf($gameParty.members()) == 1 {
  $gameVariables.setValue(42, x);
  target.minusDef(v[42]);
} else if this.stateOrigin(4).indexOf($gameParty.members()) == 2 {
  $gameVariables.setValue(43, x);
  target.minusDef(v[43]);
}
</Custom Apply Effect>
<Custom Remove Effect>
if this.stateOrigin(4).indexOf($gameParty.members()) == 0 {
  target.addDef(v[41]);
} else if this.stateOrigin(4).indexOf($gameParty.members()) == 1 {
  target.addDef(v[42]);
} else if this.stateOrigin(4).indexOf($gameParty.members()) == 2 {
  target.addDef(v[43]);
}
</Custom Remove Effect>
Can anyone please lend a hand? Thx!

Basically what I'm trying to say w/ if this.stateOrigin(4).indexOf($gameParty.members()) == 0 is "if the caster who applied this state is the 1st party member, do stuff". What's the correct syntax for that?

Edit: Can someone plz teach me how to write "if user = $gameParty.members()[0]" correctly for use in a <Custom Execution> notetag?
Edit2: if $gameParty.members().indexOf(user) == 0 also doesn't work, sigh...
Just save the reduced amount into a variable on the target when they get hit with the skill. Then uses that saved value to re-add the defense back after the state expires.

This has two advantages:
  • You don't have to try to keep track of state changes on the origin
  • You don't need the origin of the state to still be alive when this state falls off.
JavaScript:
<Custom Apply Effect>
target._sunderArmorAmt = target._sunderArmorAmt || 0;
target._sunderArmorAmt += Math.round(origin.atk / 2)
target.minusDef(Math.round(origin.atk / 2));
</Custom Apply Effect>
<Custom Remove Effect>
target.addDef(target._sunderArmorAmt);
delete target._sunderArmorAmt
</Custom Remove Effect>

With your above code attempts, even if you managed to get it to successfully keep track of the stat changes of the origin, if that origin is an enemy, and it dies, it no longer exists, so when the state falls off after, the game will crash trying to read the parameters of something that doesn't exists anymore. By putting the amount in a variable stored on the target, it is always there, and is only removed when the state is removed.

Also in my code snippet above there, I made it so that if the same target gets sundered again, the defense lower amount gets added to the current one, and that gets kept track of as well. You can add some other things to that if you want it to bottom out at so many stacks using state counters instead, maybe.
@ramza Thank you! I just woke up and will try this now. Btw, would this accommodate for, say, more than 1 unit knows this skill and applies the state? Like if party members 1 & 2 both have this skill, would there be problems?

Edit: Ok, looks like I'm gonna need alternative for:
target._sunderArmorAmt += Math.round(origin.atk / 2) target.minusDef(Math.round(origin.atk / 2));
Since origin doesn't work in LTBS (it targets the stateholder instead of the caster of said state) idk what to do...

Would I maybe have to use a <Custom Execution> on the skill side and put the value of Math.round(origin.atk / 2) into a v[ ]? Sorta like...
JavaScript:
<Custom Execution>
var sunderArmorAmt = Math.round(user.atk / 2);
$gameVariables.setValue(32, sunderArmorAmt);
</Custom Execution>
Except I need to account for if there's more than 1 party member using the skill (only 3 party members total so not too bad).
I was thinking: (but my syntax is definitely incorrect somewhere)
JavaScript:
<Custom Execution>
var sunderArmorAmt = Math.round(user.atk / 2);
if ($gameParty.members().indexOf(user) == 0) {
  $gameVariables.setValue(32, sunderArmorAmt);
}
</Custom Execution>
Ok, I think I figured out a way to get the functionality of origin w/o actually using it! At least conceptually...I ran into an error trying to actually implement it, however. Basically, I have the Sunder skill w/ the following: (only 3 party members)
JavaScript:
<Custom Execution>
var _sunderAtkVal = Math.round(user.atk / 2);
if (user === $gameParty.members()[0]) {
  $gameVariables.setValue(41, _sunderAtkVal);
} else if (user === $gameParty.members()[1]) {
  $gameVariables.setValue(42, _sunderAtkVal);
} else if (user === $gameParty.members()[2]) {
  $gameVariables.setValue(43, _sunderAtkVal);
}
</Custom Execution>
<After Eval>
if (user === $gameParty.members()[0]) {
  $gameVariables.setValue(41, 0);
} else if (user === $gameParty.members()[1]) {
  $gameVariables.setValue(42, 0);
} else if (user === $gameParty.members()[2]) {
  $gameVariables.setValue(43, 0);
}
</After Eval>
And on the state side:
JavaScript:
<Custom Apply Effect>
target._sunderArmorAmt = target._sunderArmorAmt || 0;
target._sunderArmorAmt += v[41] + v[42] + v[43];
target.minusDef(v[41] + v[42] + v[43]);
</Custom Apply Effect>
<Custom Remove Effect>
target.addDef(target._sunderArmorAmt);
delete target._sunderArmorAmt;
</Custom Remove Effect>
Howver, this is the error I get: (I'm guessing my syntax is wrong)
1606185478866.png

1606185552639.png


Note: I would rather use party member index instead of actorId since that would reduce the number of variables I need to create/manage. (half dozen actors vs only 3 party members)

Edit: I've narrowed it down to the state-side code. The skill-side code works as intended. What could be wrong w/ the following?
JavaScript:
<Custom Apply Effect>
target._sunderArmorAmt = target._sunderArmorAmt || 0;
target._sunderArmorAmt += v[41] + v[42] + v[43];
target.minusDef(v[41] + v[42] + v[43]);
</Custom Apply Effect>
<Custom Remove Effect>
target.addDef(target._sunderArmorAmt);
delete target._sunderArmorAmt;
</Custom Remove Effect>
Edit2: Ok, it's definite this line: target.minusDef(v[41] + v[42] + v[43]);. I also tried creating a var 1st: var totalAtk = v[41] + v[42] + v[43]; then using target.minusDef(totalAtk); but got the same error...

Edit3: Ok, this is VERY strange! I just created a brand new blank state w/ only the following:
<Custom Apply Effect> target.minusDef(v[50]); </Custom Apply Effect>
...where v[50] is a BLANK variable, meaning a value of 0. (I just arbitrarily picked one that wasn't being used). So why can't we use a v[ ] w/ that script call? I've also tried using toFixed() and valueOf() in an attempt to get it to be read, but alas it didn't work.

Even this.addParam(3, v[50]) yields the same error...
WHY CAN'T V[ ]s BE USED?!😐

Edit4: OMG, all I had to do was use $gameVariables.value(x) instead of v[x]! Why did nobody tell me sooner?...😮‍💨

Muahaha, now get the same functionality of origin w/o actually having to use it!!😤
SOLUTION:
Spoiler: Skill
JavaScript:
<Custom Execution>
var _crush = Math.round(user.atk / 2);
if (user == $gameParty.members()[0]) {
  $gameVariables.setValue(41, _crush);
} else if (user == $gameParty.members()[1]) {
  $gameVariables.setValue(42, _crush);
} else if (user == $gameParty.members()[2]) {
  $gameVariables.setValue(43, _crush);
}
</Custom Execution>
<After Eval>
if (user == $gameParty.members()[0]) {
  $gameVariables.setValue(41, 0);
} else if (user == $gameParty.members()[1]) {
  $gameVariables.setValue(42, 0);
} else if (user == $gameParty.members()[2]) {
  $gameVariables.setValue(43, 0);
}
</After Eval>
Spoiler: State
JavaScript:
<Custom Apply Effect>
var sunder = $gameVariables.value(41) + $gameVariables.value(42) + $gameVariables.value(43);
target._sunder = target._sunder || 0;
target._sunder += sunder;
target.minusDef(sunder);
</Custom Apply Effect>
<Custom Remove Effect>
target.addDef(target._sunder);
delete target._sunder;
</Custom Remove Effect>

Original thread: https://forums.rpgmakerweb.com/threads/sunder-skill.130212/