I need a script call which can identify if the enemy attacked has died or not.
The same sort of structure as
if b.result.critical;
but in this instance testing if the result is death - either a straightforward identification or perhaps using something like b.hp = 0
I've tried various combinations, but nothing works.
Thanks.
Identifying an enemy has been killed
● ARCHIVED · READ-ONLY
-
-
-
@TheoAllen Yes, for use in the damage formula. So it would be something along the lines of
if b.result[whatever it is to indicate the enemy has been killed by this skill]; [some actor buff or other]; end; damage formula -
@Kes I fail to understand why you want to check if target is dead, when the damage formula is not even executed yet. The logic is, it won't be dead if it didn't get the damage. Ofc it won't work, bcz the damage formula is just to determine the value of damage, and the time the formula is evaluated, it doesn't immediately executed. Here is the illustration:
You can use "b.result.critical" because checking if it's land critical is checked before the formula is evaluated. But checking if it's dead, upon the damage formula evaluation, it isn't yet delivered. It couldn't check if it's dead bcz ofc it isn't dead yet.
Or, is it a skill that targets dead ally/enemy? -
@TheoAllen The skill does not target dead enemies.
What I am trying to do is to give the specific actor who kills an enemy with this particular skill a TP boost. Can you suggest an alternative way of going about this? -
I did this in my project by making a check after the damage is done (after the execute_damage call), if the target is killed ( hp <= 0), it runs the code specified by a notetag in the skill (and other game objects).. So basically I modified the item_apply method to do it
something like
Code:execute_damage(user) #Add the check after the execute_damage kill_effect(user,item) if self.hp <= 0
with the kill_effect method basically checking the actor, classes, equipment and states for the presence of a notetag that I've set to determine what things to do upon killing a target
But ofc its a bit hazardous since I directly modified the script, but in my case its fine because all battle related stuff in my game was made by me anyway.. You can also opt to just alias item_apply and check if the target dies after calling the aliased method.
Also take note that this of course is for a general purpose "on kill" effect which can generate any effect that you might want
Alternatively, you can always just check the current HP of the target in your formula and if its less than the damage, do the effects that you want. It would ofc happen before the actual damage though
Code:x=damage_formula;if x >= b.hp; then; a.tp += value;end;return x
But depending on your added systems, it might not be foolproof to check beforehand (like if you have an auto revive system or killing blow blocking abilities etx) -
@Kes Go try to edit item_user_effect in Game_Battler line 713 (although this one actually deserve their own thread)
Code:The default is like this. Use these to address the user / targetclass Game_Battler def item_user_effect(user, item) user.tp += item.tp_gain * user.tcr end end
- user = the user of the skill / item
- self = the target of the skill / item
Code:This one will buff TP gain by +50%class Game_Battler def item_user_effect(user, item) user.tp += item.tp_gain * user.tcr # <-- default formula user.tp += 10 if self.dead? end end
Code:If you want it only valid for actor, use thisclass Game_Battler def item_user_effect(user, item) user.tp += item.tp_gain * user.tcr * (self.dead? ? 1.5 : 1.0) end end
Code:class Game_Battler def item_user_effect(user, item) user.tp += item.tp_gain * user.tcr # <-- default formula user.tp += 10 if user.actor? && self.dead? end end -
@TheoAllen You're right, this had got too big for script calls, so I've moved all the posts into their own thread.
I can understand (I think) what the edits you have suggested will cause to happen, and I think that the way they are written will mean that no matter how the enemy is killed, the user will get the TP bonus. However, I want this tied to a particular skill so that it happens then and only then.
Would this mean doing this in a custom damage formula snippet? And if so, where the the actual damage part of the formula go?
Sorry to be so dense on this, I just can't get it straight in my head.
@Engr. Adiktuzmiko Thanks for the suggestion. I'm a bit reluctant to go down that route, as I have all sorts of things which modify battles and it looks to me from your description that I could end up with clashes. -
@Kes yea I forgot that you want it specifically for a certain skill since you originally want it to be in damage formula. In that case, you can check the item by using the keyword "item". For example:
Code:class Game_Battler def item_user_effect(user, item) user.tp += item.tp_gain * user.tcr # <-- default formula user.tp += 10 if item.is_a?(RPG::Skill) && item.id == <replace with skill ID> && self.dead? end end
Edit:
Does this tutorial answer your question? https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-vxace-and-mv-damage-flow.4219/And if so, where the the actual damage part of the formula go? -
@TheoAllen Thanks, I'll dig around in there and see what I can come up with.
Your help is, as always, much appreciated. -
Could this not be done using a common event (which gets executed after all the damage), using the user and target that are still stored in the internal variables (which I can never remember)?