Gw Temp

Menu

Tutorial - 'Battery Depletion' by Guest

An item about RPGMaker 2000 posted on

Blurb

A tutorial on making a system that uses batteries. Shocking!

Body

Battery Depletion Tutorial
-------------------------------------

This is my first tutorial ever, and so bare with any confusions that may arise. I will try to answer them if you need any further explanations. This system is used in my current project: Perfect Creation. It is made using RM2k3. I also use curly brackets {} for comments. These are not part of the code itself.


The Aim
------------
In some games, you may have a cell phone system that allows you received information from different people, and also to do other things. This tutorial will make having the cell phone a little harder than normal. Every cell phone has a battery, and this one is no different. This battery will deplete, and stop working until it is charged. That is also what will happen here. . So, first things first, a list of the necessary switches, variables and other useful things.

Common Events (2)
-----------------------------
You need to have this common event to make sure that the timer on the battery will always be on. The programming is very simple. The numbers are made up for the sake of the tutorial. They are also useful to test the system with.

>Common event - Battery Timer (Parallel Processing)

>Variables (1): 0001: BatterySeconds

<> Branch if Var [0001: BatterySeconds] is 20 {Time before flat battery}
<>
:Else Handler
<> Wait 1.0 sec
<> Variable Oper: [0001: BatterySeconds] + , 1
<>
:End
<>

This increases the status counter by 1 every second, thus adding a little realism to the system.


Another thing you might want to include, is a CMS (Custom Menu System) for the cellphone. I will include a little info, and the way that I have done this.
The CMS will be the root of you cellphone, and will include the Battery Status.

Here is the coding I used to get to my CMS Cellphone.



>Switches (1): 0001: Cell Phone Accessed

>Variables (5): 0002: Map ID
0003: Map X
0004: Map Y
0005: Menu Go To
0006: Menu Leave


>Common Event - Cellphone Access (Parallel Processing)

>(Common Event) Code:

<> Branch if Var [0001:BatterySeconds] is 20 or More {time before flat battery}
<>Key Input Proc: [0005: Menu Go To] is 7
<>Branch if Var [0005: Menu Go To] is 7
<>Message: The Cell Phone has a flat battery.
<>
:End
<>
:Else Handler
<> Branch if Switch [0001:Cell Phone Accessed] is ON
<>Key Input Proc: [0006: Menu Leave] {Set this to Shift, so that when you press the Shift key, it accesses the menu}
<>Branch if Var [0006: Menu Leave] is 7
<>Recall to Location: V[0002] (V[0003], V[0004])
<>Switch Operation: [0001: Cell Phone Accessed] OFF
<>
:End
<>
:Else Handler
<>Key Input Proc: [0005: Menu Go To] {again set this to shift, so that you can leave the menu}
<>Branch if Var [0005: Menu Go To] is 7
<>Memorize Location: [0002], [0003], [0004]
<>Switch Operation: [0001: Cell Phone Accessed] ON
<>Teleport: {Location of CMS, Co-ordinates, face direction}
<>
:End
<>
:End
<>

This is the basic coding that I used to access and leave the CMS for the Cell Phone. Each little part is roughly the same.


Now onto the main part of the battery coding.


Firstly, you need a set of graphics for the battery. Click this link to download my Battery, which is good as a template. It either needs putting into a tileset or a charset for use. Mine is in the tileset i have created for my CMS.

The Battery
-----------------
The switches and variables from before will also be used again here...

>Switches (2): 0001: Cell Phone Accessed
0002: Flash {this will make the battery flash when its low}

>Variables (4): 0001: BatterySeconds
0002: Map ID
0003: Map X
0004: Map Y

>Code:


Event: Battery
Page: 1
Graphic: Full Battery
Preconditions: Variable [0001: BatterySeconds] is Equal To or Greater Than 0
Trigger: Action Key
Commands: None

Page: 2
Graphic: Battery 3 Bars
Preconditions: Variable [0001: BatterySeconds] is Equal To or Greater Than 5
Trigger: Action Key
Commands: None

