If/else command request for damage formula.

One of the character classes in my game is a goo girl. One of her abilities involves engulfing an enemy and digesting them while the battle rages on.Digesting an enemy slowly damages them while slowly healing the goo girl. I have two states setup for this, digested and digesting. However, I'm having trouble getting the skill to function as I want. Essentially, what I want to have happen, is something along these lines (in grossly simplified terms):


if = enemy is successfully afflicted with state(id1), then user is afflicted with state(id2)


else;


nothing.


In otherwords, if the player uses "Engulf Target" and the state is successfully applied, then the character who used it gets a state applied to them too. If the attack fails and then nothing happens. No states are applied to anyone.


I am wondering if there is a way I can do this using the damage formula box, since that thing is crazy powerful and its usefulness is woefully understated. I want to have this work using skills and avoiding common events, since common events just seems like it's going to be problematic as it's hard to check which character used what. Considering I have 27 character slots and 22 character classes, that would be an insanely huge common event to check and see which character is using what skill on what enemy and if it worked...
Not really, because the states are applied after the damage is calculated.  If it's possible for the state to be resisted, you won't know, when the damage formula gets calculated, whether the state is going to be applied or not.


I suggest you attach a common event to the skill - as this will be the very last thing that gets run, the damage will have been dealt and the state would have been applied to the target by the time it runs.


In your damage formula, you can put something like this:

Code:
v[1] = a; v[2] = b; real_damage_formula_here

which will put the actor into variable 1 and the target into variable 2 (replace 1 and 2 with variables you have available for this purpose).  Then in your common event you can do this:

Code:
Conditional Branch: Script: $game_variables[2].state?(15)
  Script: $game_variables[1].add_state(16)
Branch End

again replacing the 1 and 2 with the appropriate variable ids, and the 15 and 16 with the appropriate state ids.
There were a couple errors but I managed to fix it. I was using a script call instead of putting that first part into a conditional branch to start. Thank you a bunch! It's awesome to see this actually working now!


My only concern is that the status icon doesn't update on the end of the turn. Is there a script call I can do to force update status icons? It's not really a big deal, just a small quality of life thing.


Lastly, I use yanfly's skill restriction script. Do you know how I'd be able to add onto the same conditional branch that if the skill lands, a cooldown is placed on the skill?


Thank you again!
Instead of add_state, try calling add_new_state which does a few other things, including refreshing the battler.


With the Yanfly question, sorry, I have no idea.  I'm not familiar with the script.  There might be someone else who can fill in the blanks there.  As a guess though, the skill landing and the state being applied are two different things - I would imagine it would already cater for a cooldown if the skill lands - you just need to set it up in the notes of the skill, not as part of the conditional branch.
add_new_state didn't work and actually caused a crash with the following error!


---------------------------



Script 'Game_Battler' line 246: NoMethodError occurred.


undefined method `>' for nil:NilClass
oh no, add_state was correct - it calls add_new_state.


I imagine there would need to be a refresh somewhere to update the status icons.  I can't see where, after a quick look through, and don't have time to go into it more thoroughly.  Sorry.
That's fine. It's only a small quality of life change, definitely not necessary. Thank you Shaz!

Original thread: https://forums.rpgmakerweb.com/threads/if-else-command-request-for-damage-formula.69893/