Gain state on critical or killing enemy, lose state when criticaled?

I have 3 states that represent 3 power levels.

How do I make an actor auto-gain a state when he kills or criticals an enemy, and lose it when he is criticalled? Or how to make the gain the negative state if they're criticalled?

and apart from those,

I'd be great if I could also get help on how to increase critical rate in proportion to the less MP the actor has, and how to make an actor's HP drop when he's out of MP and walking on the map, when I only have the ActorID as a variable.

Because my party can be rearranged in any way, and some actors are created via script, so I can't tell which actor is in the party in any moment other than getting their ActorID through 'Variable > Game Data > Party Member's Actor ID'

Sorry for all the requests I've been posting the past few days.

I'm so illiterate in programming...

Any help would be appreciated, any at all.

Thanks in advance!
Okay, I'll start the ball rolling, as some of this can be done through the damage formula.

For the sake of argument, let's say that the autostate IDs are 30, 31 and 32.  I think this is how you would apply the first state.  I don't have access to Ace at the moment, so you will have to check this.  I don't know how to identify if the target has been killed, so I'm lloking forward to seeing people's answers on that.

if b.result.critical; a.add_state(30); end; a.atk * 4 - b.def * 2

That is the formula for the actor's skill.  The skill for the enemy would have to identify if state 30 is present, and remove it.  Here's where it gets more tricky and not having Ace to hand is going to make this more difficult, because it is 2 "if" statements, but I think it would be something like this.

if b.result.critical; a.state ? (30) ?; a.remove_state(30); end; a.atk *4 - b.def * 2

Try those and see if they're okay before I make any further suggestion - or maybe someone will come along with a better idea.
Okay, I'll start the ball rolling, as some of this can be done through the damage formula.

For the sake of argument, let's say that the autostate IDs are 30, 31 and 32.  I think this is how you would apply the first state.  I don't have access to Ace at the moment, so you will have to check this.  I don't know how to identify if the target has been killed, so I'm lloking forward to seeing people's answers on that.

if b.result.critical; a.add_state(30); end; a.atk * 4 - b.def * 2

That is the formula for the actor's skill.  The skill for the enemy would have to identify if state 30 is present, and remove it.  Here's where it gets more tricky and not having Ace to hand is going to make this more difficult, because it is 2 "if" statements, but I think it would be something like this.

if b.result.critical; a.state ? (30) ?; a.remove_state(30); end; a.atk *4 - b.def * 2

Try those and see if they're okay before I make any further suggestion - or maybe someone will come along with a better idea.
Oh wow! I'm at work right now, so I can't test it out, but I'm sure that I'd be able to perform remove states by having states override other states in their settings, so at least I've that down. Thanks, ksjp17!

I'm no programmer, but by that logic,

would something like

if b.result.state? (death state)? a.add_state(30); end; a.atk*4 - b.def*2

work?

also,

would

b.result.critical = true if rand (100)< ((10*(a.mmp/a.mp))<100)

work for higher critical if MP is lower?
That might work for your death state (state ID 1, btw)

For your second formula, I suspect it might have to be the other way round, i.e. 

if (mp lower) then (result critical)

though I couldn't see what the random variable was doing there.  My brain is feeling mushy at the moment, so for the purposes of this, I'll ignore it.  It almost looks as if the critical is dependent on the random, rather than on the low MP.

What you also haven't got in your formula is what happens if MP is not low.  With the ordering I've suggested, you could have  the 'else' part

if ((10 * (a.mmp)/a.mp))<100); b.result.critical; end; normal_damage_formula_here

As I said, my brain is mushy right now, so that will need testing and I could be completely wrong.
That might work for your death state (state ID 1, btw)

For your second formula, I suspect it might have to be the other way round, i.e. 

if (mp lower) then (result critical)

though I couldn't see what the random variable was doing there.  My brain is feeling mushy at the moment, so for the purposes of this, I'll ignore it.  It almost looks as if the critical is dependent on the random, rather than on the low MP.

What you also haven't got in your formula is what happens if MP is not low.  With the ordering I've suggested, you could have  the 'else' part

if ((10 * (a.mmp)/a.mp))<100); b.result.critical; end; normal_damage_formula_here

As I said, my brain is mushy right now, so that will need testing and I could be completely wrong.
Oh, I just tried to understand a critical formula from another thread, apparently it was supposed to be a percentile chance? Your formula makes a lot more sense.

But this part

if ((10* (a.mmp/a.mp)) <100)

Does it mean that if the number is less than 100, then it will critical?

In the formula, the lower the mp, the bigger the number would be, so wouldn't that make the critical rate actually be higher when the mp is higher?

