Gw Temp

Menu

Tutorial - 'Four Phase Day/Night in RM2K' by Rast

An item about RPGMaker 2000 posted on

Blurb

A more advanced Day night system, and it's from Rast! (Which means it is good)

Body

I wasn't going to post this since this day/night system is something new I made for DD2, but, I've had a lot of requests lately for a day/night tut, so here goes. This tutorial will demonstrate how to do the following:

1) How to create a day/night system with four phases (morning, day, evening, night) instead of the usual two (day and night).

2) How to set your outdoor maps up so they reset properly (go straight to the appropriate screen tone instead of the momentary glitch you see in many systems)

3) How to apply screen-level lighting effects to your indoor maps.

There's nothing overly complicated here, but there's a lot of steps, so pay close attention.

Step 1 - Variables and switches

You need these variables and switches to make this work.

V1) Time of Day (TOD). This keeps track of the current time of day. For this tut, it's values are:
- 1: Morning
- 2: Daytime
- 3: Evening
- 4: Nighttime

V2) Time of Day Counter (TODC). This is a timer that keeps track of the progression through the current time of day. The combination of this and the above variable are what is used to set the screen tone. This variable starts at 30 and counts down to zero.

V3) LightLevel. This tells the lighting event how you want your map lighted. I give it these values, you can add your own depending on your needs (simply edit the RestoreLightLevel event to deal with them)
- 1: Outdoors
- 2: Indoors Full
- 3: Indoors Morning
- 4: Indoors Evening
- 5: Indoors Night

S1) IsDay. This switch is ON during TOD 1 and 2, and OFF during TOD 3 and 4. You can use this to configure your NPCs or take other actions based on whether it is daytime or not (like in a normal day/night system).

S2) TimerEnable. If this switch is ON, day/night will progress normally. If it's off, day/night will not progress. You turn this off when you're in town to stop the day/night system. You'll also need to set this off when running a cutscene in an area where day/night normally progresses to keep the Screen Tone changing events from interfering with your cutscene.

S3) LightingWait. If ON, RestoreLightLevel will wait 0.5 seconds before returning (to allow the lighting to fully take effect before letting the game continue, useful for map transitions). If it's OFF, it will start the lighting transition and return immediatly (useful for when the lighting is changing as a result of day/night progression).

Step 2 - Setup

When your game starts, it should set TOD to 2 and TOD Counter to 30. Also turn on IsDay. This will prevent a momentary lighting glitch when you first step outdoors caused by the TOD and TODc variables being uninitialized.

Step 3 - Create your timing event

This event should be a parallel process common event, keyed on by the TimerEnable switch. It will then do the following:

1) Wait 0.5 seconds (If you have day/night running in town, I recommend you increase this to at least 2.5, as with this value a full day will pass each minute)
2) Decrement TODC by 1
3) If TODC is 0 or less...
- a) Set TODC back to 30
- b) Increment TOD by 1
- c) If TOD is 5 or higher, set TOD back to 1. If you're using a date system, this is the time to increment your date counter.
4) If TOD is 1 or 2, Set IsDay ON. If it's 3 or 4, set IsDay OFF.
5) If LightLevel is 1, set the LightingWait switch off and call RestoreLightLevel (all this will be explained in a moment)

Step 4 - Split up your teleports

In order for this system to work, you can't use normal teleport events. Instead, you have to split them up so the teleporting event fades the map out, and a map reset event fades the map back in. This is to prevent a momentary lighting glitch when you change outdoor maps. You can get away with using just two events, but I recommend four for easier editing later.

Event 1 - TransitionMapOut (common)

This event hides your map and prepares you to teleport. It does the following:

1) Turn off TimerEnable. This is important - if you're on a map where day/night progression is active leaving this switch on will cause your teleport to malfunction.
2) Set Screen Tone (0,0,0,0 [black])
3) If you need to do any custom map shutdown stuff, do it here

Event 2 - Teleport Event

This is the event that the player steps on to activate the teleport. It does the following:

1) Calls TransitionMapOut
2) Teleports player to destination
3) Sets hero facing as appropriate

Event 3 - TransitionMapIn (common)

This event is called by the map reset event and displays the map. It's a little more complex than TransitionMapOut, but not much.

1) If you need to do any custom map startup stuff that's the same on every map, do it here.
2) Set LightingWait ON and call RestoreLightLevel. This step will cause the map to transition to the exact correct lighting level specified in your map reset event, even if it's outdoors.

