Script Call Support Boards

If you mean doing it in like a troop event or something at the end of a turn

None that I know of. Afaik you will need to determine that right after the damage has been dealt because the game doesn't really save who attacked who after the damage dealing has been done.

You'd probably be interested in looking at Game_Battler's execute_damage method or something for this effect
This may be totally off the wall, and impractical if you want it for every actor, but it might be possible to do this using the damage formula if it is only for one actor.

It is possible for the formula to determine at least some outcomes and add something accordingly. For example, I use it on some skills if it is a critical hit. For example,
if b.result.critical; do stuff here; end; damage formula here

Is there an equivalent of b.result.critical when it is b.result.[death]?
@Kes - death doesn't exist yet when the formula is called (death actually only exist in Ace when hp becomes 0 or given State #1, its not even captured in the damage flow), unlike things like critical which is checked and saved before the damage formula is called. Practically, you can't have death before you even know the damage and/or effects anyway, unless you do a "test run" of the whole situation first which the engine doesnt actually do.

Doing this via the DF is doable via a direct check of the damage vs target's HP.

something like

Code:
x=damage_formula;if x >= b.hp then; a.mp *= 1.05;end

The problem here though is that this doesnt take into account other factors like element rates etc because those are calculated after the damage formula is evaluated.

That's why in my own game, I've resulted to tapping into the damage flow itself, checking if the final damage itself is fatal, to do this kind of effect.
Phooey, looks like this may be harder than I initially thought.

To answer your question, this is something I'm hoping to have for all actors. I'm currently using a script to call a common event every time an enemy dies, so at that point I know it was a killing blow, the main issue I'm running into is finding out who did the last attack.
@Vis_Mage

That would now depend on how your script captures the dying moment.. TBH, the script should have included a way to determine who caused the death if it captures it the moment it happens, else there will be no cause of death (like in the normal way of checking if an actor dies or is dead)

Its not hard, but it involves tapping into the damage flow which is something that I dont really suggest for someone who isnt confident enough with their scripting.

But since all you seem to need is to know the killer as you already a script to run events upon death this might work for you, but I cant be sure since I dont have the script ur using

Code:
alias execute_damage_kill execute_damage
def execute_damage(user)
  execute_damage_kill(user)
  $killer = user if self.dead?
end

Add that in a new script preferably below the one that allows you run the common event. Then on your common event, you should be able to reference the killer using the variable $killer

This should work in most cases unless your script taps into the exact moment hp reaches 0 or when State #1 is applied, which means it will probably run before the line where we set $killer

And take note that this also only works if the target dies from the damage itself, afaik this doesnt work if the target dies from having the death state added directly or from any other damage source.
Thank you for taking a look into this for me!

Although, I'm currently getting a crash on startup, with the error: Undefined method 'execute_damage' for class 'Object' for line 1

As a side note, how would I go about setting this result as a variable? Do I just need to add "$killer" to the script option in change variable?

Additionally, I'm using Yanfly Engine Ace - Death Common Events to call the common events after an enemy dies.
Oooh Silly me..

you should enclose it inside the game battler class

Code:
class Game_Battler

 #put my old code here

end

Usage depends on what you wanna achieve, $killer returns the battler/actor object itself, so its more of meant to be used within the script call event command since most event commands that handle actors uses the actor ID in the selection

you could simply do this on your common event using a script call event command

Code:
$killer.mp = ($killer.mp * 1.05).to_i
$killer.mp = [$killer.mp,$killer.mmp].min
#Just so it doesnt go above max mp

If you need the id, try either

$killer.id or $killer.actor_id

on your set game variable command

I've checked the script and it taps into the collapse effect method, I cant check right now though when that method happens, so I cant guarantee right now if this will work, hopefully you can try it soon.
No problem! Made the needed changes to the script, to some interesting results.

At first, I tried using the script call you provided. No crashes or anything, although it doesn't seem to do anything. In the very least, no MP change occurs.

