# Is there a way to make a skill heal for half the damage caused?

#### Berylstone

##### Veteran
This is likely something simple I'm missing and I'm about to feel stupid, but I can't figure out how to make a skill heal the user for half the damage it causes to the enemy.

Does anyone know how to do this?

#### oooNUKEooo

##### Veteran
if youre not using plugins, you can try the damage formula:

Code:
``4 * a.atk - 2 * b.def; a.gainHp((4 * a.atk - 2 * b.def) / 2)``

i used the default attack skill formula as an example. change it to meet your needs.

its: [damage formula]; a.gainHp([damage formula / 2]).

#### Arthran

##### Veteran
if youre not using plugins, you can try the damage formula:

Code:
``4 * a.atk - 2 * b.def; a.gainHp((4 * a.atk - 2 * b.def) / 2)``

i used the default attack skill formula as an example. change it to meet your needs.

its: [damage formula]; a.gainHp([damage formula / 2]).
I'm pretty sure that a skill with that damage formula would do 0 damage every time. When you're using semicolons in a damage formula, it's important to put the actual damage formula portion at the very end--not at the beginning. The engine will assume that the code that comes after the last semicolon is your actual damage formula. In this case, it would try to use the return value of the `a.gainHp` call, and `gainHp` doesn't return a value, so it'd wind up as 0 damage. But more importantly...

Generally speaking, you shouldn't put something like `a.gainHp` in a damage formula. The reason is because when the game does autobattle, at the start of a unit's turn, it evaluates the damage formula for each of that unit's skills, in order to determine which one to use. When that happens, it will actually execute that `a.gainHp` call and heal the person. That's why you should only calculate numbers in the damage formula--never put in functions that actually cause something to happen.

The safer way to do it (without plugins) would be to have the damage formula save that value into a variable, and also save the user into a variable, and then have the skill call a common event (which will then use those variables to make the HP gain happen). So the damage formula would look something like this:
JavaScript:
``\$gameVariables.setValue(4, (4 * a.atk - 2 * b.def) / 2); \$gameVariables.setValue(3, a); 4 * a.atk - 2 * b.def``

And then the common event would use this script call:
JavaScript:
``\$gameVariables.value(3).gainHp(\$gameVariables.value(4));``

Those code snippets are assuming that you want to use variable #3 to store the skill user, and variable #4 to store the hp gain amount. You'd obviously want to change them to represent the IDs of the variables that you would actually be using.

Last edited:

#### ATT_Turan

##### Forewarner of the Black Wind
Just leaving this here for the OP's reference:

#### Berylstone

##### Veteran

Don't feel bad, because the way you suggested was exactly the same way I was trying to get it to work too.

I tried putting the gain hp at the beginning, at the end, in the middle... all with varying and incorrect results. lol

#### Anastasius

##### Veteran
...make a skill heal the user for half the damage it causes to the enemy.
Hello.
To add to what others had said, the actual damage done to a target is affected by a lot of factors ON TOP of the ones you've defined in the damage formula:
• base damage from damage formula
• elemental rates
• damage reduction from physical / magical damage rates i.e. pdr / mdr
• damage increase from critical hits
• damage variance
• damage reduction from guarding
• rounding to nearest integer after accounting for all of the above
You can find the above from `Game_Action.prototype.makeDamageValue`:
JavaScript:
``````Game_Action.prototype.makeDamageValue = function(target, critical) {
var item = this.item();
var baseValue = this.evalDamageFormula(target);
var value = baseValue * this.calcElementRate(target);
if (this.isPhysical()) {
value *= target.pdr;
}
if (this.isMagical()) {
value *= target.mdr;
}
if (baseValue < 0) {
value *= target.rec;
}
if (critical) {
value = this.applyCritical(value);
}
value = this.applyVariance(value, item.damage.variance);
value = this.applyGuard(value, target);
value = Math.round(value);
return value;
};``````
May I suggest you use a free plugin instead such as Yanfly's Skill Core? Then you can use a single variable that takes into account all of the above factors:
Copy and paste the following within the skill's notetag.
JavaScript:
``````<Post-Damage Eval>
user.gainHp(value);
</Post-Damage Eval>``````
Note that everything mentioned so far applies to DIRECT damage from skills or items. This will NOT apply to INDIRECT damage such as negative hp regeneration (e.g. poison).
To do that you will need to alias either `gainHp` or `setHp` and then add your code there.
If you're not familiar with aliasing you can use @ct_bolt's Custom Script Anywhere.

#### Berylstone

##### Veteran
I'm pretty sure that a skill with that damage formula would do 0 damage every time. When you're using semicolons in a damage formula, it's important to put the actual damage formula portion at the very end--not at the beginning. The engine will assume that the code that comes after the last semicolon is your actual damage formula. In this case, it would try to use the return value of the `a.gainHp` call, and `gainHp` doesn't return a value, so it'd wind up as 0 damage. But more importantly...

