# Making Variables Check Health Percentages?

#### Blah_Blee

##### Professional Idiot
Hello, everybody. Just a quick question:

I've been trying to set a variable (in a common event) to a certain percentage (in this case, 10%) of one's maximum HP, then use a conditional branch to check if their current HP is less than the variable. After trying to use the classic 'divide health by max health and multiply by 100', I realized that RPG Maker cannot handle decimal values, and that the variable value will always remain at 0 as a result.

For further information: the goal in my game is not to reduce the opponent's health to 0 per se, but reduce their health enough and knock them down, where you can 'pin' them. The guard option was replaced by a 'pin' command, which sets off a common event. Said common event counts to 1, then checks the opponent's current and max HP to check if the opponent's current HP is less than 50% of their max HP. If the condition is met, it counts to 2, then checks if the opponent's health is less than 10% of their max HP. From there, if that condition is met once more, a three count will be made, and the battle is ended.

#### Kes

##### Veteran
There is what I can only describe as a counter-intuitive move in dividing variables.

Set variable #1

Operand 'set'

Game data - Actor's MHP

This is the counter-intuitive bit.  You use the same variable to get the division

Variable #1

Select 'Div' and in the operand put 10 (if you want 10%)

Variable #2

Actor's HP

Conditional

Variable #2 is less than variable #1

#### Sarlecc

##### Veteran
Another way to do it is do the first part of the above to get the players hp.

Then using the same variable select multiply (Mul) and in the script box put in 0.1 for 10%.

Then you can do the conditional like the above.

Last edited by a moderator:

#### Andar

##### Veteran
The problem is that the variables are integer by default, and integers always drop decimals.

But the easiest solution to that is to make the division the last operation: First multiply by 100 and then divide by max health to get the percentage value.

#### Blah_Blee

##### Professional Idiot
Another way to do it is do the first part of the above to get the players hp.

Then using the same variable select multiply (Mul) and in the script box put in 0.1 for 10%.

Then you can do the conditional like the above.
Silly me tried to use multiple variables to store the half and 10 percent hp values when I could have simply used the same max HP variable instead.

I tried multiplying by 0.1 in the 'constant' section to no avail, I didn't know that using the script box would work as well.

So would all three suggestions work in this case?

#### Rinobi

##### Veteran
Script Call:

x = \$game_actors[actor_id].param(0) ; x *= 0.1\$game_variables[variable_id] = xWhere 'actor_id' is the number of an actor in the database whose MHP value you need and 'variable_id' is the id of the variable in which you'll store 10% of the actor's MHP value.

### Latest Profile Posts

Moving day is on May 12! A month from today! I'm finally getting my own apartment!
I made the logo and title screen for my game (Still rough but at least it's got a design now)
Whelp, it's been a while. Had another retina surgery on april 1st on my left eye. Well, 4 time's the charm, right? *recovery mode on*
The next JABS update will include ally AI and an aggro system.

Question:
What would YOU expect to happen if you had four+ party members in an ABS, all fighting either together or separately or a mix of the two, and the player hits "swap leader" button?
It currently pulls all followers to the player's location, removes all aggro towards enemies, and swaps them.
Time to wear a new face again...

Should keep things interesting huh? @EpicFILE