I then tried using $killer.actor_id in the change variable script box, although this one does crash.

Interestingly enough, using $killer.id doesn't crash, and indeed sets the correct actor ID. From there, I can use a chain of conditional branches to determine what actor that is, determine what 5% of their MP is, and recover that MP, although I'm sure there's an easier way to go about this.

Either way, thank you for all your help so far! 🙏
It should be changing mp, I think its just actually not refreshing, so you dont notice that you are actually gaining mp. It happens to me a lot when I change the hp/mp values directly via script calls xD

You could try adding $killer.refresh after the mp setting and see if it finally refreshes the values.
Hmm, doesn't seem to be changing anything. I've done a few tests to make sure it isn't just not updating (going in and out of battle/using more skills/opening and closing the menu), and even tried commenting out the .min line of the script call, in case that was causing something to act strange, to no luck.
can you add this line after them
Code:
p $killer.mp

and run your game with the console on and see what value it prints out after you're supposed to recover MP?

Also, whats your current MP during the tests anyway?

Edit: actually try this so we get the mp before and after

Code:
p "mp before is " + ($killer.mp).to_s
$killer.mp = ($killer.mp * 1.05).to_i
p "mp after is " + ($killer.mp).to_s
Sure thing:

In the test battle I'm doing, there are 2 monsters, and 2 actors present. I kill one of the monsters with 1 skill.
The actor has 22 base MP, and are full MP at the start of the battle.
The skill they use costs 10 MP, leaving them with 12 when the foe dies.
When I defeat the foe, the console gives me the number 12.
Uhm that can be a big problem..

12 MP left means 5% is 0.6 only leaving you with 12.6 final MP. The to_i operator will round it down so your MP will still be 12 after the 5% recovery.

This is the inherent problem with using percentage on low enough numbers, their effects become negligible.

You should try it with a bigger MP value, 100 should be fine enough.

PS: or if you're supposed to actually recover 5% of max mp instead of current value,
Code:
$killer.mp += ($killer.mmp*0.05).to_i
Oh jeez, I just realized I probably made this a lot more difficult for you than need be. The whole time, I thought it was healing 5% of max MP. Sorry about that... 😅 Although, now knowing how to heal MP based on current% could make for an interesting skill.

Added the new script call, and things are working perfectly now! Thank you so much!
Yeah, I always thought you meant 5% current mp since you only said 5% mp. XD
A (hopefully) easier question, is there a script call that can store an enemy's stat as a variable.

To clarify, I'm not looking to set an enemy's stat with the variable, just for it to check the ATK stat of enemy 5, and store that value in a variable. I know there's a way to do this while in battle using the below script call, although I'm hoping to use this out of battle.

Code:
# Enemy Troop Stats (use this only in battle!)
$game_variables[n] = $game_troop.members[index].stat
# where stat = hp or mp or param(id)
# where id = 0:MHP, 1:MMP, 2:ATK, 3:DEF, 4:MAT, 5:MDF, 6:AGI, 7:LUK
@Vis_Mage

If you want to get it outside of battle, you can do

$data_enemies[enemy id].stat

Here you need the exact enemy id though corresponding to its its database entry, instead of index in the current troop.

$data_enemies basically hold the database data of enemies, and this is also where the game loads it when making instances of Game_Enemy for use in Game_Troop.
Thanks for the quick reply. Although, the engine's spitting an error at me:

Game Interpreter line 543 NoMethodError Occurred
undefined method "param" for #<RPG::Enemy:0x8623e48>

Just to be sure, here's exactly how I have it set up:
$data_enemies[2].param(2)
Try params instead of param..

or it might actually need to be [] instead of () coz were taking directly from the database so like .param[2] or .params[2]

I'm at work so I cant check which one will actually work.
You're a lifesaver! 😤

Using the below setup works like a charm, thank you!

$data_enemies[2].params[2]

Original thread: https://forums.rpgmakerweb.com/threads/script-call-support-boards.25767/