Generally speaking, you shouldn't put something like `a.gainHp` in a damage formula. The reason is because when the game does autobattle, at the start of a unit's turn, it evaluates the damage formula for each of that unit's skills, in order to determine which one to use. When that happens, it will actually execute that `a.gainHp` call and heal the person. That's why you should only calculate numbers in the damage formula--never put in functions that actually cause something to happen.

The safer way to do it (without plugins) would be to have the damage formula save that value into a variable, and also save the user into a variable, and then have the skill call a common event (which will then use those variables to make the HP gain happen). So the damage formula would look something like this:
JavaScript:
``\$gameVariables.setValue(4, (4 * a.atk - 2 * b.def) / 2); \$gameVariables.setValue(3, a); 4 * a.atk - 2 * b.def``

And then the common event would use this script call:
JavaScript:
``\$gameVariables.value(3).gainHp(\$gameVariables.value(4));``

Those code snippets are assuming that you want to use variable #3 to store the skill user, and variable #4 to store the hp gain amount. You'd obviously want to change them to represent the IDs of the variables that you would actually be using.

Using your formula and script call I was able to restore HP, but it wasn't giving me the desired amount. I'm guessing I would probably have to go through and change the value based on the elemental resists of the target to get it to work like I want. But my more immediate problem is I can't figure out how to integrate your information into my original damage formula:

`if (a.atk >= v[17]*5) { v[17]*5*2 - b.def*1 } else { a.atk*2 - b.def*1 }`

v[17] is just a variable for player's level. I use it to put a cap on damage.

I tried changing it to this based on your information:

``` if (a.atk >= v[17]*5) { \$gameVariables.setValue(1207, ([v17]*5*2 - b.def*1) / 2); \$gameVariables.setValue(1206, a); v[17]*5*2 - b.def*1 } else { \$gameVariables.setValue(1207, (a.atk*2 - b.def*1) / 2); \$gameVariables.setValue(1206, a); a.atk*2 - b.def*1 } ```

But I was getting all kinds of errors and weird results. I obviously did something badly wrong, and the first formula may not be compatible since I use v17 instead of a.atk. So if you have any ideas on how to translate your formula into mine I would like to try them.

Just leaving this here for the OP's reference:

Thanks for the reference. That is indeed a great read and has helped me do a lot of things with my formulas. Sadly, I was not smart enough to figure out how to use that information to write this one particular formula. This one has really stumped me for some reason.

Hello.
To add to what others had said, the actual damage done to a target is affected by a lot of factors ON TOP of the ones you've defined in the damage formula:
• base damage from damage formula
• elemental rates
• damage reduction from physical / magical damage rates i.e. pdr / mdr
• damage increase from critical hits
• damage variance
• damage reduction from guarding
• rounding to nearest integer after accounting for all of the above
You can find the above from `Game_Action.prototype.makeDamageValue`:
JavaScript:
``````Game_Action.prototype.makeDamageValue = function(target, critical) {
var item = this.item();
var baseValue = this.evalDamageFormula(target);
var value = baseValue * this.calcElementRate(target);
if (this.isPhysical()) {
value *= target.pdr;
}
if (this.isMagical()) {
value *= target.mdr;
}
if (baseValue < 0) {
value *= target.rec;
}
if (critical) {
value = this.applyCritical(value);
}
value = this.applyVariance(value, item.damage.variance);
value = this.applyGuard(value, target);
value = Math.round(value);
return value;
};``````
May I suggest you use a free plugin instead such as Yanfly's Skill Core? Then you can use a single variable that takes into account all of the above factors:
Copy and paste the following within the skill's notetag.
JavaScript:
``````<Post-Damage Eval>
user.gainHp(value);
</Post-Damage Eval>``````
Note that everything mentioned so far applies to DIRECT damage from skills or items. This will NOT apply to INDIRECT damage such as negative hp regeneration (e.g. poison).
To do that you will need to alias either `gainHp` or `setHp` and then add your code there.
If you're not familiar with aliasing you can use @ct_bolt's Custom Script Anywhere.

Hi ^^

Yeah, it seems you're right and I would have to go through and factor in all of my resistances (and from the looks of it a whole lot more) to get the result I'm looking for. So this is probably out of my league.

I was thinking this would be relatively easy to do, but apparently I was very wrong about that. I may just abandon this particular skill since it's starting to look like more trouble than its worth. But if I decide to stick with it I'll definitely try out your suggested addon, because being able to work with a variable that gives me access to the final damage numbers is probably the only realistic way I'm going to be able to do something like this.

