Execute custom formula once per action

Hi there,

I'm relatively new to rpg maker, mostly still exploring the program's capabilities. I'm looking for some help figuring out how to have a custom formula that activates once per action instead of once per hit.

Short Version:

I'd like to use the note box to add a custom formula that activates either at the start or end of the action, instead of putting the formula in the damage box so that it activates once each hit.

The Very Long Version:

I'm creating a sample scifi game and wanted to have a gun that would sometimes apply a recoil state.

In the damage formula box I added the following after the damage formula (where state 28 is my recoil state)

;if rand <= 0.8 ; a.add_state(28); else; ; end

This makes it so there's an 80% chance the attacker is inflicted with the recoil state.It works exactly as intended with two exceptions.

1) Skills that hits multiple targets. Instead of having an 80% chance of recoil, the state almost always occurs because the code executes every hit!!!

2) If the attack misses the code never executes.

I managed to solve #1 but I'm still stumped for #2.

To resolve #1 I created another new state to behave as an action switch. The thought process was the state would get added on the first hit and last until the end of the action. I then nested the if statement to first check if the actor had this new state before executing the recoil code.

So first hit, the state would not be present and the custom formula would execute.

Second+ hits, the state would be present and the custom formula would not execute.

At the end of the action, the state would disappear so everything is reset for next time.

I managed to get this working after reading Fomar0153's custom formulae tutorial. I even made the percentage a variable

class Game_Battler < Game_BattlerBase

  def recoil(a,b,prob_perc)

    if a.state?(32); ; else; a.add_state(32); if rand <= prob_perc ; a.add_state(28); else; ; end; end

  end

end


Where state 32 is a custom state that acts as a switch that gets reset at the end of the action and state 28 is my custom recoil state. So now I just add ";a.recoil(a,b,0.8)" to my damage formula and the code activates.

However, since I'm using the damage formula box this script only activates on a hit. Is there a way to make separate it from the damage completely? Ideally I want to use the note box rather than having to hardcode this into the script editor for every skill.
Uhm, you can maybe just use a common event for that... just make a common event that adds that state to that actor, then make your skill run that common event... you can set a variable to a random number then check that variable on a conditional branch
Perhaps my Pre-Skill Eval could be of some assistance?  On top of the variables in the instructions, you can use subject for the user in place of a.
how did you make that damage selector on the script page???
I believe it had something to do with $game_message, and whatever scriptcalls are necessary to setup the the number input, throw in a wait for message command and boom! I just had the damage formula use whatever variable I used for it.
ah... so wait for message is also effective for that... didn't know that... XD...


HMMM... Now I wonder if I can whip-up something great with that script of yours... *goes to thinking mode - EX*


@OP - for all other needs, just use his script... 🙂
With my script there it allows for setting up messages before a skill is used, kind of why I originally made it but as the screenshot shows, it has some other benefits too xD.  The method I used for that screenshot can easily be used for a "gold throwing" skill, where you actually select the amount you use.

Edit: That's getting off topic tho, it should be capable of what DCF needs.
Thanks for the replies!

I'll look into the script provided.

Original thread: https://forums.rpgmakerweb.com/threads/execute-custom-formula-once-per-action.23448/