How to break a battle formula into stages?

 I've been trying some stuff to get a skill to situationally cost 1 TP whenever used through a common event but that's not working but I haven't had any luck... so I thought about doing it within the battle script itself.


 something along the lines of:


 x = Math.floor(Math.random()*100)+1


if x > a.lv


a.tp = a.tp-1


 and then the formula.


 however, I'm not 100% sure how to break up the battle script into 2 parts where it uses the TP then deals damage based on the formula.


 I was planning on having attacks that enemies do use a similar script, only with the level check against b.lv and b.tp = b.tp-1 (so that enemy attacks can potentially deal TP damage.
x = Math.floor(Math.random()*100) + 1; if x > a.lv {a.tp = a.tp - 1}; x
 Well, I tried it but the attacks do 0 damage (and not subtracting tp).


x = Math.floor(Math.random()*100) + 1; if x > a.lv {a.tp = a.tp - 1}; (((a.atk + a.luk) * 2) * ((b.atk + b.luk)/(a.def + a.luk))) * (a.tp/100)


for the player attack and


x = Math.floor(Math.random()*100) + 1; if x > b.lv {b.tp = b.tp - 1}; ((a.atk + a.luk) * 2) * ((b.atk + b.luk)/(a.def + a.luk))


for monster attacks


not sure what's causing the 0 damage.
Well, work through it.  What is a.atk, al.uk, b.atk, b.luk, a.luk and a.tp (which will be reduced by this stage if the random number was greater than the level).


0 could mean it's resulting in 0. Or it could mean an error in the formula, but it doesn't tell you it's an error in the formula.  Something you could try is debugging and setting a breakpoint somewhere around the eval (or the rescue) to see if it's something wrong with the formula.


Why do you change the formula for the player and for monsters?  a does not equal your ally and b does not equal the monster.  a is the attacker (which could be an ally or a monster) and b is the target (which could be an ally or a monster).  If you want to say "my.atk + my.luk ... * your.atk + your.luk ..." just leave it as the first one.  
 well, without the first 2 stages, the attack deals damage as normal (though a little higher than I intended it to be, but I can work on that later)... so that means that the problem is somewhere in here:


x = Math.floor(Math.random()*100) + 1; if x > a.lv {a.tp = a.tp - 1};


 What I can't figure out is why...


Edit:


x = Math.floor(Math.random()*100) + 1; if (x > a.lv) {a.tp = a.tp - 1};


that's why. With "X > a.lv" in parentheses, the skill deals damage..... but it still doesn't deplete TP.


 as for why I have separate attacks for players and monsters: monster attacks are supposed to cause tp loss in the player and player attacks are also supposed to have a conditional tp cost. Also, If I were to keep the a.lv as part of the attack then I'm pretty sure it would throw something off because monsters don't have levels by default.


I've got the system set up so that TP is preserved and remains at 100 unless something decreases it (walking, attacking, and getting hit). This reduces the damage dealt as the characters get more tired and only resting/eating will restore TP. The higher your level, the longer you can go without resting.


------------


 I've debugged the first part of the formula as well. By changing "x" to v[1] and then setting a text window to display the variable, I've confirmed that this part is working correctly...


 if (v[1] > a.lv) {a.tp = a.tp - 1};


 so I've narrowed it down to this.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-break-a-battle-formula-into-stages.65809/