じ☆ve冰风 发表于 4 天前

Generate Bank Interest (with Demo!)

So I've seen many tutorials about eventing a banking system but there are no tutorials about implementing an interest system.

The player needs a good reason to want to store money in the bank. So I fiddled around with the eventing options and came up with a way to generate interest over a period of time. This can be number of steps or play time. This interest system is fully evented and requires no scripts whatsoever.

I'll try to make this as noob-friendly as possible. But since this is my first ever tutorial, there aren't any guarantees 
http://www.rpgmakervxace.net/public/style_emoticons/default/mellow.png


Here's a small demo to show you how it works. I also added comments in the event pages to try to explain what I did, so look through that if you're having trouble.
The demo contains the full banking system, complete with Withdraw, Deposit, Review Balance and Add Interest.
Download Demo Here

First of all, you'll need 6 variables:


http://s10.postimg.org/9i2bybcqh/Variables.png



*Note: Variable 6 "Bank Steps" is not required. I noticed it after completing everything, so couldn't change it. Just imagine it was never there.

Since this tutorial is about implementing interest, I won't go into detail on the basic banking process. There are plenty of tutorials floating out there that can teach you how to do that.

So the first three variables are required for the basic banking. For the interest, we'll be using variables 4 (Global Steps), 5 (Local Steps) and 7 (Bank Interest)

The first part of the event should look like this:


http://s14.postimg.org/se3dmk1ld/Steps_Interest.png


Now, let me explain how this works.


http://s30.postimg.org/fijue9va9/Steps.png


Here, we will be calculating how many steps the player took since the last time the bank was accessed. You wouldn't want the interest to keep increasing as the game steps increase to a massive amount!
This willl probably be the most difficult part of the event. So try to understand it clearly.

*Note: If you want to generate interest by game time instead of steps, simply replace steps with play time when binding it to a variable.

First we will bind the total steps the player took throughout the game to a variable. In this example, that would be variable 4 "Global Steps".
To bind a variable to game steps(or time), simply choose 'Variable Operation' and substitute the variable with the 'Game Data' option in the variables menu.
Then we will subtract the amount stored from the last time the bank was accessed. That would be binded to a new variable. In this example, variable 5 "Local Steps" was used for that purpose. If the bank was accessed for the first time, the value would obviously be zero, thus no change whatsover.After subtraction, the "Local Steps" variable will receive the game steps again. This means it now recorded the new number of steps.

Here's an example of how this works. Lets say the first time the player accessed the bank, he had already walked 220 steps. If you follow the event properly, this is what happens:

> GS (Global Steps Variable) recieves 220 (number of steps)
> GS - LS (Local Steps variable). Since LS = 0, GS is still 220
> LS receives 220

Then the next time the player accessed the bank, he walked another 300 steps.

> GS receives 520 (the 220 from before and the additional 300)
> GS - LS. LS now equals 220 from last time. So 520 - 220 = 300 steps! (Success! Yay 
http://www.rpgmakervxace.net/public/style_emoticons/default/laugh.png
 )
> LS receives a new value of 520

So this is how you calculate the number of additional steps from the last time the bank was accessed.

Congratulations! You have completed the most difficult part of the event! The rest is simple mathematics 
http://www.rpgmakervxace.net/public/style_emoticons/default/happy.png




http://s13.postimg.org/a53yefi8n/Interest.png


Now for some old school maths. Yes, finally those painful lessons will pay off 
http://www.rpgmakervxace.net/public/style_emoticons/default/huh.png


To calculate interest, we will use the simple mathematical formula of I = PRT/100 (I'm sure everyone knows this)
We already got the tricky part, the time, and the principle is just the amount you have in the bank, So that leaves us with just the rate!
The rate is completely your choice. In this example, I'll be using 1 per 15 steps.ie: 1/15. If you choose 1 per 20 steps, it'll be 1/20 and so on.

So if you look at the event, first we multiply the time we achieved with the Bank Gold. DO NOT MULTIPLY BANK GOLD BY TIME, IT MUST BE TIME BY BANK GOLD. The obvious reason is not to change the Bank Gold Variable.Anyways, we then multiply it by the rate as the formula says. Since the rate is 1/ 15, the number actually gets divided by 15. So thats how we get PRT. Now we divide this by 100. To simplify things, as you can see in the screenshot, I simply divided it whole by 1500 instead of dividing by 15 and again dividing by 100. So if you're rate is 1/15, its No. of steps multiplied by Bank Gold and the answer divided by 1500. If its 1/20, its divided by 2000. Piece of cake.

Now you simply add your answer to a new variable. In this case, its Variable 7 "Bank Interest". REMEMBER TO ADD IT. ITS A COMMON MISTAKE TO SUBSTITUTE THE VALUE. YOU SHOULD ADD THE VALUE, NOT REPLACE IT.

Then you just continue to regular banking:


http://s28.postimg.org/50xxcw2vh/Choices.png




Now there is just one simple step left. You have to create an option, something like "Add Interest", to the banking event.


http://s27.postimg.org/94p8uj343/Add_Interest.png


You display a text stating the interest that was generated using the Bank Interest Variable, then give the player the choice to add the interest to the bank money. If he chooses 'Yes', simply add the interest variable to the Bank Gold and then empty the Bank Interest Variable (see screenshot above)



So after the long eventing process, you're event should look like this(the banking part isn't included here.Check the demo if you need it)

*The Input Number and Party Gold are needed for the main banking purposes, not for generating an interest

http://s13.postimg.org/d4t8kil93/Full1.png


http://s21.postimg.org/4oab4jc8n/Full2.png



Phew! That was a long tutorial. Hope I was able to help and explain clearly.
Feel free to ask anything!


本贴来自国际rpgmaker官方论坛作者:Naveed处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/generate-bank-interest-with-demo.30899/
页: [1]
查看完整版本: Generate Bank Interest (with Demo!)