RMVX Day/Night System

0 Members and 1 Guest are viewing this topic.

****
I saw a squirrel...
Rep:
Level 81
...it got in my way.
Day/Night Evented System

Ok, this is a fairly simple, but very effective system. It only requires two variables and two switches, unless you decide to add days, weeks, years, or AM/PM. Right now, it runs on a 24 hour system, so 1:00PM is 13:00. It can be done entirely in the common event page of the database. What's more, I'll include another event system under this one (same page) that can play music for day and night in individual places.

So let's get to it! I'll go through it in steps.

1. Go to the common event page under the database and make a new common event called "Clock," or "Time," or whatever you wanna name it. For the purpose of this tutorial, we'll call it "Clock." Make the trigger a parallel process, run by a switch, which we'll call "TIME."

2. Start a loop. This loop will never break. Ever.

3. Make a conditional branch. This is where your first variable comes in. Make the conditional branch state that if Hours is less than 6, it'll do... the next step.
Your code should look like this...

Spoiler for:
@>Loop
    @>Conditional Branch: Variable [0001:Hours] < 6
        @>
    :   Else
        @>
    :   Branch End
:   Repeat Above

4. Inside this statement, control a switch called Night to the ON position. Then tint the screen to RGB: -128, -96, -64, and a grey of 128, making it take 600 frames, and do NOT wait for completion.

5. Copy and paste this entire branch into the else statement of the branch. Change the parameters of the branch to hours > 20. It should look like this...

Spoiler for:
@>Loop
    @>Conditional Branch: Variable [0001:Hours] < 6
        @>Control Switches: [0001:Night] = ON
        @>Tint Screen: (-128,-96,-64,128), @600
        @>
    :   Else
        @>Conditional Branch: Variable [0001:Hours] > 20
        @>Control Switches: [0001:Night] = ON
        @>Tint Screen: (-128,-96,-64,128), @600
        @>
        :   Else
            @>
        :   Branch End
        @>
    :   Branch End
:   Repeat Above

6. In the else statement of THAT branch, control the switch Night to be OFF, then tint the screen back to normal, with the frame time at 600, and do not wait for completion.

Spoiler for:
@>Loop
    @>Conditional Branch: Variable [0001:Hours] < 6
        @>Control Switches: [0001:Night] = ON
        @>Tint Screen: (-128,-96,-64,128), @600
        @>
    :   Else
        @>Conditional Branch: Variable [0001:Hours] > 20
        @>Control Switches: [0001:Night] = ON
        @>Tint Screen: (-128,-96,-64,128), @600
        @>
        :   Else
            @>Control Switches: [0001:Night] = OFF
            @>Tint Screen: (0,0,0,0), @600
            @>
        :   Branch End
        @>
    :   Branch End
:   Repeat Above

I won't copy and paste the whole code now, but everything must now be written after what you have already written.

7. So, after everything except for the loop end, you want to write the code to move time forward. To start, wait 60 frames. That's one second. Then change a variable named "Minutes" to +=1. It should look like this...

Spoiler for:
    @>Wait: 60 frame(s)
    @>Control Variables: [0002:Minutes] += 1
    @>
:   Repeat Above

8. Now that you have that, create a conditional branch that checks if the minutes are equal to 60. Don't bother setting handling when conditions don't apply. In this, set the minutes to 0, and the hours to += 1. It'll look like this...

Spoiler for:
    @>Wait: 60 frame(s)
    @>Control Variables: [0002:Minutes] += 1
    @>Conditional Branch: Variable [0002:Minutes] == 60
        @>Control Variables: [0002:Minutes] = 0
        @>Control Variables: [0001:Hours] += 1
        @>
    :   Branch End
:   Repeat Above

9. Now, copy and paste that branch under itself. Change the parameters so that it checks if hours are equal to 24. Erase the change in the minutes, then make it so that the hours are set to 0, rather than += 1.

10. You're done! That's it! Set the variables "Minutes" and "Hours" to whatever you want in a separate event, and you have your day/night system! If you ever want to turn off the clock for a specific event, you can do that by turning off the "TIME" switch we made at the start. Just to be specific, I'll post the code below to show you what it looks like, then I'll resume the tutorial with a few new quirks and tricks.

