Doing things to an unknown/completed damage formula [VX Ace] (SOLVED)

Heyo!

-Edit-
Solved thanks to help from TheoAllen. Thanks to everyone for all the tips and thoughts. Thread is now being closed.
-End of Edit-

So I was toying around trying to find a way to alter damage formulas via the Script Editor and ended on this answer:

Damage Formula Help 4.png

(original thread here: https://forums.rpgmakerweb.com/inde...ipt-editor-vx-ace-solved.124909/#post-1099549 )


But, since then, I've been struggling to find a way to make a skill multiply the original skill damage formula by X when conditions are met (like a standard if statement checking the Regular Expression of a Notebox area for example).

Add on top of that, that I got these messages on me profile:

Damage Formula Help 3.png


And I'm beginning to think maybe my original solution wasn't ideal after all.

So!

If anyone's got any tips on the subject or advice on how to multiply the result of a damage formula via the Script Editor (without needing to then edit the formula section of the skill in the Database) then by all means share.

I've tried a LOT of variations on my original solution, but what it basically boils down to is I don't know how to get this kind of code: item.damage.formula * 100

To provide the result of the damage formula's result * 100 (instead of just making the game run the original formula 100 times like that example does).

I've tried messing around with .eval and .result but neither of those worked for me.

And that's that!

I'll leave this thread open for a while after any seeming solutions are found this time, just in case anyone wants to add anything again.


All the best,
- The_Sarah
But, since then, I've been struggling to find a way to make a skill multiply the original skill damage formula by X when conditions are met (like a standard if statement checking the Regular Expression of a Notebox area for example).
Specifically for your case, in your example, there is nothing from stopping you from just write "a.atk * 100 - b.def * 2" in skill 1. Because, why notetag? The notetag is persistent through the game, unlike other conditions like the influence of states. That was not the perfect example for this case.

If anyone's got any tips on the subject or advice on how to multiply the result of a damage formula via the Script Editor (without needing to then edit the formula section of the skill in the Database) then by all means share.

I've tried a LOT of variations on my original solution, but what it basically boils down to is I don't know how to get this kind of code: item.damage.formula * 100
Here are some of the approaches.

The first solution (and the easiest) that you don't need a separate script at all.
Code:
damage = a.atk * 4 - b.def * 2; damage * (a.state?(21) ? 2 : 1)
If the user has state 21, multiply damage by two.

The second solution that if you REALLY need to alter the skill for whatever reason (maybe you want to create a battle system). Always make a deep copy of the skill.
Code:
skill = Marshal.load(Marshal.dump($data_skills[10]))
This will make a whole copy of skill 10. So you can freely change the skill 10 property without changing the original one. As to how to change the formula, it can be as simple as
Code:
skill.damage.formula = "(#{skill.damage.formula}) * 100"
This means, the original damage formula but multiplied by 100.
Then of course you need to use this skill variable for dealing damage and all.
Specifically for your case, in your example, there is nothing from stopping you from just write "a.atk * 100 - b.def * 2" in skill 1. Because, why notetag? The notetag is persistent through the game, unlike other conditions like the influence of states. That was not the perfect example for this case.

Right, sorry if the example was weirding you out, basically I'm working on a Throw script but the code of it is all over the place at the moment (but it works!) so it'd be hard to share in its current state.

As a result, I tried to come up with an example that was easy to read and understand that I could then apply the logic of to what I'm struggling with in the Damage Formula part of my Throw script.

Basically, I'm now working with this example script in my attempt to manipulate Damage Formula purely in Script Editor (ideally without needing to know what the actual Formula originally looks like):

Damage Formula Help 5.png



But in using your bit of code you suggested here as a template:

Code:
skill.damage.formula = "(#{skill.damage.formula}) * 100"

I end up with a situation where the skill incrementally adds a " * 100" to the damage formula of the skill (in this case Attack, skill 001) each time the skill is used.

Which ends up with something like this (in the console):

Damage Formula Help 6.png



In an ideal world, what I am trying to achieve is adding that multiplication onto the end of the damage formula without knowing the original formula (just like this has done so in the above images)... BUT!

Then, after the damage has been done, the formula for the skill reverts to whatever its original state was.

The logic being that my Throw script (not pictured) would thus be able to take whatever damage formula the user wants to have for their default Throw damage... and multiply it by different multiplications depending on the notetag they have in the item/weapon/armour they are throwing.

Again, I've got all my code working for registering the different item/weapon/armour IDs and their individual notetags, so you see the reason I'm after this Damage Formula solution to my example skill script is because I have yet to figure out how to make it so when a skill is used, its formula is multiplied by an amount in my Script Editor and then reset to normal for the next time that skill is used.

Right... I hope that all made sense.

Sorry if the stuff about Throw scripts confused you, that's just the bigger picture behind the why I'm trying to figure this out.

The important thing is that I need to figure out how to multiply a skill's formula (on cast) by an amount using just the Script Editor and then have that formula revert to normal -once the damage is done- for the next time that skill is used.
In an ideal world, what I am trying to achieve is adding that multiplication onto the end of the damage formula without knowing the original formula (just like this has done so in the above images)... BUT!

Then, after the damage has been done, the formula for the skill reverts to whatever its original state was.
Here is your ideal world.
Go look up at Game_Battler > make_damage_value
This is the original code
Code:
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    @result.make_damage(value.to_i, item)
  end
And you can just pretty much add anything in it
For example
Code:
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= 2 if @conditionexample # << add this
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    @result.make_damage(value.to_i, item)
  end
You don't need to touch the damage formula at all 😀
Here is your ideal world.
Go look up at Game_Battler > make_damage_value
This is the original code
Code:
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    @result.make_damage(value.to_i, item)
  end
And you can just pretty much add anything in it
For example
Code:
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= 2 if @conditionexample # << add this
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    @result.make_damage(value.to_i, item)
  end


It works! And doesn't appear to be stacking on forever! Hooray!!!!!!
Here's an example of it with example code for any onlooking readers:
Damage Formula Help 7.png


You don't need to touch the damage formula at all 😀

I've found with Ruby (aka my first coding language) the solutions to my problems all too often end up being something simple like a typo or me having being looking in the wrong place.

I appreciate it is a learning experience but it still makes me feel rather silly each time lol XD.

Thanks so much!!!!!!!!!!!!!!!!!!

I'll report this thread for closing within the next 12 hours or so, just in case someone else like you feels like popping in with something additional that I didn't expect.

I'll also make sure to leave a thanks to you in the completed Throw script when it's cleaned up and released publicly 🙂
Here's a suggestion on how to change an item's value inside the make_damage_value_method.

Code:
my_note = item.note[/multiplier \d+/i] || '100'
value *= my_note.scan(/\d+/)[0].to_i

If you set the tag with a value like 250, well, that'll become the value multiplier there. You'd get 100 as its default value otherwise. It'd help you avoid issues because of that dreadful nil return value.
Here's a suggestion on how to change an item's value inside the make_damage_value_method.

Code:
my_note = item.note[/multiplier \d+/i] || '100'
value *= my_note.scan(/\d+/)[0].to_i

If you set the tag with a value like 250, well, that'll become the value multiplier there. You'd get 100 as its default value otherwise. It'd help you avoid issues because of that dreadful nil return value.

I don't think that'll work for my Throw script... unless I'm misunderstanding.
Thanks for the tip though, I'll be uploading me Throw script tonight and it will undoubtedly have areas (probably including the make_damage_value method) that can be shortened and/or neatened, so feel free to check it out and post any tips there too.

For now though it's been basically 24 hours, so I'm gonna report this thread for closing as the big problem has been resolved and my Throw script is now merely a couple hours away from completion!

Onwards!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/doing-things-to-an-unknown-completed-damage-formula-vx-ace-solved.124919/