MV [Solved] Creating a State that Adds Extra Gold Upon Knockout?

I apologize for posting so much lately, but this community has been amazingly helpful and insightful! I tried to create a skill where it adds a state to an enemy that grants extra gold if the enemy is killed while affected by that state (I know I could just add gold drops to the enemy encounter, but I thought a skill like this could be fun). I've basically been going through the list of skills from Fire Emblem Engage and trying to poorly replicate them in RPG Maker. The skill works, and adds the state to the enemy, but the state itself doesn't seem to be working yet. I've been using Yanfly's plugins, and I added this code to the custom state I created:

<Custom Passive Condition>
if (user.isStateAffected(1)) {
condition = true;
$gameParty.gainGold(100);
} else {
condition = false;
}
</Custom Passive Condition>

What am I doing wrong? Is my spacing/syntax wrong? Also, what would be the code I would put to add a message that informs the player they've gained gold?

Thank you for all the help and support the community has shown these last few days!
I'd probably see to add a note to the knockout state instead since you want them to get extra gold on knockout...
I'm not entirely sure how the note tag would be structured, but I believe it would be something like:

Code:
<Custom Apply Effect>
  if (user.isStateAffected(1)) {
    gameParty.gainGold(100);
</Custom Apply Effect>

This should more or less make it so whenever and enemy get kocked out, it checks if your user has that gain extra gold state and then increase your gold by a fixed amount. There's no need for an else condition and I don't see why it would need a "condition = true" either. gameParty.gainGold would only execute if the condition was true anyway.

As for displaying a message, you can try:


Code:
<Custom Apply Effect>
  if (user.isStateAffected(1)) {
    gameParty.gainGold(100);
    gameMessage.setBackground(1);
    gameMessage.setPositionType(2);
    gameMessage.add(You gained 100 Gold!');
    this.setWaitMode('message');
</Custom Apply Effect>

As I said, I'm not very proficient with these either. I just looked up the script call list here.
@SGHarlekin has the right idea - this should be in a Custom Apply Effect on state 1. All of his references to the $gameParty need the dollar sign at the front, though.

Custom Passive Conditions aren't for executing code, they're only for evaluating the condition variable to see whether the passive state becomes active or not.

So here's a quick fix to what Harlekin posted:
Code:
<Custom Apply Effect>
  if (user.isStateAffected(X)) {
    $gameParty.gainGold(100);
    $gameMessage.setBackground(1);
    $gameMessage.setPositionType(2);
    $gameMessage.add(You gained 100 Gold!');
    this.setWaitMode('message');
}
</Custom Apply Effect>

replace X with the ID of the state you're inflicting on the enemy (no leading zeros).
@SGHarlekin has the right idea - this should be in a Custom Apply Effect on state 1. All of his references to the $gameParty need the dollar sign at the front, though.

Custom Passive Conditions aren't for executing code, they're only for evaluating the condition variable to see whether the passive state becomes active or not.

So here's a quick fix to what Harlekin posted:
Code:
<Custom Apply Effect>
  if (user.isStateAffected(X)) {
    $gameParty.gainGold(100);
    $gameMessage.setBackground(1);
    $gameMessage.setPositionType(2);
    $gameMessage.add(You gained 100 Gold!');
    this.setWaitMode('message');
}
</Custom Apply Effect>

replace X with the ID of the state you're inflicting on the enemy (no leading zeros).
Ah so they do actually need it, well sh*t. But I knew you can always count on @ATT_Turan to correct you. 😀

I was not posting them, refering to my own custom note tags, which don't have them (and they work).
Ah so they do actually need it
Yeah, all of MV's "system variables" are prepended with the dollar sign - so it's actually a part of the name. If you pull up the console and type something in with just gameParty, it'll give you an error because it doesn't know what that is 🙂
It's a bit awkward because by default all states get removed on death, and I think YEP Buffs & States Core's <Custom Apply Effect> tag processes after the state is applied. (Maybe that's why you were trying to use a passive state.)

If Turan/Harlekin's suggestion doesn't work out, you could try using these tags (untested):
Spoiler: click to see tags
  • On your "drop extra gold" state:

    <Custom Apply Effect> user._dropExtraGold = true; </Custom Apply Effect> <Custom Remove Effect> delete user._dropExtraGold; </Custom Remove Effect>
  • On state 1 (death state):

    <Custom Apply Effect> if (user._dropExtraGold) { var gold = 100; $gameParty.gainGold(gold); $gameMessage.add( TextManager.obtainGold.format(gold) ); delete user._dropExtraGold; } </Custom Apply Effect>
This assumes that <Custom Remove Effect> processes only when the state is "removed", not when it is "erased" (e.g. on death). Yanfly might've patched that since the last time I checked.

It also uses the standard "Obtain Gold" message as defined on the Terms tab in the database. If you want a custom message then you can replace this line:

TextManager.obtainGold.format(gold)
...with something like this:

"Gained 100 gold!"
All message text codes are valid in this message as long as you write all backslashes as \\, e.g. "Gained \\C[14]100\\C[0]\\G!".
It's a bit awkward because by default all states get removed on death, and I think YEP Buffs & States Core's <Custom Apply Effect> tag processes after the state is applied.
That's a good call...the Apply Effect runs after the state is applied (and others would get stripped), so you'd need to use a tracker variable like that.
I just wanted to add to this conversation, if OP also has YEP State Categories plugin, they can use the notetag
<Category: Bypass Death Removal>
to prevent states being erased on death. It may help them out with this effect, and some others that are death-dependent 🙂
I ended up going with caethyril's method, and it worked exactly as intended! Thank you all!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-creating-a-state-that-adds-extra-gold-upon-knockout.157464/