# RMMV Damage Formula - ideas and help

#### Random_StarWars_Coder87

##### Warper
If an enemy is using that same skill to attack with, it's going to mess up because enemies don't have an actor id. Try this revised version:

Code:
``if (a.isActor()) v[25] = a.actorid(); a.atk * 4 - b.def * 2``
Thank you. I tried this, and the now the opposite is happening. The enemies now can damage the actors, but the actors can't damage them.

#### Aesica

##### undefined
Oh my bad. Minor capitalization error

actorId(), not actorid()

So:

Code:
``if (a.isActor()) v[25] = a.actorId(); a.atk * 4 - b.def * 2``

#### Random_StarWars_Coder87

##### Warper
Oh my bad. Minor capitalization error

actorId(), not actorid()

So:

Code:
``if (a.isActor()) v[25] = a.actorId(); a.atk * 4 - b.def * 2``
Oh are those two different things?? I did not know that. By the way, it works now. Thank-you.

#### Waterguy

##### Veteran
yeah, javascript is case sensitive. meaning aA is sifferent from Aa that is different from AA that is different from aa

#### Accatosh

##### Veteran
Hello!

I need help with a formula. So I have tried making a formula which damages the user, when it has over 30% HP and heals when it is below that percentage. Here's what I did:

(a.mhp * 0.3) < a.hp ? a.gainHp(a.mhp * -0.1) : a.gainHp(a.mhp * 0.1)

But I also want the skill to damage the enemy. Thus I tried to do it like this:

a.atk * 4 - b.def * 2 && (a.mhp * 0.3) < a.hp ? a.gainHp(a.mhp * -0.1) : a.gainHp(a.mhp * 0.1)

This unfortunanly didn't work.
Can I please get help with this one? How can I fix this formula?

#### Aesica

##### undefined
Is the 30% heal/damage supposed to happen to the user regardless of whether they target an enemy or ally?

Anyway, the logic in the second one is weird and is tripping you up.
1. You're not doing any sort of check to see if an enemy is targeted, if your system allows for the targeting of enemies or allies alike.
2. The logic in the first part is a bit weird, because the a.atk * 4 - b.def * 2 part is always going to evaluate to true unless it equals 0.
3. That's...not really how you use the ternary operator (value = conditional ? trueValue : falseValue) however you're trying to use it like a classic if...else.
4. Damage needs to be the last thing in the formula box.
5. So, overall, your formula is trying to assign whatever value gainHp() returns after it is executed. Since it doesn't return anything, the resulting damage is undefined.
Anyway, I'm going to assume this is just a basic attack skill, intended to target an enemy, that will either damage the user if hp is above 30% or heals them if below. So, try this:

if (a.hp < a.mhp * 0.3) a.gainHp(Math.floor(a.mhp * 0.1)); else a.gainHp(Math.floor(a.mhp * -0.1)); a.atk * 4 - b.def * 2

#### Waterguy

##### Veteran
Hello!

I need help with a formula. So I have tried making a formula which damages the user, when it has over 30% HP and heals when it is below that percentage. Here's what I did:

(a.mhp * 0.3) < a.hp ? a.gainHp(a.mhp * -0.1) : a.gainHp(a.mhp * 0.1)

But I also want the skill to damage the enemy. Thus I tried to do it like this:

a.atk * 4 - b.def * 2 && (a.mhp * 0.3) < a.hp ? a.gainHp(a.mhp * -0.1) : a.gainHp(a.mhp * 0.1)

This unfortunanly didn't work.
Can I please get help with this one? How can I fix this formula?

there are two things you are doing wrong: you don't use && to separate things in damage formulas, you use ;
&& is for comparisons.
and second, the damage is the last thing in the formula.
meaning you need to separate your a.atk * 4 - b.def * 2 from your (a.mhp * 0.3) < a.hp ? a.gainHp(a.mhp * -0.1) : a.gainHp(a.mhp * 0.1) with an ; and a.atk * 4 - b.def * 2 goes the latest.

so,
(a.mhp * 0.3) < a.hp ? a.gainHp(a.mhp * -0.1) : a.gainHp(a.mhp * 0.1); a.atk * 4 - b.def * 2

@Aesica are you sure you can't use a ternary like that? while I mostly use them like "x = ternary" I think I already did something like this successfully before too...

#### Accatosh

##### Veteran
@Aesica and @Waterguy, thank you!

It works great! Also, thank you for letting me know that damage should be written last and that ";" separates.

#### Aesica

##### undefined
@Aesica are you sure you can't use a ternary like that? while I mostly use them like "x = ternary" I think I already did something like this successfully before too...
Well technically...I suppose you could since you're still invoking the functions (gainHp in this case). I guess that's why I like Javascript (yes, I actually like it) because it seems like there's always bizarre, alternative ways to do something.

#### Diretooth

##### Lv. 23 Werewolf
I'm trying to create an item that heals the user a variable amount. My initial attempt was 0.3*+(v[X]*.05), which in my mind translates to 30% plus 5% times Variable.
Since it didn't work, this is why I am here.
I want the item to heal a base 30%, but have it so that a variable adds 5%, in essence acting like the Estus Flask in Dark Souls 2 and 3, where it is enhanced to allow for more potent healing. Where do I go wrong in setting up the formula, and how could I make it work properly?

