Blah_Blee

Professional Idiot
Veteran
Joined
Feb 4, 2015
Messages
212
Reaction score
41
First Language
English
Primarily Uses
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
Veteran
Joined
Aug 3, 2012
Messages
22,305
Reaction score
11,730
First Language
English
Primarily Uses
RMVXA
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
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Mar 5, 2013
Messages
32,339
Reaction score
8,075
First Language
German
Primarily Uses
RMMV
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
Veteran
Joined
Feb 4, 2015
Messages
212
Reaction score
41
First Language
English
Primarily Uses
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
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
220
First Language
English
Primarily Uses
RMVXA
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 Threads

Latest Profile Posts

Well, I've decided I'll take a break on making Forgotten Eclipse...and Make a mod for FNF
Trailer for my new game.
last one for a while
MythicRuss wrote on gothicvoid's profile.
hi, i was looking thru ur awesome stuff, and was looking around the internet, how in the heckin heck do i get the hiddendoors to open? im addng them to the doors event but they just appear as solid walls, btw am total noob lol

Forum statistics

Threads
110,308
Messages
1,052,192
Members
143,343
Latest member
DarkValkyrieSin
Top