MZ Is there a formula for damage output-based spell costs?

Is there a way to write a damage formula for spell cost based on damage output? Like, the more damage you do the more it costs to cast the spell in the first place? I'm asking because I'm using Synrec's Skill COnstruct plugin to give the player the illusion of being able to "make custom spells," but I realized that with how absolutely busted this system would make the character I would either need to attach a damage-based spell cost formula to custom spells, or make different tiers of custom spells that have a static cost but only allow certain tags/effects to be attached to the spells.
It seems complicated and difficult to achieve with a single skill.
Why not try creating a skill that increases the user's attack power or damage, and also increases their MP cost? I think that would be easier and less complicated to create.

For example: Double the user's attack power, but also double their MP cost for 5 turns.
Yea...a skill's cost is determined beforehand, to ensure it can be used: if you can't pay the cost, you can't use the skill in the first place. Rifleman_XM8's idea seems much more practical.

Otherwise, here are some other ideas:
Spoiler: ideas
  1. Make the skill cost depend on the user's stats.


  2. Apply an extra cost after the skill is used, based on the damage it dealt.

    • If the skill is unique to 1 actor or enemy, then this is feasible via Common Event: just make the damage formula store the result in a variable, e.g.

      var dmg = a.atk * 4 - b.def * 2; v[123] = dmg; dmg
      I.e. calculate the damage, store the damage in variable ID 123, then return the damage. You can then refer to that variable in a common event attached to the skill.

    • Otherwise I would recommend a plugin that offers relevant triggers for script calls, e.g. Turan's Eval Tags or VisuStella Battle Core.

  3. Precalculate the skill damage to determine the cost.

    • If the damage is stored in variable ID 45, the damage formula could simply be v[45]. The skill cost could be customised using a plugin like one of those I linked for option 1.

    • You would need to decide when to calculate the damage. Maybe a troop event that runs every turn? A plugin like those I mentioned in option 2 would probably be helpful.

    • This would probably be quite awkward if multiple characters can use the skill, unless you want the damage value to be the same for all characters.
Yea...a skill's cost is determined beforehand, to ensure it can be used: if you can't pay the cost, you can't use the skill in the first place. Rifleman_XM8's idea seems much more practical.

Otherwise, here are some other ideas:
Spoiler: ideas
  1. Make the skill cost depend on the user's stats.

  2. Apply an extra cost after the skill is used, based on the damage it dealt.
    • If the skill is unique to 1 actor or enemy, then this is feasible via Common Event: just make the damage formula store the result in a variable, e.g.

      var dmg = a.atk * 4 - b.def * 2; v[123] = dmg; dmg

      I.e. calculate the damage, store the damage in variable ID 123, then return the damage. You can then refer to that variable in a common event attached to the skill.

    • Otherwise I would recommend a plugin that offers relevant triggers for script calls, e.g. Turan's Eval Tags or VisuStella Battle Core.

  3. Precalculate the skill damage to determine the cost.
    • If the damage is stored in variable ID 45, the damage formula could simply be v[45]. The skill cost could be customised using a plugin like one of those I linked for option 1.

    • You would need to decide when to calculate the damage. Maybe a troop event that runs every turn? A plugin like those I mentioned in option 2 would probably be helpful.

    • This would probably be quite awkward if multiple characters can use the skill, unless you want the damage value to be the same for all characters.
Yea, the idea that I'm going with right now is that "custom spells" are unique to the player character who'll be perma-locked to the slot of party member 1. I think I actually quite like the idea of applying an additional cost after the fact of using the skill. I think I follow your notes on the second option well enough, too. Basically you're saying that the "dmg" at the end of "dmg; dmg" will return the damage number stored in the variable and "run" the damage then?

I don't have Eli's skill costs or cae's tweaks, but I do have Visustella's skills and states plugin, as well as the battle core. You're suggesting I might be able to customize cost based off the number stored in the damage variable with something like the <JS Cost Type> notetag? I'll have to try that.

The reason I ask is because it seems to me that Synrec's Skill Construct plugin is set up in such a way that while it lets you augment pre-existing skills in-game dynamically with skill tags, said tags don't include an option to customize cost type override. Only magnitude, scope and damage type overrides.
Basically you're saying that the "dmg" at the end of "dmg; dmg" will return the damage number stored in the variable and "run" the damage then?
It will return the value that it stored in the game variable, yes. The engine will handle the value as usual from there. I don't know what you mean by '"run" the damage'. 😅