I

#### ATT_Turan

##### Forewarner of the Black Wind
I tried changing it to this based on your information:

``` if (a.atk >= v[17]*5) { \$gameVariables.setValue(1207, ([v17]*5*2 - b.def*1) / 2); \$gameVariables.setValue(1206, a); v[17]*5*2 - b.def*1 } else { \$gameVariables.setValue(1207, (a.atk*2 - b.def*1) / 2); \$gameVariables.setValue(1206, a); a.atk*2 - b.def*1 } ```

But I was getting all kinds of errors and weird results. I obviously did something badly wrong
You need to read Arthran's suggestion a bit more carefully - there's a difference between the setValue function, which is setting the value of the variable, and the value function, which is retrieving that value to be used. (you also have a typo with `[v17]`)

setValue() does not provide any value, so you can't use it in your damage formulae in place of a number.

Also, your math is kinda screwy - what's the point of saying `v[17]*5*2` instead of just `v[17]*10`? And why do you have `*1` at the end? That doesn't do anything.

Note that Arthran's suggestion is the most universally correct, but it's a bit more complicated. It's only necessary to put the actor in a variable and use a common event if it's possible that your game/players are using autobattle. If you don't have that, then this can be made easier by doing the healing inside of the damage formula, thusly. (Note I'm also using, instead of if/else, the shorter ternary operator described in the thread I linked you to):
Code:
``var damage=a.atk>=v[17]*5 ? v[17]*10-b.def : a.atk*2-b.def; a.gainHp(Math.floor(damage/2)); damage``

#### Berylstone

##### Veteran
You need to read Arthran's suggestion a bit more carefully - there's a difference between the setValue function, which is setting the value of the variable, and the value function, which is retrieving that value to be used. (you also have a typo with `[v17]`)

setValue() does not provide any value, so you can't use it in your damage formulae in place of a number.

Also, your math is kinda screwy - what's the point of saying `v[17]*5*2` instead of just `v[17]*10`? And why do you have `*1` at the end? That doesn't do anything.

Note that Arthran's suggestion is the most universally correct, but it's a bit more complicated. It's only necessary to put the actor in a variable and use a common event if it's possible that your game/players are using autobattle. If you don't have that, then this can be made easier by doing the healing inside of the damage formula, thusly. (Note I'm also using, instead of if/else, the shorter ternary operator described in the thread I linked you to):
Code:
``var damage=a.atk>=v[17]*5 ? v[17]*10-b.def : a.atk*2-b.def; a.gainHp(Math.floor(damage/2)); damage``

I've never used setValue function in a damage formula before, so I am unfamiliar with how it works. Did I write those incorrectly somewhere in the formula or script call?

As to my screwy math, does writing the v[17]*5*2 interfere with the final result? If it does, that might have something to do with the error.

And I have the *1 at the end because I change my formulas around frequently when testing and it's just easier for me that way. Do you think that it's causing a problem?

I tried the formula you presented, but it still seems to be ignoring the elemental resists of the target. For example: i hit the enemy for zero damage due to its resistance but it still healed me for 2. Or at least, I'm assuming that's what is happening.

Thanks for showing me how to integrate Arthran's suggestion into my own formula. I was having some problems with that.

Last edited:

#### ATT_Turan

##### Forewarner of the Black Wind
I've never used setValue function in a damage formula before, so I am unfamiliar with how it works. Did I write those incorrectly somewhere in the formula or script call?
Every time.
As to my screwy math, does writing the v[17]*5*2 interfere with the final result? If it does, that might have something to do with the error.

And I have the *1 at the end because I change my formulas around frequently when testing and it's just easier for me that way. Do you think that it's causing a problem?
No, neither of those cause an error, but it makes anyone else reading unsure as to your intention.

I was asking myself, did you intend for some of those operations to be grouped parenthetically? Did you type the wrong operator for some of them? If it's a part of your process, that's fine, but surely you can see how they'd cause confusion
I tried the formula you presented, but it still seems to be ignoring the elemental resists of the target. For example: i hit the enemy for zero damage due to its resistance but it still healed me for 2. Or at least, I'm assuming that's what is happening.
Correct. Resistances are calculated after the damage formula by other game functions that take many things into account - it would not be simple for you to integrate that into the formula.

If you need that to happen, you will need to use plugins. Yanfly's Skill Core has skill notetags for the various parts of the skill execution process. The value in Post-Damage Eval should be taking into account resistances, I think. If not, it could be surely be done on a passive state.

Or you could go back to Arthran's suggestion of moving it into a common event (this is my least favorite way to do skill effects, because it often looks funky. You do the skill, are finished, then heal).

#### Berylstone

##### Veteran
Every time.

No, neither of those cause an error, but it makes anyone else reading unsure as to your intention.

