@Berylstone
Unfortunately, the method that I originally recommended will not account for resistances and variance and such. But to answer your question anyway, for academic purposes, here is how you could combine my original formula with your formula:
JavaScript:
let damage = a.atk >= v[17]*5 ? v[17]*5*2 - b.def*1 : a.atk*2 - b.def*1; $gameVariables.setValue(1206, a); $gameVariables.setValue(1207, damage / 2); damage;
If you're confused about the ? and : business, that's called a
ternary operator. It is similar to if + else, except it's more suitable for single-line usage, and you're allowed to use it within an expression. So you can use it as the argument in a function, or you can concisely set a variable equal to the result. It's structure is like this:
Code:
(condition) ? (when true) : (when false)
----------------------------------
But anyway, there actually *is* a way to account for resistances and such, without having to use a plugin. What you would do is save the user to a variable, save the target's current hp to a variable, and also save the target to a variable. Then in your common event, you would use that information to subtract the target's new hp from the previously recorded hp. That would give you the full damage amount, while taking resistances and such into account.
However, there is one important caveat to this method. If the attack kills the enemy, it won't count any of the over-kill damage. So for example, if the enemy has 50 hp, and your attack does 100 damage to that enemy, it will only drain 25 hp (half of the 50 hp that the enemy had). Depending on exactly what you're trying to do, this could be a deal breaker, or it might actually be a good thing.
For example, if it's a life drain skill, then I think it actually might make more sense this way. Because how can you drain more life force than the enemy actually has? The method to do this is to put this in your damage formula:
JavaScript:
$gameVariables.setValue(1206, a); $gameVariables.setValue(1207, b.hp); $gameVariables.setValue(1208, b); a.atk >= v[17]*5 ? v[17]*5*2 - b.def*1 : a.atk*2 - b.def*1
Note that a third variable is now necessary. I used ID 1208, but you'd obviously want to change it if necessary.
And this would be the script call in your common event:
JavaScript:
$gameVariables.value(1206).gainHp(($gameVariables.value(1207) - $gameVariables.value(1208).hp) / 2);
But all that being said, if it were me personally... I would just use a plugin, like Anastasius and ATT_Turan recommended. Being able to put JavaScript in the note tags opens up so many more possibilities for your skills, and it also allows you to keep your damage formulas a lot cleaner looking.