The code that runs when the engine reads your damage formula is this:
Code:
Game_Action.prototype.evalDamageFormula = function(target) {
try {
var item = this.item();
var a = this.subject();
var b = target;
var v = $gameVariables._data;
var sign = ([3, 4].contains(item.damage.type) ? -1 : 1);
var value = Math.max(eval(item.damage.formula), 0) * sign;
if (isNaN(value)) value = 0;
return value;
} catch (e) {
return 0;
}
};
The "item.damage.formula" is the damage formula that you write in the database. So any variable defined before that can be used.
Usually you want "a" (the subject, or user of the action), b (the target) and v (the list of game variables). But you also have available "item", which is what the engine calls the skill that's currently being used (because it uses the same structure to refer to skills, equipment and items).
So you can get the skill's cost with:
However, that just returns the skill's base MP cost. To get the cost after modifying it by the actor's MP cost rate SP-parameter, you can write:
If you're wondering what the engine calls a particular property of a skill - let's say you want to use the skill's TP Cost in the formula, but you don't know what to write to use it in the formula box - there's a quick trick for this. Write this in the formula box:
Then run your game, use the skill and press F8 to open the console window. There will be an "> Object" entry in the log. If you click on it, you see something like this:
That tells you everything you can use that's inside of the skill. So we can see that the MP cost that I used above is "item.mpCost". Similarly, if you wanted the TP cost, you would write "item.tpCost".
You can do the same thing to look inside the characters or the game variables. This way you don't have to remember what everything is called - if you forget, you have a way of looking it up.