Event 4 - Map Reset Event

You'll need an event like this on every map. For the most part, it's copy and paste (CTRL-C and CTRL-V for those of you who don't know the speedy keyboard shortcuts), so it's not too much of a pain. This event is AUTOSTART with NO APPEARANCE CONDITIONS. It will run every time they first appear on a new map, and the purpose of this event is to set the map up after the party teleports. Anyway.. this event does the following:

1) If you're doing anything special (such as a cutscene), stick in a fork here and do it. Don't forget to switch it off when you're done.
2) If you have any custom map setup to do (such as custom systems) that's different on every map, do it here.
3) Set LightLevel as appropriate to this map.
4) Call TransitionMapIn
5) If Day/Night progression is active, turn on TimerEnable. Remember, TransitionMapOut turned it off so you need to turn it back on, even if you're going between two maps that both have day/night progression enabled. I recommend you leave this switch off for towns - it will still have the correct day/night lighting but day/night will not progress.
6) Clear Timer / Clear Event / Whatever your version of RPGMaker calls the command that deletes the event.

Step 5 - Create your lighting event (RestoreLightLevel)

Now for the big RestoreLightLevel event. This will probably be one of the longest events in your game, as it holds screen tone information for every day/night state in your game (all 120 of them), as well as any indoors lighting values you may have set up. This event is called every half second by the day/night timer when outdoors with day/night progression enabled, and also by all your map reset events.

Some important things before we get started...

1) All Screen Tone commands are set to 0.5 seconds, do not wait. Don't forget the Do Not Wait part or you'll be kicking yourself in the arse when you have to come back and fix all of them.
2) This sytem is based off the following screen tones for the four phases. If you change these, you'll need to recalculate all your screen tones (each should be 1/30 the difference between the current phase and the next).
- a) Morning: 70, 70, 100, 100
- b) Day: 100, 100, 100, 100
- c) Evening: 70, 70, 100, 150
- d) Night: 40, 40, 70, 50

This event takes the following actions to set up the map's lighting properly:

1) If LightLevel is anything EXCEPT 1 (outdoors)...
{
- a) If LightLevel is 2 (indoors full), Set Screen Tone 100, 100, 100, 100
- b) If LightLevel is 3 (indoors morning), Set Screen Tone 70, 70, 100, 100
- c) If LightLevel is 4 (indoors evening), Set Screen Tone 70, 70, 100, 150
- d) If LightLevel is 5 (indoors night), Set Screen Tone 40, 40, 70, 50
- e) If you set up any additional LightLevel values, set them up here.
} ELSE {
- a) If TOD is 1 (Morning)...
-- 1) If TODC is 30, Set Screen Tone 70, 70, 100, 100
-- 2) If TODC is 29, Set Screen Tone 71, 71, 100, 100
-- 3-30) Continue adding 1 to the Red and Green Screen Tone values for each value of TODC down to 1
- b) If TOD is 2 (Day)...
-- 1) If TODC is 30, Set Screen Tone 100, 100, 100, 100
-- 2) If TODC is 29, Set Screen Tone 99, 99, 100, 102
-- 3-30) Continue moving Red, Green, and Chroma toward their evening values in 1/30th increments. Use a calculator, it's a lot easier.
- c) If TOD is 3 (Evening)...
-- 1) If TODC is 30, Set Screen Tone 70, 70, 100, 150
-- 2) If TODC is 29, Set Screen Tone 69, 69, 99, 147
-- 3-30) Continue moving all values toward their night values in 1/30th increments. Again, use a calculator.
- d) If TOD is 4 (Night)...
-- 1) If TODC is 30, Set Screen Tone 40, 40, 70, 50
-- 2) If TODC is 29, Set Screen Tone 41, 41, 71, 52
-- 3-30) Continue moving all values toward their morning values in 1/30th increments. Like before, use a calculator.
}

2) If LightingWait is ON, wait 0.5 seconds.

Step 6 - Avoid Glitches (Some Things to Remember)

This section is just some points to keep in mind to keep your system from glitching.

1) Remember to turn off TimerEnable whenever you're doing something special in an area where the switch is normally on and LightLevel is 1 (outdoors). If you leave it on, the day/night system will interfere with your own Set Screen Tone events.

2) You can use the Show Screen and Erase Screen commands when teleporting, but if the two maps don't have identical non-outdoor Light Levels, you may see a momentary glitch.

And.. that's it. I'm not very good with conclusions, so I guess this'll have to do :P. Till next time!