I was asking myself, did you intend for some of those operations to be grouped parenthetically? Did you type the wrong operator for some of them? If it's a part of your process, that's fine, but surely you can see how they'd cause confusion

Correct. Resistances are calculated after the damage formula by other game functions that take many things into account - it would not be simple for you to integrate that into the formula.

If you need that to happen, you will need to use plugins. Yanfly's Skill Core has skill notetags for the various parts of the skill execution process. The value in Post-Damage Eval should be taking into account resistances, I think. If not, it could be surely be done on a passive state.

Or you could go back to Arthran's suggestion of moving it into a common event (this is my least favorite way to do skill effects, because it often looks funky. You do the skill, are finished, then heal).

Using a common event after the skill goes off to heal for half the damage caused wouldn't be a problem for me. So if that way will work and factor in all of the resistances, I'd like to give it a try. But I can't figure out how to apply their formula to mine.

This is the best I can come up with:

Formula:

`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 }`

Comment Event:

``` \$gameVariables.value(1206).gainHp(\$gameVariables.value(1207)); ```

But that didn't work. I've read Arthran's post many times, but I don't understand the mechanics so paying more attention probably isn't going to help me, since I don't understand the process itself. If you can show me how to properly write it into my formula I'll give it another go and see if I can make it work.

Your truncated code is a lot neater. But I'm not familiar with some of the language you use, so it would probably be safer for me just to stick with my original formula if it can be salvaged for this.

As far as my weird math, I can see how it would be confusing. It's just my game is still very much in the testing phase, so I change numbers around a lot in my formulas. So that's why you see the odd *1's or *5*2's. So I would just try to humor me and ignore it if you can. lol

Last edited:

#### Anastasius

##### Veteran
Yeah, it seems you're right and I would have to go through and factor in all of my resistances (and from the looks of it a whole lot more) to get the result I'm looking for. So this is probably out of my league.

I was thinking this would be relatively easy to do, but apparently I was very wrong about that.
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.

Last edited:

#### ATT_Turan

##### Forewarner of the Black Wind
Sure, I'll walk you through it.
Formula:

`if (a.atk >= v[17]*5) { \$gameVariables.setValue(1207, (v[17]*5*2 - 1 * b.def) / 2);`
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.

Comment Event:

``` \$gameVariables.value(1206).gainHp(\$gameVariables.value(1207)); ```

But that didn't work.
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>``````

#### Anastasius

##### Veteran
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>``````
You should use `> 1` instead, since 1 damage will still give zero heals.
JavaScript:
``````<Post-Damage Eval>
if (value > 1) user.gainHp(Math.floor(value * 0.5));
</Post-Damage Eval>``````

Last edited:

#### ATT_Turan

##### Forewarner of the Black Wind
You should use `> 1` instead, since 1 damage will still give zero heals.
Fair enough - I was mostly concerned with avoiding the possibility of dividing by zero.

Which is stupid because I wasn't dividing by that number

Well, that's what I get for writing a post while playing another game.

#### Arthran

##### Veteran
@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.

Last edited:

#### Anastasius

##### Veteran
``` \$gameVariables.value(1206).gainHp(\$gameVariables.value(1207)); ```

But that didn't work. I've read Arthran's post many times, but I don't understand the mechanics so paying more attention probably isn't going to help me, since I don't understand the process itself. If you can show me how to properly write it into my formula I'll give it another go and see if I can make it work.

Your truncated code is a lot neater. But I'm not familiar with some of the language you use, so it would probably be safer for me just to stick with my original formula if it can be salvaged for this.

As far as my weird math, I can see how it would be confusing. It's just my game is still very much in the testing phase, so I change numbers around a lot in my formulas. So that's why you see the odd *1's or *5*2's. So I would just try to humor me and ignore it if you can. lol
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++:
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:

Fair enough - I was mostly concerned with avoiding the possibility of dividing by zero.

Which is stupid because I wasn't dividing by that number

Well, that's what I get for writing a post while playing another game.
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.

Last edited:

#### ATT_Turan

##### Forewarner of the Black Wind
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.
That was my primary reason for just going to the plugin (plus, it was way less complicated). You're absolutely right that it could be a desired outcome, and right that it is possible to account for without the plugin.

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.
Well, I'm not always right

#### Berylstone

##### Veteran
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++:
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.

Last edited:

### Latest Profile Posts

The main game of my trilo/saga 50%OFF on Steam..... its now or never more
I swap between Ace and MZ so I can stay fresh but - what do you mean you can use subfolders in the plugin's folder for easier organization!?
Did some new music again, praise be. To the next song!
Watch Studio Blue play Numina by starlit in our latest RPG Maker Games Critique stream starting NOW!