Experience only to character that lands killing blow

I'm making a game where player competes in a party with ai-controlled members, so the player will have to compete and plan to get the killing blow and get "credit" for the kill by getting the exp (and also items if possible).

Also it would be great to be able to have a comment event where if the player gets the kill he says something like "I did it!" while if someone else gets the kill he says something like "Aw, that sucks".

Any help would be appreciated.
i dont know a full method for this but maybe if you disable xp (giving 0xp per enemy) and with every skill, check if the target is dead and then reward the xp there, midbattle. i dont know. maybe theres a native way of doing this.
or maybe you can try


maybe it helps.
i dont know a full method for this but maybe if you disable xp (giving 0xp per enemy) and with every skill, check if the target is dead and then reward the xp there, midbattle. i dont know. maybe theres a native way of doing this.
Thanks for the reply 🙂. So I would use skill -> effects: run common event -> conditional branch: enemy "x" is dead -> rewards / items / comment. Sounds like it may work, I'll try it out!
It's easy! Just make the XP gain into state notetags. This is what I did:
JavaScript:
<Custom React Effect>
target._HP = target.hp;
</Custom React Effect>
<Custom Establish Effect>
if (user.isActor() && target.result()) {
  if (target.isEnemy() && target.result().hpDamage > 0) {
    var XP = Math.round(target.exp() * Math.min(target.result().hpDamage, target._HP) / target.mhp);
    user.gainExp(XP);
    BattleManagerTBS.activeEntity().addTextPopup("+" + XP + "xp", 28, "#fd5ca8");
  } else if (target.isActor() && target.result().hpDamage < 0) {
    var XP = (target.result().hpDamage + target._HP - target.mhp) * target.level;
    user.gainExp(XP);
    BattleManagerTBS.activeEntity().addTextPopup("+" + XP + "xp", 28, "#fd5ca8");
  }
}
</Custom Establish Effect>
Of course, mine is for XP gain on damage/healing dealt, but you can adapt it for your own uses. Some of that code, such as addTextPopup(), is for LeTBS only, so you can ignore that. And then just disable XP gain anywhere else.
The solution Frostorm posted relies on you using Yanfly's Buffs and States Core plugin, just because the information wasn't given to you.

I would not do it in a common event attached to the skill like you describe in post 4. You could do it in troop events that are checking for a given enemy to have 0% HP, but that would need HimeWorks' End Phase Triggers plugin to make sure they function properly.

I think a state is the easiest way to go. You'd use Yanfly's Buffs and States Core and Auto-Passive States. Make a state with this in the notetag:
Code:
<Custom React Effect>
if (target.hp<=0)
    user.gainExp(target.exp());
</Custom React Effect>

You can then add stuff like turn on a switch which will trigger a troop event and make the party members say things.
Doh, I keep forgetting YEP stuff isn't there by default. Good catch. But shouldn't it be <Custom Establish Effect>?
Code:
<Custom Establish Effect>
if (target.hp<=0)
    user.gainExp(target.exp());
</Custom Establish Effect>
Okay, I got it to work using passive states and custom establish effect note tags on enemies. But now
how do I add a switch to make people talk? Is there a way to add info about which character killed which enemy?
Doh, I keep forgetting YEP stuff isn't there by default. Good catch. But shouldn't it be <Custom Establish Effect>?
No. Custom Establish runs when the battler with the state connects a hit, and we're putting this on the enemies.

Custom Respond is when the battler takes the hit. (but you're correct that I typed the wrong R word, it should be Respond not React).

But now how do I add a switch to make people talk?
There's a pinned thread in the JavaScript forum that has a list of script calls for RPG Maker MV. (you can also find a lot of things by just Googling. e.g. "RPG Maker MV script switch").

But basically you'd change the middle to look like:
Code:
if (target.hp<=0)
{
    user.gainExp(target.exp());
    $gameSwitches.setValue(ID, true);
}
where ID is the ID of a switch.

Is there a way to add info about which character killed which enemy?

You'd add the command to turn the switch on, and the rest is basic eventing logic. You could say which switch is flipped indicates the person that killed the monster. Or set both a switch and a variable, and the variable indicates who killed it and you use conditionals inside the troop event.
No. Custom Establish runs when the battler with the state connects a hit, and we're putting this on the enemies.
But, I thought we're putting this on the attacking unit because we want the user (player) to gain XP. Hence the if (target.hp<=0) user.gainExp(target.exp()); part.
But, I thought we're putting this on the attacking unit because we want the user (player) to gain XP. Hence the if (target.hp<=0) user.gainExp(target.exp()); part.
The target and user variables will refer to the same battlers regardless of which battle-process notetags you use.

My presumption was to put it on the enemies, but it can also be done by putting it on all the actors - it really doesn't matter. Either way you have to put the same passive state on each battler involved in the battle, of whichever side you choose.

If you only put it on the player's actor, then it won't be able to do anything (boastful comments, etc.) when the AI teammates defeat enemies.

Original thread: https://forums.rpgmakerweb.com/threads/experience-only-to-character-that-lands-killing-blow.148994/