Thanks for helping me ksjp, I'm so slow when it comes to programming.
I just copied that bit about the mp over from your previous post.  As it stands that formula may not do what you want it to.  Let's say, for example, that your max MP is 256, and you are down to 70.

((10* (256/70))

= 37 (rounded figure)

That formula will always give a result of less than 100.

I'm not sure that you can do quite what you want.  I'll have a think about this.
I tried that cos' I thought I could simulate a percentage chance but after a bunch of tries it really didn't work very well. I started using this:

(( a.atk * 2 - b.agi ) /2 ).tap {b.result.critical = true if ( ((10*(a.mmp/a.mp))>(a.mmp/2)))}

and it kind of achieves what I want in a very strict fashion. I'll probably change up the (a.mmp/2) to balance it out as I go along.

Thanks for the help, ksjp!

But about the gaining a state after killing an enemy,

if there a way to just apply it to... all the skills, instead of having to include it in all the skills' damage formulae?
I'm afraid I can't think of a way of automatically applying it to every skill.  If it could be done (and I'm not sure it can) then it would probably require some esoteric modding to one (or more) of the default scripts - and that's way beyond my skill grade.

Sorry I can't help with that.
I know that when an enemy is killed, a command called die is called in the engine. Maybe an edit to the same part of code that calls the die command could do what you want? I would have suggested inside the die command, but I think a and b are undefined there so it would not know who to apply the state to hence why I'd find where that command is called, and make the edits there in a script snippet.

Unfortunately I'm at work right now, so cannot check more on this. But I think this should work.
Interesting ideas.

1) Apply states upon performing/receving Critical, KO, etc.: I'm actually working on a "Battle Effects" script that allows you to tag skills, actors, enemies, etc. with notetags to achieve the exact kind of effects that you're thinking of.  It's not available yet and will probably be a couple more months before I release it, since the scope of the script is far beyond what you're mentioning here.  But keep an eye out for it!

2) Increase Crit Rate based on current MP: This one isn't hard to do.  Find the item_cri method in Game_Battler:

  #--------------------------------------------------------------------------  # * Calculate Critical Rate of Skill/Item  #--------------------------------------------------------------------------  def item_cri(user, item)    item.damage.critical ? user.cri * (1 - cev) : 0  endModify it to take the user's MP rate into effect:

  #--------------------------------------------------------------------------  # * Calculate Critical Rate of Skill/Item  #--------------------------------------------------------------------------  def item_cri(user, item)    item.damage.critical ? (user.cri * (1 - cev)) * (2.00 - user.mp_rate) : 0  endThe example modification above will double a user's MP rate when they are at zero MP, multiply it by one and a half when they are at 50% MP, etc.

3) Drain HP when Walking with zero MP: This one's a little more complicated to script (deserves a separate request), and would also cause a slight hit to performance.  What I might recommend doing, since it's easier, is handling it through common events.

You could, for example, create a new State that saps HP while walking the map, and have a Common Event that's always running, but Waits 120 frames then checks each actor to see if they have any MP.  If they don't have any MP, it adds the HP Sap state to them.  If they do have any MP, it removes the state from them.  If you want to make it a bit more precise, you can also have any MP-restoring items remove the HP Sap state, since we know that the item's target is replenishing their MP and is therefore no longer at 0.
For #3, couldn't you add it to the regenerate command? Since that is called every 15 steps (by default), then it would kick in as often as the normal regeneration effects do. Just add a if check to see if mp is equal to 0, then if so do a negative HP regeneration.

Only thing is, this would also kick in inside of battle, at the end of turn. Not sure if the OP wants that.
Woahoah! Thanks, Wavelength! I tried it, it's still kind of hard to control the exact critical hit chance I'm expecting, but I suppose it's just a matter of thorough guess and check until I get it.

What is this regenerate command?

I didn't think of it at first, but if HP drains in battle with lack of MP, it could make the battles I have in mind a little more interesting. I'd have to test it out first though.

See, in my game MP kind of loosely represents... hunger. So it'd kind of make sense XD
Its under class Game_Battler < Game_BattlerBase, and the command is regenerate_hp. It's called at the end of every combat round, and every 15 steps or so (or whatever you set in the engine as the number of steps that equals one turn). I think the following would work (untested as I'm at work, but in theory it should work). Add this as a its own script in materials and above main.

class Game_Battler < GameBattler_base

alias theoriginal_regenerate_hp regenerate_hp

def regenerate_hp

if(self.mp == 0)

  *add your code here to make it a negative regeneration

else

   theoriginal_regenerate_hp

end

end

This would ignore the default HP regen when mp is zero though, so if you want things like HP Regen skills to still kick in when mp is 0, it will need some tweaking.

Original thread: https://forums.rpgmakerweb.com/threads/gain-state-on-critical-or-killing-enemy-lose-state-when-criticaled.42916/