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

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,569
Latest member
Shtelsky
Top