(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
663
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

Please do not buy games from g2a.com. The sellers have total power over you. The website has many scam sellers. It looks cheap, but the key code didn't work.
A while back I was having fun making my own custom tiles, then I hit carpet... why is it so difficult!? Lol.
Weekend is finally here... what would you like to see (?):
1) Pokemon into zelda minish-cap style
or
2) Pokemon into zelda gbc style
or
3) Zelda into pokemon style

#= Choose ===============#
||__[ Full mockup ]_[ Charset ]__||
#=======================#
I know someday I'll start working on this...

I'm so happy that I got Steam achievements to work in my game, thanks in large part to the posts by other RPG Maker devs on this issue!

Forum statistics

Threads
97,943
Messages
948,060
Members
129,193
Latest member
annygma
Top