Help with simple damage formula.

Hey, the damage formula I want to use is:

Char's attack multiplied by 4, then added to the char's level to give the total. Then, take the defending char's defence multiplied by 2 away from the total to give the amount of damage dealt. 

So that's:

((a.atk * 4) + a.lvl) - (b.def * 2)

I think.

I mean, imagine my character has an attack of 11 and a level of 1. I am attacking an enemy with a defence of 20. 

So that should be 11 x 4... 44. Add 1, 45. 20x2 is 40.

45-40 = 5.

Yet when I hit the enemy using that formula, I hit 0. So obviously I've written it out wrongly or I'm overlooking something.
probably because its a.level and not a.lvl 😛

There is no short version of level in code...
Oh.

...

Thanks. That fixed it.
Ok, I have a follow-up question. I'm using a different formula for enemies attacking the party. I have their only available skill set to a different 'Attack' skill.

This is the formula I want to use:

The enemy's attack, minus the party member's defence multipled by two. Then take away the party member's level.

(a.atk - (b.def * 2)) - b.level.

So, my enemy has 22 attack. My party member has 10 defence, and is level 1.

So, the party member's defence multiplied by 2 is 20. 22-20 is 2. Then take away the party member's level, which is 1, and it should give 1.

Yet they're hitting him for 13...
What is your variance percentage?

There is, by the way, a whole thread devoted to questions on the damage formula.  In future, please use that one rather than start extra threads.  You would also have found the answer to your first query there.
Noted, sorry about that. The variance is 40. I thought if the damage is 1, 40 percent of 1 would be... well, yeah. Is that the issue? 

Edit: Evidently not, as changing it down to 20 did nothing.
Ok, I have a follow-up question. I'm using a different formula for enemies attacking the party. I have their only available skill set to a different 'Attack' skill.

This is the formula I want to use:

The enemy's attack, minus the party member's defence multipled by two. Then take away the party member's level.

(a.atk - (b.def * 2)) - b.level.

So, my enemy has 22 attack. My party member has 10 defence, and is level 1.

So, the party member's defence multiplied by 2 is 20. 22-20 is 2. Then take away the party member's level, which is 1, and it should give 1.

Yet they're hitting him for 13...
First of all, make absolutely sure that they're using the new skill (not the regular Attack) - I recommend changing the "X attacks!" text on it temporarily to make sure - and then add a troop event that runs to confirm what the characters' and monsters' stats are (you can do so by having an "each turn" page that sets variables to the values of the characters'/monsters' stats (it's under Game Data in the Control Variables event command), then prints them to a Show Message).

I'm pretty confident this will show you where the problem is.  If not - the only other reasonable culprit would be the use of outside scripts - for example, I believe Yanfly's core battle system changes certain calculations, so if you're using outside scripts, disable them (visit each script, hit Ctrl + A then Ctrl + Q) before trying again.
First of all, make absolutely sure that they're using the new skill (not the regular Attack) - I recommend changing the "X attacks!" text on it temporarily to make sure - and then add a troop event that runs to confirm what the characters' and monsters' stats are (you can do so by having an "each turn" page that sets variables to the values of the characters'/monsters' stats (it's under Game Data in the Control Variables event command), then prints them to a Show Message).

I'm pretty confident this will show you where the problem is.  If not - the only other reasonable culprit would be the use of outside scripts - for example, I believe Yanfly's core battle system changes certain calculations, so if you're using outside scripts, disable them (visit each script, hit Ctrl + A then Ctrl + Q) before trying again.
Well, I'm definitely going to get roasted for not mentioning that I am using Victor's animated battlers. I had no idea it affected damage calculations, I'm sorry. 

Alright, so, I changed the X attacks, and they are indeed using the new attack, not the original.

I added the show variable and their attack is indeed 22. 

So I'm guessing the culprit is the scripts. Oddly enough, I tried doing what you suggested - I went to animated battlers, and also ATB (his two attack scripts I'm using, though I thought both were just visual) - and tried what you said. A hashtag appeared to the left of every line, but then when I went to the practice battle, the visual effect was still in place. So I guess it didn't disable.

