Damage calculation in ability descriptions

I'm not actually sure if this is a possible script to create, since it would involve information in the editor.

Basically, what I'm looking to do is show damage calculations in an ability's description. For example, right now, I have an ability with the damage formula "((1.8 * a.mat) + 17) - b.mdf" and the ability's description reads "Deals 180% MAT plus 17 holy damage." I'd like it to be the case that, in game, when you go to select the skill, if you had, say, 30 MAT, it would simply read "Deals 71 holy damage."

If possible, it would be great if it could calculate the variance, too, so that if the above example has a variance of 20, it would say, "Deals 57-85 holy damage," but that's not as important. Since you can't know the enemy's magic defense until the skill and target have already been selected, it doesn't need to calculate that aspect.

Is this something feasible to do?
I always enjoyed specific information in RPGs. Having a damage output with variance included would take some of the guesswork out of things. Stuff like "Okay, I have an attack stat, with a strength stat, and a bonus here, and the target has HP, and defense, and resistances, so I should do about...uh...1-9999 damage?" can be frustrating and unnecessary.

I am not a scripter, so I'm sorry if you saw a reply and got your hopes up. I'm just a guy who is rooting for this idea to be made possible, haha.
Since you can't know the enemy's magic defense until the skill and target have already been selected, it doesn't need to calculate that aspect.
So what happens if the formula is "a.atk * 4 - b.def * 2"?
It will be better if you just supply the formula to be used for the description... since using the default one then parsing it in a way that it won't use any b. part can be quite a handful to do


and it is feasible to write up an escape code for the description box that does that
So what happens if the formula is "a.atk * 4 - b.def * 2"?
Well, I'm not looking to show the information in the damage formula box in the skill description - I'm looking for whatever I put into the description box to be calculated. So, for example, I might put in the formula box "a.atk * 4 - b.def * 2", then in the description box, put "Deals <a.atk * 4> damage." The player simply won't know how much the damage is going to be reduced by, but they'll be told how much damage it will do before defenses or critical strikes are factored in.

It will be better if you just supply the formula to be used for the description... since using the default one then parsing it in a way that it won't use any b. part can be quite a handful to do

and it is feasible to write up an escape code for the description box that does that
I know you can use \V in the description box, but I don't know how to make the description box do any kind of calculation. Is there some way to do "Deals \V[x]+17 damage" and have it come out something like "Deals 42 damage?" Also, how would I dynamically update stats during battle, like if a character gets a 10% MAT buff or something?

I suppose maybe I could have a common event running outside of battle that updates each actor's ATK and MAT before erasing itself, and then make every buffing skill also call a common event that recalculates the variable, but then how would I recalculate it again once the buff/debuff wore off?
You can try this


http://www.himeworks.com/2013/11/25/convert-code-eval/


But I don't know if it works for anything other than the message window out-of-box.


You might need another script that allows you to use these codes anywhere.
The user and the target are only viable parameters when you're about to execute the skill on a selected target. Since you don't have the target until the skill has already been selected, you can't do anything at the point where the skill's description is displayed, that involves the b parameter.


Hime, in the skill scene, you've already selected an actor. So you would know who 'a' is.
@OP - I never said to use \V, what I said was that we can make a new escape code that does that...
The user and the target are only viable parameters when you're about to execute the skill on a selected target. Since you don't have the target until the skill has already been selected, you can't do anything at the point where the skill's description is displayed, that involves the b parameter.
Right, I'm not looking to involve the target at all - I'm just looking for a way to do a formula calculation in the skill description box that only uses the user's ATK and MAT parameters, but it needs to be able to get them in real time.

I'll try the eval script Hime linked and see if I can do something like eval[1.8*a.mat+17] in the skill description box.

EDIT: I see I can only use game party, game troop, game switches, and game variables, so I can't use something like a.mat. Is there some sort of code like p.actor.mat or something that could get the current actor's MAT or ATK? As mentioned before, I could use common events to store each actor's ATK and MAT as variables (though this would be very cumbersome), and update them in another common event when a buff/debuff is applied, but I have no way of then updating the variable when a buff/debuff is removed.

@OP - I never said to use \V, what I said was that we can make a new escape code that does that...
I guess I'm not sure what escape codes mean, then.

But I don't know if it works for anything other than the message window out-of-box.

You might need another script that allows you to use these codes anywhere.
I tried doing \eval[v[24]] in the skill description window and in combat. It does display the variable correctly, so it does work for the description boxes and not just message windows. I just need some way to access the current actor's stats.
All the \ (escape character?) codes that you use on the text boxes... XD


