(Conditional Branch) check if an actor's HP is full (percentage)?

RicoRob

Veteran
Veteran
Joined
Apr 28, 2016
Messages
54
Reaction score
4
First Language
Portuguese (Br)
Primarily Uses
RMMV
- Example:
1585496939236.png
-
I know this code: $gameActors.actor(n)._hp = x
however I can only replace the x with specific numbers, I want to check for percentages, but I have no idea how.

Is there a way to use only script calls for this? Without storing numbers in variables, adding invisible states and the like?
 

Soulrender

Veteran
Veteran
Joined
Jan 12, 2019
Messages
411
Reaction score
244
First Language
Poland
Primarily Uses
RMMV
Calculating percentage is simple:

(a / b) * 100

so replace a with $gameActors.actor(n).hp
then replace b with $gameActors.actor(n).mhp

multiply it by 100 and you get result in percentage.

Oh, to get more precise result, use Math.floor() function

example:
var x = Math.floor((a/b)*100);
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
659
Reaction score
373
First Language
English
Primarily Uses
RMMV
hpRate() returns a float of the current HP percentage.

So for your script, use $gameActors.actor(n).hpRate() == 1
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
703
Reaction score
549
First Language
French
Primarily Uses
You can also use
Code:
$gameActors.actor(n).hp === $gameActors.actor(n).mhp
Edit: oh didn't see it had to be a percentage check, my bad.
 

RicoRob

Veteran
Veteran
Joined
Apr 28, 2016
Messages
54
Reaction score
4
First Language
Portuguese (Br)
Primarily Uses
RMMV
@ramza That does the trick!

@Astfgl66 that also works! Just want to check if the HP bar is full.

Thanks everyone! :kaocry:
 

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

Latest Threads

Latest Posts

Latest Profile Posts

I forget what is bumping rule in this forum. Is anyone know? Thank you.
BCj
Ew, why does my blogpost on the rpgmaker.net site look like a garbled mess? Are html codes disabled or something?
I feel that I should cut down on my order queue so I can get some more time for my projects, its been quite a longggg while since I worked on them LOL
I friend of mine insisted on practicing dubbing things with him... and its quite funny, yet, it really takes a huge amount of practice!
Gotta save this for my next thread later...

Forum statistics

Threads
97,882
Messages
947,617
Members
129,116
Latest member
Lupom
Top