Thanks for your continued help with this. Sorry for not mentioning the scripts, I use a lot and I guess I should make a list so I can copy and paste it into these threads. :/ I'll do that from now on. 
You need to Save before entering the practice battle for the changes to take effect.

Also were you able to confirm (via variable) that the character's defense is 10?

The last thing I could think of would be elemental weaknesses or physical/elemental damage rates on your character.  This seems like an unlikely reason for such a big swing, but check in the database just to be sure.

If none of these help, and the monsters are still hitting for way more than expected, I'm afraid I'm out of ideas.
You need to Save before entering the practice battle for the changes to take effect.

Also were you able to confirm (via variable) that the character's defense is 10?

The last thing I could think of would be elemental weaknesses or physical/elemental damage rates on your character.  This seems like an unlikely reason for such a big swing, but check in the database just to be sure.

If none of these help, and the monsters are still hitting for way more than expected, I'm afraid I'm out of ideas.
Alright, I disabled every script I have, saved and went into battle. They were disabled, and the enemies STILL hit me for 10 to 13. My defence is 10, it shows up on the troop screen when you enter mock battle. There's no elemental weakness on my character, and its a normal attack anyway. The enemy has no element either. :/

Thanks for trying.
Please provide screenshots of enemy, actor, class and skill for us to see.


Most probably it's something you don't tell us because you don't know that it affects the damage - and with the screenshots, we can see everything.


Happened before in the past, usually when someone had a wrong idea what a feature does or miscalculated somewhere.
This is actually apparently an issue caused by Hime's Core - Equip Slots script:

http://himeworks.com/2013/07/core-equip-slots/

As of yet I am unsure if it's caused by compatibility with another script, or just that script in isolation.
I created a new project with the script exactly as is in the link, and the setup you mentioned: the enemies are dealing 1 damage every time.  I also tried reducing the character's DEF to 6, and, like expected, the enemies will do around 9 damage with each hit.  My instinct is that this script is not what is causing your issue.

Could it be an incompatibility with another script?  It's possible, but if that's the case, you should only see the bug happening when the character has equipment.  If they have no equipment, there's almost no way this script would cause weird results, since none of the script's methods affect skill behavior or damage calculation.

I know this is really frustrating for you.
The character has equipment, yes. I started a script from scratch and added all the scripts I use in, checking the issue after each. It began after that script. Compatibility issue is possible. I'll send you the file.
So, after testing with the file you sent, here's what I found:

  • Using the setup you provided, I do see the bug happening; enemies are hitting for ~10-13 damage.
  • Interestingly, raising the character's DEF to 10 manually in the database, then removing all armor, "fixed" the issue: enemies only hit for 1 damage.
  • Deleting Hime's Core Equip script did seem to fix the problem.
  • However, copying the default Configuration from Hime's linked script and using it to replace your own configuration also fixed the issue.
This means one of two things: either there is a bug in the script, or there is a problem with your setup.  The way I understand the script, your setup looks okay (but I'm not completely sure).  Here's what I'd recommend doing: first, test this in a battle in Playtest mode rather than Battle Test mode.  As I looked through the script, there is a method to handle Battle Test, but my instinct is that it could be incomplete, and that when you play through the actual game, the damage will actually be calculated properly.  Whether this works or not, report the problem you are having to Hime on his site - he is very good about supporting people who have configuration problems and even better about fixing legitimate bugs that are found.  Make sure to include the configuration that you were using that caused the problem to happen when you report the "bug".
Thank you so much. It still happens in Playtest, FYI. I will report it to Hime, but in the mean time the script is not that important for my project relatively speaking, so I would consider this closed.
No problem.  It does sound like a legitimate bug (and probably a pretty serious one if it's also happening in Playtest), so I'm glad you're reporting it.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-simple-damage-formula.45646/