RMMV Damage Formula - ideas and help

Joined
Jan 7, 2020
Messages
4
Reaction score
1
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
May 12, 2018
Messages
1,012
Reaction score
944
First Language
English
Primarily Uses
RMMV
Oh my bad. Minor capitalization error

actorId(), not actorid()

So:

Code:
if (a.isActor()) v[25] = a.actorId(); a.atk * 4 - b.def * 2
 
Joined
Jan 7, 2020
Messages
4
Reaction score
1
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Jun 6, 2014
Messages
1,398
Reaction score
316
First Language
Portuguese
Primarily Uses
RMMV
yeah, javascript is case sensitive. meaning aA is sifferent from Aa that is different from AA that is different from aa
 

Accatosh

Veteran
Veteran
Joined
Dec 16, 2018
Messages
69
Reaction score
11
First Language
Swedish
Primarily Uses
RMMV
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?

Thank you in advance.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,012
Reaction score
944
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Jun 6, 2014
Messages
1,398
Reaction score
316
First Language
Portuguese
Primarily Uses
RMMV
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?

Thank you in advance.
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
Veteran
Joined
Dec 16, 2018
Messages
69
Reaction score
11
First Language
Swedish
Primarily Uses
RMMV
@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
Veteran
Joined
May 12, 2018
Messages
1,012
Reaction score
944
First Language
English
Primarily Uses
RMMV
@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
Veteran
Joined
Mar 10, 2013
Messages
1,213
Reaction score
438
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
May 12, 2018
Messages
1,012
Reaction score
944
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Mar 10, 2013
Messages
1,213
Reaction score
438
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Jun 6, 2014
Messages
1,398
Reaction score
316
First Language
Portuguese
Primarily Uses
RMMV
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
Veteran
Joined
May 12, 2018
Messages
1,012
Reaction score
944
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Mar 10, 2013
Messages
1,213
Reaction score
438
First Language
English
Primarily Uses
RMMV
Observed and updated. Thank you again for the help, both of you.
 

itzel

Warper
Member
Joined
Feb 9, 2020
Messages
2
Reaction score
0
First Language
English
Primarily Uses
RMVX
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
Veteran
Joined
Jun 6, 2014
Messages
1,398
Reaction score
316
First Language
Portuguese
Primarily Uses
RMMV
@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

Villager
Member
Joined
Jan 22, 2019
Messages
21
Reaction score
10
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Jun 6, 2014
Messages
1,398
Reaction score
316
First Language
Portuguese
Primarily Uses
RMMV
@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...
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

What if I took a lesson from Half Minute Hero? Let the player get dumb powerful each area, but reset them down to just slightly stronger than before for the next map?
Been averaging 2-3 hours sleep for almost a month now. Starting to space out all the time ^^;
loopk wrote on whtdragon's profile.
Nice to meet you. My name is loopk.
May I use the materials distributed here for adult games for sale?

Thank you in advance.
loopk wrote on Avery's profile.
Nice to meet you. My name is loopk.
May I use the materials distributed here for adult games for sale?

Thank you in advance.
tfw, after your game being intensively played by many people, after 5 years, patch after patch released, suddenly an innocent person reported another bug.

Forum statistics

Threads
94,256
Messages
919,443
Members
123,971
Latest member
TsuruharaYuki
Top