Huh? It's ridiculously easy... if you don't mind installing plugins.
Yanfly's Skill Core is free and is one of the most commonly used plugins. Lots of people here can help you with that if you have questions.
Just put this inside the note box of your skill.
JavaScript:
<Post-Damage Eval>
user.gainHp(Math.floor(value * 0.5));
</Post-Damage Eval>
That's it.
The
value variable used by the
<Pre-Damage Eval> and
<Post-Damage Eval> notetags of YEP Skill Core accounts for elemental resistances (as well as all the other things previously mentioned). This variable is the ACTUAL final value you do to your target.
If you're going to use Yanfly's
Auto Passive States you might as well use his
Skill Core.
Edit: Changed notetag to note box.
Thank you for this. If I decide to use the addon this will definitely come in handy.
When I was talking about how difficult it would be to do in my earlier post, I was meaning without the plugin, since I would have to factor in all the damage indicators myself, which would be daunting and way out of my league. So I'm not even going to attempt that. I'll either be doing this with the plugin, or not at all, unless there is an easier way using a common event. I'm currently confused about whether or not the common event method can work without the plugin. Because when I tried it, it didn't appear to be taking resistances into account. But I could have easily did something wrong.
I'm not sure what Yanfly's Auto Passive States is, so if I use that addon I'm not aware of it. Right now I use Shaz's escape codes, Modern Algebra's global text codes, a Save Fix addon, a Change Enemy Parameter addon, and Hime's Battle Weather addon.
Sorry it took me a couple of days to respond. I've been out of town.
Sure, I'll walk you through it.
Why do this? You don't want to store half of your damage formula - that's pointless, as the entire reason for this approach is to use the damage done
after resistances apply.
In what way didn't it work? When you're asking for help from people who aren't either seeing your game or in your brain, you need to give details. Now,
I know why it didn't do
what you want, but if I hadn't noticed that, you just saying "it didn't work" wouldn't give us anything to go on in terms of fixing it.
😉
To do this, you need Yanfly's Skill Core, which is a free plugin. You'll put this code in the notes box of your skill.
Code:
<Post-Damage Eval>
if (value>0)
user.gainHp(Math.floor(value/2));
</Post-Damage Eval>
There were a lot of different things going wrong with it. lol
So I was going to wait and see if you needed me to expound before I tried to go into details about why it wasn't working. If it was just some coding error I was expecting that would likely be obvious to you.
In any case: it seems the basis of my last post to you was based on a misunderstanding. Because I thought you said the common event method could work without the plugin. So that was my mistake. But thanks for showing me how to write the common event all. That will definitely be nice to have if I decide to pursue this plugin.
@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.
Thanks for clearing that up for me, because I was confused about whether or not that method could work while still factoring in resistances.
I also appreciate you taking the time to show me how to write this new damage formula using a common event. I've been testing it out last half hour or so, and it seems to be working perfectly. And I can easily live with the fact it won't restore HP if the enemy dies.
One curious thing I've noticed is it seems to factor in decimals as well, which is something I haven't seen before in any of my previous formulas. For example: one time my Actor was hanging on by .5 life. So it even makes my game more exciting.
🙂
Don't worry. Your code is just missing a semi-colon.
When you're writing complicated code inside the damage formula, it's best to write them first normally inside a text editor such as Notepad++:
Spoiler: Damage Formula
You original damage formula.
JavaScript:
if (a.atk >= v[17]*5) {
$gameVariables.setValue(1207, (v[17]*5*2 - 1 * b.def) / 2);
$gameVariables.setValue(1206, a);
v[17]*5*2 - b.def*1
} else {
$gameVariables.setValue(1207, (2 * a.atk - 1 * b.def) / 2);
$gameVariables.setValue(1206, a)a.atk*2 - b.def*1 // cause of error
}
Same as above but added semi-colon:
JavaScript:
if (a.atk >= v[17]*5) {
$gameVariables.setValue(1207, (v[17]*5*2 - 1 * b.def) / 2);
$gameVariables.setValue(1206, a);
v[17]*5*2 - b.def*1
} else {
$gameVariables.setValue(1207, (2 * a.atk - 1 * b.def) / 2);
$gameVariables.setValue(1206, a);
a.atk*2 - b.def*1
}
It's much easier to detect errors if you do it this way.
Then you just remove the spaces so you can use it inside your damage formula.
Don't put yourself down
@Berylstone, you're much more competent than you think. You're just inexperienced.
There are plenty of people here who would be more than happy to help you.
😮💨
Edit:
I can't believe you can solve like at least 75% of the support threads in this entire forum each day while doing something else besides.
👋
Thanks for the advice on how I can make it easier to write code, because I was having a hard time following it all on that formula bar. And also for taking the time to show me where I erred in that monstrosity of a damage formula I came up with.
I also appreciate the kind words. Not sure how competent I am, but I try. lol
It's now a life mission of mine to finish this game, so I am determined if nothing else.