#### Aesica

##### undefined
I'm trying to create an item that heals the user a variable amount. My initial attempt was 0.3*+(v[X]*.05), which in my mind translates to 30% plus 5% times Variable.
Since it didn't work, this is why I am here.
I want the item to heal a base 30%, but have it so that a variable adds 5%, in essence acting like the Estus Flask in Dark Souls 2 and 3, where it is enhanced to allow for more potent healing. Where do I go wrong in setting up the formula, and how could I make it work properly?
If I'm reading you right, you want to heal the user for 30% of their max HP, plus 5% x v[x]? Try this:

b.mhp * 0.3 + b.mhp * 0.05 * v[x];

So:

v[x] == 0 => 30% healing
v[x] == 1 => 35% healing
v[x] == 2 => 40% healing

...etc

#### Diretooth

##### Lv. 23 Werewolf
If I'm reading you right, you want to heal the user for 30% of their max HP, plus 5% x v[x]? Try this:

b.mhp * 0.3 + b.mhp * 0.05 * v[x];

So:

v[x] == 0 => 30% healing
v[x] == 1 => 35% healing
v[x] == 2 => 40% healing

...etc
This words perfectly! Thank you! ^n.=.n^

#### Waterguy

##### Veteran
alternativelly, @Diretooth , you can use a very close code to both yours and @Aesica 's, but isntead of multiplying both sides for b.mhp you just multiply the result.
since multiplying both sides of an addition is the same as multiplying the result.

b.mhp * (0.3 + 0.05 * v[x])

assuming that you do mean a percentage of max hp, of course.
b.mhp is essential to be there though, or at least a value in its place. your original version of the code was doing it with 30% + 5% of variable... of 1. Since damage formula, be damage or heal, is rounded before being applied, it would only heal either 0 or 1, and 1 only if the variable was 4 or more to reach 50% to be rounded up.

#### Aesica

##### undefined
Honestly, I'm not sure why I wrote it the way I did, probably because I was tired if anything. But yeah, I'd suggest doing it this way over what I wrote:

b.mhp * (0.3 + 0.05 * v[x])

#### Diretooth

##### Lv. 23 Werewolf
Observed and updated. Thank you again for the help, both of you.

#### itzel

##### Warper
I'm looking to make some simple skills that have set damage ranges like in dragon quest. For example: a fire spell that does 10-20 damage or a heal spell that heals 30-50 Hp. Can someone help me with the formula? Thanks.

Last edited:

#### Waterguy

##### Veteran
@itzel if by set damage ranges you mean it is in that range regardless if your attack or magic is 1 or 99...
for the 10-20 put damage as 15 and variance as 33%, and for heal between 30-50 put damage as 40 and variance as 25%.
variance is a random value up to that percentage of the damage (25% of 40 is 10, so from 0 to 10) that has a chance of being either added or removed from the damage. meaning that damage 40 with 25% variance can go anywhere from 30 to 50, or from 40-10 to 40+10

#### xDRAGOONx

##### Veteran
I'm looking to make some simple skills that have set damage ranges like in dragon quest. For example: a fire spell that does 10-20 damage or a heal spell that heals 30-50 Hp. Can someone help me with the formula? Thanks.

Code:
``````Math.randomInt = function(max) {
return Math.floor(max * Math.random());
};``````
'Math.randomInt(max)' is a function used by MV to generate a random number between 0 and (max). Replace (max) with the max value of the skill. Then you add to it the minimum value you want the skill to hit for.

EDIT: Silva pointed out a mistake I made,
Math.randomInt(max) generates a whole number between 0 and (max -1)

Code:
``Math.randomInt(10) + 10``
This code, when placed in the damage formula of a skill, would cause the skill to hit between 10 - 19 damage.
one thing to note is that the max damage will be the two values combined (9 + 10) while the minimum damage will be the 10 at the end.

Last edited:

#### Waterguy

##### Veteran
@xDRAGOONx that is a good one, but would need variance to be set to 0...
but as I said ealier, variance is there to do... exactly that already...

#### xDRAGOONx

##### Veteran
@xDRAGOONx that is a good one, but would need variance to be set to 0...
but as I said ealier, variance is there to do... exactly that already...
I apologize, I had actuall meant to reply to itzel with that comment.

### Latest Profile Posts

Back in the old days, long before I was born, salted crisps - or potato chips, for you yanks - came unsalted and had a little pouch of salt to manually shake on it. Of course, things are more efficient now, but Walker's still brought back the old 'Salt 'N' Shake' style a couple years ago. Dunno why, but if I had to guess, I'd say it's because the nostalgia crowd were getting salty.
Guys I just want to sit around and work on my game! *gets lots and lots of money shoveled at him* Game, I don't recall a game. What game?
Seems like people have stopped looking both ways before crossing the road nowadays. Blindly walking out into a into a road only ends in disaster.
Just finished planning out the skeleton of the main quest line of my new game. I'm so excited for it!
Integrating Jason Perry's japan tile set while listening to Murray Atkinson's Heaven and Earth background music.

### Forum statistics

94,544
Messages
921,778
Members
124,411
Latest member
yellowsonicboom64