Help with Custom Formula Script

Hi,

I'm trying to make a skill script where the result changes depending on 2 possible conditions that can be met (I used variables c and d).

I want it so that:

if both conditions are met, it inflicts states c and d, and does damage according to the formula.

if only condition c is met, it inflicts state c, and does damage according to the formula.

if only condition d is met, it inflicts state d, and does damage according to the formula.

if neither condition is met, it only does damage according to the formula.

Attached is the code I'm using.  Note that I've also included some tp adjustment formulas, as I want every attack/skill in my game to take away 10 tp from the attacker, and add 10 tp to the defender.

Unfortunately when I test it in my game, the skill yields 0 damage.  Any help would be greatly appreciated!

EDIT - I think I figured out my problem - my "c" condition was not a valid expression for the way I called the variable in the rest of the script.

Need to test a bit, but damage is returning now.  

However, I have a hunch that because of my newbishness, this script is very awkwardly put together...if someone knows a much simpler way of doing this kind of thing, I'd love to learn!

customformulascript.txt
May I ask what you're actually trying to set c to? What you have at the moment makes no sense to me, and that's more than likely where your problem lies.

Edit: Ah, I just saw your edit, but my question still stands.
yeah...I want(ed) two different formulas to be satisfied in order for "c" to be true.  I just took out the first part of that expression and just added another couple of if blocks within the cases where c is true, and so far, so good.

Thank you for the help...if you or anyone has feedback on if there's a simpler / more efficient way to code this kind of thing though, I'd love to know.
This might be a cleaner way of doing it:

def custom_formula_normalatk(a,   value = (a.atk - b.def) + rand(5)  c = false  d = ((a.mdf - b.mdf) + (a.agi - b.agi) + (a.luk - b.luk)) - b.mhp / 10  #------  if a.mat + 5 >= b.mat && a.mat + 5 >= (a.mat -b.mat) + (a.agi - b.agi) + (a.luk - b.luk)    c = true  end  #------  if c && d > 0    a.tp -= 10    b.tp += 10    b.add_state (65)    b.add_state (68)  elsif c && d <= 0    a.tp -= 10    b.tp += 10    b.add_state(68)  elsif !c && d > 0    a.tp -= 10    b.tp += 10    b.add_state (65)  elsif !c && d <= 0    a.tp -= 10    b.tp += 10  end  #------  return valueendFeel free to reverse the c values if you need to.
thank you!
You could shorten it further into this, too:

Code:
def custom_formula_normalatk(a,   value = (a.atk - b.def) + rand(5)  c = false  d = ((a.mdf - b.mdf) + (a.agi - b.agi) + (a.luk - b.luk)) - b.mhp / 10  #------  if a.mat + 5 >= b.mat && a.mat + 5 >= (a.mat -b.mat) + (a.agi - b.agi) + (a.luk - b.luk)    c = true  end  #------  a.tp -= 10  b.tp += 10  #------  if c && d > 0    b.add_state (65)    b.add_state (68)  elsif c && d <= 0    b.add_state(68)  elsif !c && d > 0    b.add_state (65)  end  #------  return valueend
Thanks, but I've run into another problem.  For some reason, I've tried the formula all different ways, but it seems like whenever d is true, my attacks are returning null damage.

Any ideas?
Maybe you could try taking the damage calculation out of the method? So have the method be like this:

def custom_formula_normalatk(a, c = false d = ((a.mdf - b.mdf) + (a.agi - b.agi) + (a.luk - b.luk)) - b.mhp / 10 #------ if a.mat + 5 >= b.mat && a.mat + 5 >= (a.mat -b.mat) + (a.agi - b.agi) + (a.luk - b.luk) c = true end #------ a.tp -= 10 b.tp += 10 #------ if c && d > 0 b.add_state (65) b.add_state (68) elsif c && d <= 0 b.add_state(68) elsif !c && d > 0 b.add_state (65) endendThen have your formula like this:

Code:
(a.atk - b.def) + rand(5); b.custom_formula_normalatk(a,
def custom_formula_normalatk(a, value = a.atk - b.def c = (a.mat + a.agi + 20) - (b.mat + b.agi + b.luk) d = (a.mdf + a.agi + 15) - (b.mdf + b.agi + b.luk + b.mhp/4) e = a.mat - (b.mat + 9) if c > 0 and d > 0 and e > 0 b.add_state (65) b.add_state (68) a.tp -= 10 b.tp += 10 return value else if c > 0 and d <= 0 and e > 0 b.add_state (68) a.tp -= 10 b.tp += 10 return value else if c <= 0 or e <= 0 and d > 0 b.add_state(65) a.tp -= 10 b.tp += 10 return value else if c <= 0 or e <= 0 and d <= 0 a.tp -= 10 b.tp += 10 return value end end end end endIt didn't work, but after much torment, I was able to figure out a way to get this to work...in case anyone is curious:
def custom_formula_normalatk(a, value = a.atk - b.def c = (a.mat + a.agi + 20) - (b.mat + b.agi + b.luk) d = (a.mdf + a.agi + 15) - (b.mdf + b.agi + b.luk + b.mhp/4) e = a.mat - (b.mat + 9) if c > 0 and d > 0 and e > 0 if b.state?(68) b.add_state (65) a.tp -= 10 b.tp += 10 return value else b.add_state (65) b.add_state (68) a.tp -= 10 b.tp += 10 return value end else if c > 0 and d <= 0 and e > 0 if b.state? (68) a.tp -= 10 b.tp += 10 return value else b.add_state (68) a.tp -= 10 b.tp += 10 return value end else if c <= 0 or e <= 0 and d > 0 b.add_state(65) a.tp -= 10 b.tp += 10 return value else if c <= 0 or e <= 0 and d <= 0 a.tp -= 10 b.tp += 10 return value end end end end endWell, I've run into a new problem - not sure if I should make a new topic though.   What's happening now is, my character is getting stun-locked.  I have tweaked the code to make it so that if the target has state 68 (Stun), then to not add it.   Stun lasts for 2 turns.   This is how the battle plays out: 

Turn 1:

Actor attacks Troll.  Troll attacks and stuns Actor.

Turn 2:

Actor is stunned. Troll attacks Actor.

~Stun is removed from Actor.~

Turn 3:

Actor attacks Troll.  Troll attacks and stuns Actor.

Turn 5:

Actor is stunned.   Troll attacks Actor.

~Stun is removed from Actor~

Turn 6:

Troll attacks Actor! (and stuns).  

On Turn 6, after my stun is removed, I am able to select commands but when I choose "attack', the Troll goes before the actor gets a chance to go, which is different from what happens in turn 3.  This cycle continues and my actor is effectively unable to attack after this point.

And yes - I have given my actor a considerable agility advantage and tested it many times; it's not just speed variance.

I also have made sure there are no agility debuffs to the actor.

Any ideas?
Since this is a different problem, I'm going to make a new topic...Thank you for the help with the formula/conditionals. 

Original thread: https://forums.rpgmakerweb.com/threads/help-with-custom-formula-script.36992/