Formula Effects

This script allows you to execute arbitrary formulas as an effect.

By default, you have a damage formula that allows you to execute scripts within the context of a damage formula object.
You can now move any non-damage-related logic from the damage formula into a formula effect.

Effect formulas are executed within the context of the interpreter, which is more useful since many scripts add convenience methods to the interpreter (rather than the damage formula).

You have access to a number of references such as the user, the target, and the user’s current action among other standard formula variables.

This is a stand-alone script and does not rely on my Effects Manager. As a result, it does not have all of the functionality that the Effects Manager provides.

Download

Script: download here

Installation

In the script editor, place this script below Materials and above Main

Usage

To create a formula effect, note-tag your item or skill with

<formula effect>
   FORMULA
</formula effect>

Where the formula can be any valid formula.
The following formula variables are available

a - user
b - target
c - user's action (Game_Action object)
t - current troop
p - current party
s - game switches
v - game variables

You can access the skill or item that the user is currently using via c.item

You may also like...

24 Responses

  1. john says:

    Just want to note that trying to reference result damage values, such as b.result.hp_damage, in a formula effect does not work if the project is using Ace Battle Engine. Instead the developer will need to add and use attr_accessor for values “stored” by Ace Battle Engine, like so:

    class Game_ActionResult

    attr_accessor :stored_hp_damage
    attr_accessor :stored_mp_damage
    attr_accessor :stored_tp_damage
    attr_accessor :stored_hp_drain
    attr_accessor :stored_mp_drain

    end

    I wasted a lot of time figuring this out, so I hope this stops someone else from doing the same.

  2. AngryAragami says:

    Is there a way to run these formulas either as the damage calculation or before the damage? Because I have written a damage formula that I want to use for all my skills, but have been thwarted by the damage formula box’s charector limit.

    • Hime says:

      I don’t think I have a script that will allow you to execute effects before a skill was applied.

      • AngryAragami says:

        Alright then. Will effects caused by this script show up on the battle log? What I’m trying to do is set up a system where it generates a random number from 1 to 100, then compares the users atk stat and the targets def stat and adds the difference to a number, say 50, and then if that result is greater or equal to the random number the skill deals damage, or displays a failure message if the result isn’t greater than the random number. And please don’t tell me to just mess with Hit and Eade percentages, as the way those work just doesn’t work with my needs.

        • Hime says:

          You will not be able to manually display your own custom messages.
          If you want to show that damage was dealt, or HP was recovered, you will need to write something like

          @result.hp_damage += 50
          @result.hp_damage += 100
          

          The game takes the “result” and uses it to determine what messages to display.
          So this example would show that 150 damage was dealt in total.

          • AngryAragami says:

            Thank you for your help.

          • AngryAragami says:

            As an extra question, do you know how I could change the ‘action fail’ text with a script call of some kind? Cause I could make my system work well if a common event could change the failure message before getting to the effects these formulas produce.

          • Hime says:

            The action fail text is shared among all skills so it would not be a good idea to simply change it. You would need a plugin to customize fail message for each action.

  3. sean says:

    I am a total newb to ruby and this program. I am simply trying to make an item (specifically a magic tome which costs the reader a certain number of mmp (ie 1 point) for reading it and learning the spell. I don’t know the exact formula needed for such a thing. Is it something like putting this in the notes

    a.mmp -= 1
    </formula effect>

    • Hime says:

      For gaining or losing max parameters, you would use the formula in your note-tag a.addParam(1, -1)

      This would decrease the specified param by 1.

      1 is an internal ID that refers to max MP, and -1 is just subtracting by 1.

  4. Murd says:

    If I put a formula in a skill, it will be executed only when the skill is used, am I correct?

    Is there a way to make the formula executed automatically once learn (without using it)?

  5. Arsist says:

    Wow. I agree, this is useful. So, I see that this occurs after the HP Damage has been calculated. But I also can’t reference the resulting HP damage (such as “if b.result.hp_damage > 1 then a.tp += 100 end”). So is there a way to condition based what the HP damage would be? Curious.

  6. Koldsack says:

    I concur with Dave on this one. I’m using this one through Hime’s skill conditions script which makes a formula call: formula: $game_switches[14]. when switch 14 is on, do something. Thx Hime, your stuff are extremely straightforward and useful hats off.

  7. Dave says:

    I don't know if anyone will see this, but I just had to say THANK YOU! to Hime. Every time I have a problem I can't solve on my own, there is a Hime script to save me. I can't believe nobody else has commented on this script, there is so much that I can finally do because of it.

  1. October 16, 2014

    […] because they are handled differently. If you require conditions for your common events, you can use Formula Effects and then call the common event using […]

Leave a Reply

Your email address will not be published. Required fields are marked *