Heal player per life percentage

mogneto

Gureito Eventer
Member
Joined
Oct 2, 2016
Messages
18
Reaction score
6
First Language
Portuguese
Primarily Uses
RMMV
Morning, Night or Evening to all of you!

Well, I was trying to do this script thing and I have a problem here.

$gameActors.actor(1).gainHp(0.04*(m.mhp));

So I want this script call to heal my actor for 4% of his HP when the script is active. Sadly this doesn't happen
when I use this command, but it happens if I use number values instead, just like this:

$gameActors.actor(1).gainHp(100);

What did I do wrong?
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,604
Reaction score
5,071
First Language
English
Primarily Uses
RMVXA
The shortcut for "user" is a, and the shortcut for "target" is b... not m. If you are doing this outside of a battle formula, you need to reference the object (so $gameActors.actor(1) in your case) rather than use a shortcut.
 

mogneto

Gureito Eventer
Member
Joined
Oct 2, 2016
Messages
18
Reaction score
6
First Language
Portuguese
Primarily Uses
RMMV
Mr. Wavelength, you're a god.

What you told me was very helpful. For your contribuition, you've been honored.
Again, you have my thanks.
 

mogneto

Gureito Eventer
Member
Joined
Oct 2, 2016
Messages
18
Reaction score
6
First Language
Portuguese
Primarily Uses
RMMV
I'm also trying to round up my heal, because sometimes it comes with decimal values.

tried to do something like this but it didn't work.

var m = $gameActors.actor(2)

Math.round($gameActors.actor(2).gainHp(0.04*(m.mhp)));
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
2,827
Reaction score
992
First Language
Dutch
Primarily Uses
RMMV
dont use m.mhp on the end, just mhp can do because m.mhp has no strings.
if mhp dont work, use ._mhp, i dont see why you use var though.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,604
Reaction score
5,071
First Language
English
Primarily Uses
RMVXA
I'm also trying to round up my heal, because sometimes it comes with decimal values.

tried to do something like this but it didn't work.

var m = $gameActors.actor(2)

Math.round($gameActors.actor(2).gainHp(0.04*(m.mhp)));
It's a logic error. gainHp() doesn't return a value, so you won't be able to round it. Try:

$gameActors.actor(2).gainHp(Math.round(0.04*(m.mhp)));

or, to ensure you're always rounding up:

$gameActors.actor(2).gainHp(Math.ceil(0.04*(m.mhp)));
 

mogneto

Gureito Eventer
Member
Joined
Oct 2, 2016
Messages
18
Reaction score
6
First Language
Portuguese
Primarily Uses
RMMV
It's a logic error. gainHp() doesn't return a value, so you won't be able to round it. Try:

$gameActors.actor(2).gainHp(Math.round(0.04*(m.mhp)));

or, to ensure you're always rounding up:

$gameActors.actor(2).gainHp(Math.ceil(0.04*(m.mhp)));
It worked pretty fine! Thank you all guys!
 

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

Latest Threads

Latest Profile Posts

Realizing my earlier maps are an abomination against all things, I'm doing a bit of a remake. Tell me if you can see the difference. :LZSwink:



And the horrific before pics...

Last part of OcRam Obfuscator sneek peaks!
YES! officially released my games soundtrack on Itunes, Spotify, and Amazon..... kinda cool!

Another old age version of Reid. Trying out different style.

Forum statistics

Threads
105,597
Messages
1,014,899
Members
137,266
Latest member
Bradzackyle
Top