Spoiler for:
@>Loop
    @>Conditional Branch: Variable [0001:Hours] < 6
        @>Control Switches: [0001:Night] = ON
        @>Tint Screen: (-128,-96,-64,128), @600
        @>
    :   Else
        @>Conditional Branch: Variable [0001:Hours] > 20
        @>Control Switches: [0001:Night] = ON
        @>Tint Screen: (-128,-96,-64,128), @600
        @>
        :   Else
            @>Control Switches: [0001:Night] = OFF
            @>Tint Screen: (0,0,0,0), @600
            @>
        :   Branch End
        @>
    :   Branch End
    @>Wait: 60 frame(s)
    @>Control Variables: [0002:Minutes] += 1
    @>Conditional Branch: Variable [0002:Minutes] == 60
        @>Control Variables: [0002:Minutes] = 0
        @>Control Variables: [0001:Hours] += 1
        @>
    :   Branch End
    @>Conditional Branch: Variable [0002:Hours] == 24
        @>Control Variables: [0001:Hours] = 0
        @>
    :   Branch End
:   Repeat Above

So, there are a few things that you can do with this system to make it even better. I'll provide a list of them and how to make them all work really well.

1. The Inn
This is really easy. Basically, whenever you visit an Inn or sleep, it'll change the time from day to night, or night to day. How do you do this? Just add a bit of code to your sleep events. Here's what a basic Inn should look like with this system...

Spoiler for:
@>Text: -, -, Normal, Bottom
 :        : 1000 Gold for one night. Would you like to stay?\G
@>Show Choices:, Yes, No
 :  When [Yes]
    @>Conditional Branch: Gold 1000 or more
        @>Change Gold: -1000
        @>Fadeout Screen
        @>Play ME: 'Inn', 100, 100
        @>Conditional Branch: Switch [0001:Night] == ON
            @>Control Switches: [0001:Night] = OFF
            @>Control Variables: [0001:Hours] = 8
        :   Else
            @>Control Switches: [0001:Night] = ON
            @>Control Variables: [0001:Hours] = 20
            @>
        :   Branch End
        @>Wait: 300 frame(s)
        @>Recover All: Entire Party
        @>Fadein Screen
        @>
    :   Else
        @>Text: -, -, Normal, Bottom
        :         : You don't have enough money.
        @>
    :   Branch End
    @>
 :  When [No]
    @>
 :  Branch End
@>

2. Day/Night Music
This is a really neat effect you can do with whatever maps you want. It basically changes the music of a certain area depending on what time it is. The best way to do this is to place the event in each map, with whatever music you want in each place. This only works well if the default map BGM is set to nothing, and if done in a parallel process. Here's a very basic way to do this.

Spoiler for:
@>Conditional Branch: Variable [0001:Hours] < 6
    @>Play BGM: 'Town Night', 100, 100
    @>
 :  Else
    @>Conditional Branch: Variable [0001:Hours] >= 20
        @>Play BGM: 'Town Night', 100, 100
     :  Else
        @>Play BGM: 'Town Day', 100, 100
        @>
     :  Branch End
    @>
 :  Branch End
@>

3. The Pocket Watch
Just as it says. An item accessible through your inventory or main menu that tells you the time. Just bond an item to a common event called "Pocket Watch." Then put this code in that event.

Spoiler for:
@>Conditional Branch: Variable [0002:Minutes] < 10
    @>Conditional Branch: Variable [0001:Hours] < 10
        @>Text: -, -, Dark, Bottom
         :         :Time: 0\v[1]:0\v[2]
        @>
     :  Else
        @>Text: -, -, Dark, Bottom
         :         :Time: \v[1]:0\v[2]
        @>
     :  Branch End
    @>
 :  Else
    @>Conditional Branch: Variable [0001:Hours] < 10
        @>Text: -, -, Dark, Bottom
         :         :Time: 0\v[1]:\v[2]
        @>
     :  Else
        @>Text: -, -, Dark, Bottom
         :         :Time: \v[1]:\v[2]
        @>
     :  Branch End
    @>