You're suggesting I might be able to customize cost based off the number stored in the damage variable with something like the <JS Cost Type> notetag?
If "the damage variable" is a variable where a value was stored, in advance, representing the damage output for that skill if it gets used...then yes. You can't reference the damage that was actually dealt to a target before the skill has been selected for use, because that violates causality.
  1. If adjusting the cost based on the user's stats then you just need to look at the custom cost options in your chosen plugin. E.g.

    <JS MP Cost> // Half current MP, rounded up. cost = Math.ceil(user.mp / 2); </JS MP Cost>
    I think this is my favourite option: it's predictable for the player and easy to implement. 👋

  2. If paying an extra skill cost after the damage then you can apply that with a Common Event or, more conveniently, an appropriate plugin notetag. E.g. <JS Post-Damage> from VisuStella Battle Core:

    var dmg = (a.mat + a.mp) * 2 - b.mdf; v[123] = dmg; dmg
    <JS Post-Damage> // Fetch damage value stored in game variable. const value = $gameVariables.value(123); // Calculate extra MP cost based on that value. const cost = Math.floor(value / 5); // Apply that extra cost to skill user. user.gainMp(-cost); // Show popup? user.startDamagePopup(); </JS Post-Damage>
    I think that tag might offer a value variable already, representing the damage dealt by the skill? In that case you wouldn't need the game variable stuff, so you could try something like:

    (a.mat + a.mp) * 2 - b.mdf
    <JS Post-Damage> // Calculate extra MP cost based on the damage value. const cost = Math.floor(value / 5); // Apply that extra cost to skill user. user.gainMp(-cost); // Show popup? user.startDamagePopup(); </JS Post-Damage>

  3. If calculating the cost in advance based on a damage estimate, you need to decide when to do that. In general if you calculate it too seldom or too often, then the damage values used for skill cost (displayed/paid) and damage output (formula) might be different and/or incorrect.

    If your formula doesn't actually reference the skill target, b, then you can simply calculate it in the cost, e.g.

    v[45]
    <JS MP Cost> // Calculate damage value. const dmg = user.mat + user.mp; // Calculate cost based on damage value. cost = Math.ceil(dmg / 5); // Store damage value in variable ID 45, for reference in the damage formula. $gameVariables.setValue(45, dmg); </JS MP Cost>
    Otherwise, like I said, plugin notetags or a Turn-span troop event may be helpful. Once you've figured that out, you can simply reference the stored damage value in the cost and the skill's damage formula.
(I haven't tested any of these examples, and I don't know how any of these approaches might interact with Synrec's Skill Construct plugin.)
It will return the value that it stored in the game variable, yes. The engine will handle the value as usual from there. I don't know what you mean by '"run" the damage'. 😅


If "the damage variable" is a variable where a value was stored, in advance, representing the damage output for that skill if it gets used...then yes. You can't reference the damage that was actually dealt to a target before the skill has been selected for use, because that violates causality.
  1. If adjusting the cost based on the user's stats then you just need to look at the custom cost options in your chosen plugin. E.g.

    Code:
    <JS MP Cost>
     // Half current MP, rounded up.
     cost = Math.ceil(user.mp / 2);
     </JS MP Cost>

    I think this is my favourite option: it's predictable for the player and easy to implement. 👋

  2. If paying an extra skill cost after the damage then you can apply that with a Common Event or, more conveniently, an appropriate plugin notetag. E.g. <JS Post-Damage> from VisuStella Battle Core:

    var dmg = (a.mat + a.mp) * 2 - b.mdf; v[123] = dmg; dmg

    Code:
    <JS Post-Damage>
     // Fetch damage value stored in game variable.
     const value = $gameVariables.value(123);
     // Calculate extra MP cost based on that value.
     const cost = Math.floor(value / 5);
     // Apply that extra cost to skill user.
     user.gainMp(-cost);
     // Show popup?
     user.startDamagePopup();
     </JS Post-Damage>

    I think that tag might offer a value variable already, representing the damage dealt by the skill? In that case you wouldn't need the game variable stuff, so you could try something like:

    (a.mat + a.mp) * 2 - b.mdf

    Code:
    <JS Post-Damage>
     // Calculate extra MP cost based on the damage value.
     const cost = Math.floor(value / 5);
     // Apply that extra cost to skill user.
     user.gainMp(-cost);
     // Show popup?
     user.startDamagePopup();
     </JS Post-Damage>


  3. If calculating the cost in advance based on a damage estimate, you need to decide when to do that. In general if you calculate it too seldom or too often, then the damage values used for skill cost (displayed/paid) and damage output (formula) might be different and/or incorrect.

    If your formula doesn't actually reference the skill target, b, then you can simply calculate it in the cost, e.g.

    v[45]

    Code:
    <JS MP Cost>
     // Calculate damage value.
     const dmg = user.mat + user.mp;
     // Calculate cost based on damage value.
     cost = Math.ceil(dmg / 5);
     // Store damage value in variable ID 45, for reference in the damage formula.
     $gameVariables.setValue(45, dmg);
     </JS MP Cost>

    Otherwise, like I said, plugin notetags or a Turn-span troop event may be helpful. Once you've figured that out, you can simply reference the stored damage value in the cost and the skill's damage formula.
(I haven't tested any of these examples, and I don't know how any of these approaches might interact with Synrec's Skill Construct plugin.)
Y'know, thinking about it yea I think doing something like your first example where damage cost is based on one of the user's stats would probably work better then scaling cost specifically based on how much damage the skill actually does on-hit seeing as my thinking was that all custom skill tags made with Synrec's plugin would use damage formulas to determine how much damage they do anyways, as opposed to their just doing a flat amount of extra damage added to the augmented skill. That idea hadn't even occurred to me at first, lol. One of the reasons that I think your way is probably better is actually that, despite user-stats-based costs being something that will probably end up lower then the cost of a particularly powerful skill, since I'm using Visustella's PTB system powerful custom skills that just aren't effective against certain enemies would have the unintended effect of ALSO costing less, it seems like. So doing things like how you suggested would probably be better since it would add a bit more balance to skill costs.

Thank you so much for this detailed rundown! Because I'm terrible at JS still and still have no idea what stuff like half the SP-parameters in MZ are supposed to do, lol

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-formula-for-damage-output-based-spell-costs.182986/