try


\eval[sceneManager.actor.hp]


for example
I tried doing "\eval[sceneManager.actor.mat*1.8+17]" and it gives the error: undefined method 'actor' for SceneManager:Module. Did I make any typos or use the wrong term or anything?

If not, I think Hime's script is specifically defined to only use p (party), t (troop), s (switch), v (variable), looking at this section of code:

def eval_convert_code(formula, p=$game_party, t=$game_troop, s=$game_switches, v=$game_variables)    eval(formula)  endWould it be possible to add another section to the first line like "a=$game_actor" or "a=$game_actors" such that if I did "\eval[a.mat]" it would input the current actor's MAT?
oh wait, it should be SceneManager.scene.actor


using $game_actors directly isn't really recommended unless you're sure that in your game, each skill is only available to 1 actor
"\eval[sceneManager.scene.actor.mat*1.8+17]" gives the error "undefined method 'actor' for #<Scene_Battle:0x88ac5fc>"

I can confirm that there is no skill in my game that more than one actor uses, with two exceptions. There are two skills that two party members use, but they're only briefly in your party, though, and I could just copy their skills into separate slots so that they're technically using different skills that just function identically.
Well, Scene Battle doesn't have that... AFAIK only the menu scenes has the actor variable...

you can do something like put this script

module Zevia def self.actor if SceneManager.scene_is?(Scene_Battle) return BattleManager.actor else begin return SceneManager.scene.actor rescue return nil end end endthen do \eval[Zevia.actor.whatever_parameter]or

well if that's the case, then you can just use

\eval[$game_actors[id].whatever_parameter]
You need a proper solution, preferably with a completely custom help window. You don't want to mix a battle window with a regular help window.


Any hardcoded formula is going to fail everywhere else.
So using "Deals \eval[($game_actors[1].mat*1.8+17).to_i] holy damage" does work, producing the number I'm looking for. However, I'm trying to include variance, so I want to do something like

Deals \eval[(($game_actors[1].mat*1.8+17)*0.8).to_i] to \eval[(($game_actors[1].mat*1.8+17)*1.2).to_i] holy damage

Except that I get the error

"unexpected ']', expecting $end

...ctors[1].mat*1.8+17)*0.8).to_i] to <-eval[(($game_actors[1].m..."

I'm not sure what my syntax error is, though.

EDIT: So, when I put it into the skill description box as

"Deals \eval[(($game_actors[1].mat*1.8+17)*0.8).to_i]

to \eval[(($game_actors[1].mat*1.8+17)*1.2).to_i] holy damage"

instead of all on the same line, then I don't get any errors - is there some way to put "to" or "-" or something on the same line without the game thinking it's part of the formula?

You need a proper solution, preferably with a completely custom help window. You don't want to mix a battle window with a regular help window.

Any hardcoded formula is going to fail everywhere else.
What do you mean by that last line? Why would using a formula like that in the skill's description window cause anything else in the game to crash?


you can do something like put this script
 

module Zevia
def self.actor
if SceneManager.scene_is?(Scene_Battle)
return BattleManager.actor
else
begin
return SceneManager.scene.actor
rescue
return nil
end
end
end
then do \eval[Zevia.actor.whatever_parameter]


I tried that and got the error "uninitialized constant Window_Base::Zevia" when using the line "\eval[(Zevia.actor.mat*1.8+17).to_i]". I tried putting the script above and below Hime's eval script in the materials section - do I need to put it somewhere else?
I don't see why it looks for the module inside Window_Base... I haven't looked at Hime's script though so I don't know if that has something to do with it or if it's just the default way the method runs...
Any thoughts on how I might put two instances of "\eval[formula]" on the same line without getting the error "unexpected ']', expecting $end"?
maybe Hime has an answer for that... I never had problems with using multiple custom escape codes in 1 line... but then I don't use them much for descriptions
So you can see in this picture that, on the top version, it does exactly what I want it to do, except the numbers are on separate lines in the description (and thus the description doesn't fit in the box). In the bottom version, I've tried to put the numbers on the same line (same code, except everything's on the same line), but I get an error:

fg2jUp1.png


So I think the only thing I'm missing is figuring out how to get the numbers onto the same line, if anyone happens to have any thoughts. I'm not using anything except for Hime's Convert Code: Eval script, linked earlier in the thread.

Original thread: https://forums.rpgmakerweb.com/threads/damage-calculation-in-ability-descriptions.25736/