Problem with damage formula

Hi,


I've been trying to make some custom damage formula's, not so far I'm out of luck.


This is the script I've been using:


class Game_Battler < Game_BattlerBase


def custom_formula_pyro(a, 😎


if b.state?(30);b.add_state(26);b.remove_state(30);end;(15 + a.mat * 2 - b.mdf).to_i


end


end


I've added it to my pyro skill. Now basically, when my mage casts Mark of the Mage, the enemy should get a state (marked) which will allow my battlemage's spells to have additional effects. In this case 30 = marked, and 26 = burn. But when I try to test it, the skill (Pyro) doesn't do any damage at all. What am I doing wrong?


Also, I'd like a skill to drain mp and deal hp damage based on MP drained, but I can't quite get that one to work either..
If I understood correctly, you want a skill that applies state 30 *derp*  26 and removes state 30, when enemy has state 30 and does damage independently of enemy state?

Then you could simply write that in damage formula without using script.

if b.state?(30); b.add_state(26); b.remove_state(30); end || (15 + a.mat * 2 - b.mdf).to_i

(Correct me if I'm mistaking)

For the second one, I'm not sure how to do that. =P
@BCj

In your scripplet, you have .to_i

I think you'll find that you don't need it, because the engine never does decimal points of damage.  You therefore don't need it in the damage formula.

Those extra spaces that Rikifive has put in make all the difference.

@Rikifive

for my own information (not saying it's wrong) I'm curious about why you have put end || instead of end;

Is there a functional difference here, or just personal preference?
@ksjp17

More like personal preference. AFAIK "||" just separates formulas and I don't think there are any differences between them. It's easier for me to find the separated part, because "||" is visible, especially if there are many ';' in that formula.
@Rikifive

Yes, I can see that it would be easier to spot.  When I saw your version I started wondering if there was something fundamental that I had overlooked.  Thanks for the clarification.
|| is used as a logical "or" - operator in Ruby.
When you connect two statements with this operator the second statement will be ignored unless the first statement returns <false> or <nil>
 
In this particular case, this should probably work since b.remove_state(30) usually returns <nil> when using the default scripts only, I would still not recommend to use it as a substitute for ';'. You can still use multiple semicolons to separate your commands if necessary.
 
As an alternative you can also use this pattern to separate damage formula from additional effects:
( actual damage formula ).tap { other commands }
 
 
@BCj:
 
I can't test it at the moment, but the formula should work if you call it like this:

a.custom_formula_pyro(a,  
By default, errors occurring during the damage calculation are hidden and cause the item to deal 0 damage instead.
 
When using the damage formula to apply random effects, you should not teach this skill to an actor with "Auto Battle".
I tried calling it with


a.custom_formula_pyro(a, 😎 in the damage formula box,


But that doesn't work for some reason.
|| is used as a logical "or" - operator in Ruby.

When you connect two statements with this operator the second statement will be ignored unless the first statement returns <false> or <nil>

In this particular case, this should probably work since b.remove_state(30) usually returns <nil> when using the default scripts only, I would still not recommend to use it as a substitute for ';'. You can still use multiple semicolons to separate your commands if necessary.

As an alternative you can also use this pattern to separate damage formula from additional effects:

( actual damage formula ).tap { other commands }

@BCj:

I can't test it at the moment, but the formula should work if you call it like this:

a.custom_formula_pyro(a,
By default, errors occurring during the damage calculation are hidden and cause the item to deal 0 damage instead.

When using the damage formula to apply random effects, you should not teach this skill to an actor with "Auto Battle".
I never got any problems with that, but I'll note that down, thanks.
@BCj:

Try to add this scripts, save your project and use the skill again. If the result was caused by an error during the damage calculation process, you should receive an error message then.

class RPG::UsableItem:😀amage   def eval(a, b, v)    [Kernel.eval(@formula), 0].max * sign #rescue 0  endendYour formula works fine for me though.

@Rikifive:

You can see differences when using these formulas for example:

a.mp += 30 || 99999

a.erase_state(2) || 99999  (if state 2 was successfully removed)

$game_switches[15] = true || 99999
@Another Fen

Now I see the difference...

Sorry ksjp17 for misleading.
I have another question. How can I make something autocrit if a certain condition is met? Like say, state 30 is active, set crit ON then state 30 is consumed.
Code:
if a.state?(30);b.result.critical = true;a.remove_state(30);end;a.atk * 4 - b.def * 2
Awesome 😀
Hmm sadly the crit isn't proccing..
 

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-damage-formula.42900/