Page: 3
Graphic: Battery 2 Bars
Preconditions: Variable [0001: BatterySeconds] is Equal To or Greater Than 10
Trigger: Action Key
Commands: None

Page: 4
Graphic: Battery 1 Bar
Preconditions: Variable [0001: BatterySeconds] is Equal To or Greater Than 15
Trigger: Parallel Process
Commands:
<>Wait 0.2sec
<>Switch Operation: [0002: Flash] ON
<>

Page: 5
Graphic: Battery Empty
Preconditions: Switch [0002: Flash] is ON
Variable [0001: BatterySeconds] is Equal To or Greater Than 15
Trigger: Parallel Process
Commands:
<>Wait 0.2sec
<>Switch Operation: [0002: Flash] OFF
<>

Page: 6
Graphic: Battery Empty
Preconditions: Variable [0001: BatterySeconds] is Equal To or Greater Than 20
Trigger: Parallel Process
Commands:
<>Message: The battery is dead.
<>Switch Operation: [0001: Cell Phone Accessed] OFF
<>Recall to Location: Recall to Location: V[0002] (V[0003], V[0004])
<>


That is all for the battery status. As the counter for the battery (in the common events) goes up, the battery will begin to deplete. And because it uses Parallel Processing, it will deplete during the menu and possibly through battles as well...
To fit this into your own system, the numbers used must be higher. It must also be in seconds. In my game, I will use the value 600seconds for every 10 minutes I need. So when the counter reaches 600, the battery will deplete by 1 until it is empty.

Now for the final part of this tutorial. The charging unit. This can be anything in the game that will charge the battery back up. For my game, it will be a fixed unit in a fixed location, so I can do the whole charge up in a single event. If you wish to use items, I will include that at the end.

Charging - With A Fixed Charger
------------------------------------------------
This code takes place in each charge unit.

Event: Charger
Page: 1
Graphic: Charge Unit
Preconditions: None
Trigger: Action Key
Commands:
<>Message: Do you want to charge the Cell Phone?
<> Show Choices: Yes/No
: [Yes] Handler
<>Variable Oper: [0001: BatterySeconds] Set, 0
<>
: [No] Handler
<>
:End
<>

That is all that is needed for the fixed charger. If you want to set a time to pass before it becomes charged, and even be filled only slightly, then the coding is quite simple. A timer, and a Common Event that resets the Variable [0001: BatterySeconds].
If you need help on that, let me know, and I will do a little tutorial on that as well.


Charger - An Item (such as Spare Battery)
-------------------------------------------------------------

>Switch (1): 0003: Item Charger

>Variable (1): 0001: BatterySeconds

>Item (1) - Call this Item anything you want. Make it a Switch Item, and have it turn on the Switch [0003: Item Charger]. Anything else is up to you.

>Common Event - Battery Item (Parallel Processing [Switch: 0003: Item Charger])

>(Common Event) Code:

<>Variable Oper: [0001: BatterySeconds] Set, 0
<>Switch Operation: [0003: Item Charger] OFF
<>

The code here resets the battery and turns of the event to prevent a loop resetting the battery.


And that covers the tutorial for the creation of a Cell Phone Battery that depletes and cause the Phone to be inaccessible when the battery has died. Of course, the battery event can all be made into a single page using Branch Conditions, but for furture programming and development, it is easier when things are split up. The actual idea behind this is very simple, but does take time, and it can add an interesting addition to the gameplay...though try to make the gap between the battery being full and empty quite large. In Perfect Creation, it will be about 30-45 minutes, with the game being about 8-10 hours. You can even add other things to this, like an event which makes a sound beep every few seconds, to tell you when the battery is low, as well as the flashing battery.

Any problems, feel free to let me know, and I will try to sort it out immediately.

If this is used, please credit me. It took me some time to make this event work, let alone write this tutorial.

Thanks

Logan Forrests
The Rebellion

{Logan_Forrests@hotmail.com}