# PERCENTAGES IN RPG MAKER 2003

### A guide on how to work with percentages in RPG Maker 2003

- Momeka
- 11/10/2019 01:04 PM
- 1964 views

**Percentages in RPG Maker 2003**

While percentages isn’t something that usually comes up when making a game in RPG Maker 2003 it does have it uses. Especially when you’re making custom systems and menus. Like in a healthbar to display a character’s HP or maybe a skill that scales its damage depending on the users remaining health.

Since I’m forgetful and math isn’t my strong suit I keep forgetting how it works and end up having to look it up again and again. So I figured it would be easier to write a little guide that I can go back to and it might help others as well.

There is links to a demo project at the bottom. The demo will showcase the examples used in the guide. So you can look at all the events yourself.

So let’s get started.

**Converting values to percentages**

Usually when you want to get the percentage of something you would divide it by the max value. Like 45 / 75 results in 0.6 which would be 60%. This doesn’t work in RPG Maker 2003 since it doesn’t support decimal numbers (also known as floating points). So we are stuck working with regular integers. That means when we’re calculating the percentage we want to get back a number from 0 to 100 instead of a 0.0 - 1.0.

To achieve this we can use this formula:

*result = (100*current + max/2)/max*

With 45 out of 75 it would turn into this:

*result = (100*45 + 75/2)/75*

result = (4500 + 37)/75

result = 4537/75

result = 60

result = (4500 + 37)/75

result = 4537/75

result = 60

But how do we get it into RPG Maker 2003? Well, let’s start by creating a common event and we’ll take it step by step from there.

Name it to something like “Get %” and set the trigger to “

*None*”.

Secondly we’ll need 4 variables. So let’s start with creating them:

*% Result*- This variable will contain the result of our calculations. The actual percentage so this is the variable you’ll want to use to set your Healthbar or whatever it is you need the percentage for.

*% Max Value*- This variable stores the max value of the number we want to get the percentage of. This would need to be set before you call the Get % common event.

*% Current Value*- This variable stores the current value of the number we want to get the percentage of. This would also need to be set before you call the Get % common event.

*% Temporary*- This is a variable that is only used during the calculation in the common event. You won’t need to set it before nor use it afterwards.

Your variable window should look something like this:

Now that we have all the variables we can start implementing the formula in the common event. We’ll start with this part of the formula:

*result = (100*current +*

**max/2**)/maxWe’ll do this by setting the

*% Temporary*variable to the

*% Max Value*variable. After that we divide it by 2. Simple enough, you should see something like this:

Now let move on to this part:

*result = (*

**100*current**+ max/2)/maxStart by setting the

*% Result*variable to the

*% Current Value*variable. Then we multiply the

*% Result*variable by 100. So now you should have this:

Now just add the

*% Temporary*to the

*% Result*variable.

Finally just divide the

*% Result*variable with the

*% Max Value*variable.

With that the common event is complete. So let me show how it would be used in an event. Say our heroic hero has been injured or just healed and we need to update their healthbar, then we would do something this:

In this case 333 would be our hero's max hp so we set the

*% Max Value*variable to that. And we set the

*% Current Value*to be equal another variable, in this case that variable would store the hero's current hp.

Then we simply call the common event we just made to calculate the percentage. Since the spritesheet index always start at 1 and not 0 we need to add a 1 to the result.

But what if our healthbar isn’t from 0 to 100, what if it’s from 0 to 34? Well then let’s move on to the next part.

**Converting percentages to values**

To convert a percentage to a number we would use this formula:

*result = (percent * (max - min) / 100) + min*

In the case of 60% out of 75 it would be like this:

*result = (60 * (75 - 0) / 100) + 0*

result = 60 * 75 / 100

result = 4500 / 100

result = 45

result = 60 * 75 / 100

result = 4500 / 100

result = 45

Now you might think it’s weird that there is a bunch of zeros in the formula. That cause this formula allows us to convert from more value ranges than zero to some higher value. We could do 23 to 434 if we wanted or whatever else.

If all we wanted was values that start from zeros we could use this formula instead:

*result = (percent * max) / 100*

Which is simpler to implement but we won’t go through it in this tutorial.

We will need another Common Event so let's make one. Name it to something like Map %. As before the trigger should be set to “

*None*”

We’ll also need an additional 4 variables. So let’s go ahead and make them:

*Get Result*- This variable will contain the result of our calculations. This is the value you would use after you called the common event.

*Get Max Value*- This is the maximum value of the range we want to get the percentage. This would need to be set before you call the event.

*Get Min Value*- This is the minimum value of the range we want to get the percentage. This too would need to be set before you call the event.

*Get %*- This is the percentage to use. 0 would be the minimum value, 50 would be half and 200 would be double the max value etc. This will also need to be set before you call the event.

Now your variable window should look like this:

With that done let’s move on to implementing the formula. We’ll start with this part:

*result = (percent **

**(max - min)**/ 100) + minWe do this by setting the

*Get Result*variable to be equal to the

*Get Max Value*variable. The we subtract

*Get Min Value*from it.

Next let’s do this whole part:

*result =*

**(percent * (Get Result) / 100)**+ minStart by multiplying

*Get Result*variable with the

*Get %*variable. Then simply divide

*Get Result*with 100.

The final step is just to add

*Get Min Value*to the

*Get Result*variable and we’re done!

Now lets see it used in action. In this case we have a space ship that over the duration of 2 seconds it should move to a position and scale up. Now this could easily be done with a Move Picture event but maybe we want to be able to pause and resume the movement or even let the player control where along the path the ship should be. To do this we have a parallel process event on a map. It’s set up like this:

The

*Current Frame*variable is where along the path the ship is. It’s essentially just a timer ticking up. The

*% Max Value*is set to 120, which would be 2 seconds. RPG Maker 2003 runs at 60 frames per seconds, meaning the event will update 60 times each seconds. Thus 120 times for 2 seconds.

With the

*Current Frame*and

*% Max Value*set we can get the percentage of the path traveled by using our

*Get %*common event we made before. With a percentage we can map the ships positions and size with our new

*Map %*event. Just set the min and max value of each variable.

Then we simply draw the ship as an image using the X, Y, and Size variables we got back.

**Demo Project**

The demo project contains the two examples used above.

You can download it from here: