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

RicoRob

Veteran
Veteran
Joined
Apr 28, 2016
Messages
59
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

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
838
Reaction score
467
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);
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
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
59
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:
 

Killerslash

Veteran
Veteran
Joined
Mar 31, 2017
Messages
65
Reaction score
12
First Language
Arabic
Primarily Uses
RMMV
If I want to make Hp actor is zero, how?
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
838
Reaction score
467
First Language
Poland
Primarily Uses
RMMV
$gameActors.actor(id).gainHp(-$gameActors.actor(id).mhp);

This will set actor's HP to 0
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Yet another custom skill animation, sometimes i waste too much time on details people will barely notice :kaocry:
Time flies by... already 1/6th of the calendar released :o
Realizing that 2020 is the only year since 2015 that I haven't made a RM game. Maybe I should do a tiny one to keep the streak?
grief... lol... I keep seeing request for MZ versions of MV plugins. this is why I haven't moved over and just MZ for my MV project.

Forum statistics

Threads
105,815
Messages
1,016,668
Members
137,512
Latest member
xperiad
Top