4. We're Closed
You know how stores and houses are always open at all times of the day? Well guess what? Not any more. You can make any door lock itself at night with one extra page per event. You can even make certain people say different things, or make certain events happen at certain times. However, keeping with the interest of time, I'll just use the locked door code here.

Well, there isn't any code, but there is a trick.

Just add an event page at the very end of all the other pages for doors or people. The conditional switch should be (of course) Night. Now make a text that says, "We're closed for the night" or something like that. For people, you can make them say something different at night. If you really wanna be specific, you can make the condition a variable, so they say something at a certain time, but that's... well, not a whole lot more difficult, to be honest.


Well! That's everything! I hope someone gets use out of this, it works really well so far. If anyone finds any bugs, let me know.

Here's a demo.
http://www.megaupload.com/?d=XHD3ME7D

I'd really appreciate credit for this one. This had the most work put into it.
« Last Edit: June 10, 2011, 12:00:50 AM by Strak »

Gods ain't gonna help ya son...

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Zero to Hero2014 Best IRC Quote2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
Very nice work Strak, and very well explained. There are tonnes of cool things you can do with a simple time system like this.

****
I saw a squirrel...
Rep:
Level 81
...it got in my way.
Wait... did I just put this under resources?
 :facepalm:

Can someone move this to event systems please?

It was late when I did this...

EDIT: Thanks.
« Last Edit: June 09, 2011, 11:46:03 PM by Strak »

Gods ain't gonna help ya son...

**
Rep: +0/-0Level 66
RMRK Junior
Thanks a lot it helped me create a very cool event, how ever... it won't change back to daytime and I've gone over the script a dozen times and i cant fins out what i missed, please help...

****
I saw a squirrel...
Rep:
Level 81
...it got in my way.
Take a screenshot of both the time system and the event you made, then I'll run through them. I'll try to see what's wrong.

Gods ain't gonna help ya son...

**
Rep: +0/-0Level 66
RMRK Junior
I downloaded your demo, and it doesnt automatically change back either... or maybe im to impatient but ill load them in a min

****
I saw a squirrel...
Rep:
Level 81
...it got in my way.
There seems to be nothing wrong with your event, so there must be another event that counteracts this one. Are there any other events you use that directly relate to this one? If so, take screenshots of them and show them to me.

Gods ain't gonna help ya son...

**
Rep: +0/-0Level 66
RMRK Junior
there isnt, but i do have the time switch activated in another event, could that be it? I also as said above downloaded you demo, but the time doesnt change automatically either...

****
I saw a squirrel...
Rep:
Level 81
...it got in my way.
It should. Try taking out the other event that uses the time switch. Or at least change the switch. See what happens. The entire event is run on that one switch, so you can't mess with it too much.

Actually, now that I think about it, are you turning the switch on at all?

Also, keep in mind that any scripts that use those switch ID's may mess with the event. Make sure the Switches are used for the time system only.

Gods ain't gonna help ya son...

**
Rep: +0/-0Level 66
RMRK Junior
Would it work if i made it like this:

loop
Control switch: Time(on)
conditional branch: Time (on)
conditional branch: Night(on)
Control Switches: Night(off)
Tint screen
else
Control switches: Night (on)
Tint screen
Else

****
I saw a squirrel...
Rep:
Level 81
...it got in my way.
Er... I don't know. Try it out. I doubt it, but maybe. How about this? Create an exe file of your game, and send it to me, either through here or PM. I'll go through the time system and see if I can figure out what's wrong.

Gods ain't gonna help ya son...

**
Rep: +0/-0Level 66
RMRK Junior
its compressing right now, test my game out if ya wanna, it'll be pretty good

**
Rep: +0/-0Level 66
RMRK Junior
It said it couldnt compress so ima gonna try it again

****
I saw a squirrel...
Rep:
Level 81
...it got in my way.
Not really worth the double post there, you could have just edited the first one.

Gods ain't gonna help ya son...

*
RMRK's dad
Rep:
Level 86
You know, I think its all gonna be okay.
For going the distance for a balanced breakfast.Project of the Month winner for June 2009For being a noted contributor to the RMRK Wiki2013 Best WriterSilver Writing ReviewerSecret Santa 2013 Participant
Kewl beans. Going in the game-o.
:tinysmile: