Formula Effects

Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

formulaEffects1

All items and skills in RPG Maker come with additional “effects”.

Effects include gaining HP, learning a skill, gaining a buff in a parameter, or running a common event.

However, what if you would like a skill to do something that isn’t provided by default?

You could use the damage formula, but what if you would like to create conditions on those effects? You could include those conditions in the formula as well, but the problem here is you may end up with a very complex damage formula.

Instead of using the damage formula for everything, you can create custom effects that support formulas. If you already knew how to write the formula, then you can just move it from the damage formula into this formula effect.

Because a formula effect is just another effect, it supports other plugins that work with effects, such as Effect Conditions, which allows you to determine whether an effect should be executed based on a condition.

Download

Plugin: download here (right-click, save-as)

This plugin is for RPG Maker MV only. Click here for the Ace version!

Installation

Download the plugin and place it in the “plugins” folder in your project’s “js” folder. Then open your Plugin Manager (F10), double-click an empty row, and select the HIME_FormulaEffects plugin.

Once it is in your list of plugins, turn the plugin on.

Usage

To create a formula effect, note-tag items or skills with

<formula effect>
  FORMULA
</formula effect>

Where the FORMULA will be evaluated during skill execution and the behavior is determined by what you write in the formula.

The following formula variables are available

 a - attacker
 b - target
 i - current item or skill
 v - game variables
 s - game switches
 t - game troop
 p - game party

So for example, if you wanted to reduce the target’s HP by 100, you could use the formula

b.gainHp(-100);

You can access the result of the action on the target using

var r = b.result()

With this, you can then check how much HP damage or MP damage was dealt

r.hpDamage
 r.mpDamage

And then use this in your effect calculations.

Anything that is defined in the code can be used as an effect.

Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

You may also like...

15 Responses

  1. Serpenter says:

    I was wondering if I could use this to make a skill leave an enemy with 1 point of health if it would normally kill it?

  2. Anonymous says:

    Nevermind on calling events, got it to work, great work here!

  3. Anonymous says:

    Is there a way to call a common event?

  4. Sundricat says:

    Using script functions, how would I subtract the value of Variable 42 from the value of Variable 41?

    • Hime says:

      $gameVariables.setValue(42, $gameVariables.value(42) – $gameVariables.value(41));

      Which takes the value of variable 42, subtract value of variable 41, and then put the result into variable 42.

  5. Sundricat says:

    How would I set up the formula effect to make a spell drain 25% of the Users Max MP when cast?

  6. Izmeiah says:

    I have a newbie kind of question. Would it be possible to have this affect a creature(s) such that if their hp is < – x%, that they are affected by a state, such as death?

    • Hime says:

      Yes. You can a condition to check whether the target (b) HP is less than a certain percent, and then add the specified state.
      if (b.hp < b.mhp * 0.10) {
      b.addState(1)
      }

      So you’re checking whether the target’s current HP is less than 10% of their max HP.
      If so, you would add the death state.

      • Izmeiah says:

        Thank you so much for your fast response! I see what I was doing wrong when I was trying to implement this formula.

  7. Sundricat says:

    Is it possible for the formula effect to target the user?

    • Hime says:

      Yes. You can use the variable a in your formulas, similar to the damage formulas.
      It assumes the “attacker” is the user of course.

      • Sundricat says:

        How would I set up the formula effect so that 25% of the total damage dealt is dealt back to the user as recoil?

        • Hime says:

          The total damage can be accessed via b.result().hpDamage.
          Note that you are accessing the action results for the target, not the user.

          So now you just need to use

          a.gainHp(-b.result().hpDamage * 0.25)

          To inflict 25% of damage to the user.

  8. Michael says:

    Thank you so much, this is a really helpful script!

Leave a Reply

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax