Charas-Project

Game Creation => Requests => RPG Maker Programming => Topic started by: evmaster on August 13, 2012, 09:11:19 PM

Title: Day n Night and Timer Operations
Post by: evmaster on August 13, 2012, 09:11:19 PM
Hello. Can I have some help on a Day and Night System? I am trying to work with the Timer Operations too. But I can't seem to get the timer to start. I would also like some NPC to appear at different areas at different times of the day. Thanks.
Title: Re: Day n Night and Timer Operations
Post by: Natako on August 13, 2012, 11:03:56 PM
Out of curiosity, which RPG Maker are you using? I had a fully functional day and night system in a mission-based game I was working on in VX (including proper screen tinting for various times throughout the day) but it's been a while and I know that some things don't work universally in all RPG Makers even when you'd expect them to.

Unfortunately, that game was on my other laptop and I'd have to write the whole thing up again from scratch, but I'd like to make sure it works before I post anything.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 14, 2012, 12:20:22 AM
I have Rpg maker 2003.
Title: Re: Day n Night and Timer Operations
Post by: Natako on August 14, 2012, 02:07:37 AM
Okay, not going to have too much time to work on it tonight and I have work in the morning, but I'll try to put one together in 2003. Shouldn't be much different than VX, but I'll let you know how I made out.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 14, 2012, 02:16:31 AM
Alright. I look forward to it. Thanks!
Title: Re: Day n Night and Timer Operations
Post by: Natako on August 14, 2012, 02:47:33 AM
How long do you want the in-game days to last? Also, do you want any sort of clock option? (In other words, you would be able to inspect X object and find out what time of the day it is)

There are two ways that I can think of to go about doing this and depending on what type of system you want specifically, one might work better than the other.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 14, 2012, 02:54:26 AM
Hmm... I would like it to tell me what time it is. I just wanted it to turn night and day kinda like Harvest moon.
Title: Re: Day n Night and Timer Operations
Post by: Prpl_Mage on August 14, 2012, 06:50:22 AM
First off. Don't use the timer. It's pretty worthless. Good for countdowns though. When you want it to appear on screen and such.

Too make it easier to explain we're gonna go with actual time with your days. You merely need to change some conditional branches to tweak it.

The idea is simple like this. Every second 1 is added to a variable that represents seconds.
Everytime the variable seconds reaches 60 it adds 1 to the variable minutes and sets seconds to 0.
Everytime the variable minutes reaches 60 it adds 1 to hours and sets minutes to 0.
When hours reaches 25 you set it to 1.

In your events (and a common event) you check if the hour is greater or lower than a specific time. For example:
3-6 Dawn
6-10 Morning
10-14 Day
14-18 Afternoon
18- 21 Evening
21-3 Night

OR much more simple:
Day: 5-19
Night 19-5


So you check if the variable hour is greater than or lower than what hour the clock should be.
Wait why even bother that. Let's make it even more easy.

In the common event that counts the time. Make it so that when hour passes the hours you've decided on it turns on a switch that represents if it's night or day.
So when hour passes let's say 19 it turns on the switch night and off the switch day. Tint the screen a bit dark blue and maybe hide the screen during the transition.
And the switch (Night / day) are the ones you'll use for preconditions or conditions in events. No point in making everything time based like Majoras mask.

Oh right then. Explaination went pretty good. Hope you got an idea what you're gonna do 'cuz here it comes:

--------------------------=================================--------------

First off we want to create a common event.
Create three variables for seconds, minutes and hours. Then two switches for day and night.
Make the common event a paralell event (so it always runs) and name it "clock" or "father time" or whatever catchy name you can come up with.
Let's go to the commands then. It's gonna look a lot like this:

Wait 1.0 seconds
VAR Sec, +1
IF VAR Sec >= 60
¤VAR Min, +1
¤VAR sec, = 0
  ELSE
  IF VAR Min >= 60
  ¤VAR Hour, +1
  ¤VAR Min, = 0
    ELSE
    IF Hour >= 19
      IF Day is ON
      ¤ Hide screen
      ¤ Play sound (like the inn sound)
      ¤ Tint screen (dark blue for that nighty feeling)
      ¤ Switch day: OFF
      ¤ Switch night: ON
      ¤ Show screen
      ELSE
      IF Hour >= 5
        IF Night is ON
        ¤ Hide screen
        ¤ Play sound (like the chicken sound)
        ¤ Tint screen (normal tint)
        ¤ Switch day: ON
        ¤ Switch night: OFF
        ¤ Show screen
        ELSE
        IF Hour = 25
         ¤ VAR hour, = 1
The end

-------------------------------------------

So yeah. That's the basic idea that should do the trick. If you want to check the time make the clock (or whatever) show the message: "/v[X] : /v[Y]" Where X is the variable Hour and Y is the variable Minutes. It will show it like a 24 hour clock but that's always been the best way to show time so.
If you want shorter hours (you should) simply change those first parts when Minutes and seconds is added. For example make it add +10 to sec every seconds and each minute will only last 6 seconds instead of 60. Which would cut down the time an hour takes from 3600 seconds to 360.
You could also require less than 60 of a minute to add to the hours. It's all up to you really.
Oh yeah.l If you want to count the days. Throw in a variable for days and make it add 1 each time the hours go from 25 to 1.

Good luck.
Title: Re: Day n Night and Timer Operations
Post by: Natako on August 14, 2012, 04:25:02 PM
Well, thanks Prpl. I was actually going to do this once I got home from work but now I guess I'll have to sit on my rear all afternoon and find some other way to waste time. :P And I was actually going to be helpful for once!

Prpl probably did a better job explaining than I would, though, so yeah.
Title: Re: Day n Night and Timer Operations
Post by: Meiscool on August 14, 2012, 04:57:38 PM
Typically in games 1 rl second = .5 - 1 ig minute. That means 1 day in a game is 24/48 minutes worth of gameplay. I find that to be a good length of time.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 14, 2012, 06:06:55 PM
It's not working for me. I am sure I am doing something wrong.
(http://img193.imageshack.us/img193/2966/dayandnightimage.png)
Title: Re: Day n Night and Timer Operations
Post by: Meiscool on August 14, 2012, 06:31:19 PM
That looks fine.
Though, personally, I would do Show screen (Fade)-> Tint with a 0.0 wait rather than hide, sfx, tint, show.

Using the show screen option while the screen is already show adds a nice "slow down" effect to the game due to the natural programming. Try it out.

EDIT: you may have to put the tint before the show screen. I honestly can't remember the correct order.
Title: Re: Day n Night and Timer Operations
Post by: drenrin2120 on August 14, 2012, 06:54:39 PM
Here, I suggest downloading rpgmaker 2009 ultimate. It'll provide an option to enlarge the eventing space window.

Also, is the problem that the day/night only works on one map? You should probably make this a common event and toggle it on/off with a switch.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 14, 2012, 07:05:29 PM
It's not working at all. Unless, there is a long wait that I haven't stick around long enough to see any changes.
Title: Re: Day n Night and Timer Operations
Post by: Meiscool on August 14, 2012, 07:08:15 PM
Yes... you have it set to change every 10+ hours, so you have a long wait. That is why I suggested to change it to a lower amount of time, such that one minute = one hour in the game.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 14, 2012, 07:17:02 PM
Where should I make the change?
Title: Re: Day n Night and Timer Operations
Post by: Natako on August 14, 2012, 07:45:33 PM
Okay, my following post is going to be confusing. I'm much better at explaining concepts like this with screenshots or lines of "code" than in words.

The way you have it set up now, it's working like real time. In other words, one in-game hour = one IRL hour. What you need to do is cut down on the amount of time it takes for one in-game hour to pass.

When I was working on this last night, I had a similar setup to Prpl's but I only used two variables, one for hours and one for minutes. Each passing second would add +1 to the minute variable, so in other words, a minute IRL would be equivalent to an in-game hour with an entire day comprising of 24 minutes in-game.

The length of an in-game second is determined by that "Wait 1.0 sec" command at the very beginning of the chain as this affects the time delay between each increase of the "Seconds" variable. The minimum value that RPG maker will allow you to enter for that command is 0.1 seconds, so if you were to change that value to its absolute minimum, an in-game minute would be 6 seconds, an in-game hour would be 6 minutes, and a day would be 2 hours and 24 minutes. That's a bit long for a single in-game day, so then again I wouldn't recommend this method unless you really want to have days that are 2 and a half hours long.

I recommend using just two variables - one for hours and one for minutes - instead unless you really want a longer day in your game. Set the Wait command to however much time you want an in-game minute to take (e.g. one second) and have the hours variable increase by one when minutes = 60.

I'll go over Prpl's event code in a bit and see if I can explain a bit more clearly what I'm trying to say. Yeah, I'm bad at explaining things like this lol.
Title: Re: Day n Night and Timer Operations
Post by: Meiscool on August 14, 2012, 07:49:27 PM
Take out the seconds I guess... at this point it is kinda of up to personal preference, ya know?

EDIT: Actually, you could change the wait at the top to 0.0 and that might correct the problem.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 14, 2012, 08:07:51 PM
o_o

I just want a short day and night thingy. Kinda like the Harvest Moon one. And have some Npcs be at different places throughout the day.
Title: Re: Day n Night and Timer Operations
Post by: Natako on August 14, 2012, 08:52:03 PM
It's copypasta edit time! Yay!

Taking Prpl's formula, you want to edit it down so it only contains two variables: one for Minutes and one for Hours.

==========

Wait 1.0 seconds
VAR Minutes, +1
IF VAR Minutes >= 60
¤VAR Hours, +1
¤VAR Minutes, = 0
    ELSE
    IF Hours >= 19
      IF Day is ON
      ¤ Hide screen
      ¤ Play sound (like the inn sound)
      ¤ Tint screen (dark blue for that nighty feeling)
      ¤ Switch day: OFF
      ¤ Switch night: ON
      ¤ Show screen
      ELSE
      IF Hours >= 5
        IF Night is ON
        ¤ Hide screen
        ¤ Play sound (like the chicken sound)
        ¤ Tint screen (normal tint)
        ¤ Switch day: ON
        ¤ Switch night: OFF
        ¤ Show screen
        ELSE
        IF Hours = 25
         ¤ VAR hours, = 1
The end

=========
If you edit it down to something like this, it should work and the days would be 24 minutes as opposed to real time.

If you don't like that amount of time for a day, change the Wait 1.0 Seconds to a lower or higher number depending on how long you want the day to be. This amount reflects how long it takes for each in-game minute to pass.

By the way, this is copy-pasted and I tend to miss obvious things when I do that, so feel free to correct me if I overlooked something in Prpl's programming.

As for the NPC's, I'll update with a screenshot showing how to do this since I'm better at explaining with pictures than text.

======

Update: NPC's

Method 1

Here's one method of making NPC's appear at certain times. RPG Maker 2003 only allows you to use one variable as an event precondition, so you wouldn't be able to make an NPC show up at odd times this way (E.g. 7:30, 7:45)...but let's say you wanted an NPC to show up at 7PM and disappear at 5AM. You would want to set your pages up like this.

The first page accounts for 5AM until 7, when the NPC is invisible. The second page accounts for 7-midnight, and the third page accounts for midnight - 5AM.

[spoiler](http://img.photobucket.com/albums/v695/Angelwrath/daynight.png)[/spoiler]

[spoiler](http://img.photobucket.com/albums/v695/Angelwrath/daynight2.png)[/spoiler]

[spoiler](http://img.photobucket.com/albums/v695/Angelwrath/daynight3.png)[/spoiler]

Of course, depending on your ranges of time, you would have to modify the preconditions. I think this will only work if the transparent NPC is on the first page. I tested with the above pages and it worked perfectly.

Method 2

As for times which aren't right on the hour, I would recommend using switches to make the NPC's appear. You would have to use conditional branches to make the switches turn on and off when hours and minutes reached the proper amounts. You can do this by setting things up the following way:

Let's say we want a certain NPC to show up at 10:30AM and disappear at 3:03PM.

Create a parallel process event for the NPC to show up. Set up like so:

[spoiler](http://img.photobucket.com/albums/v695/Angelwrath/daynight4.png)[/spoiler]

Now we must create a second event for the NPC in question with two pages. The first page should be a blank sprite, and the second page should contain the NPC sprite and the switch as a precondition.

[spoiler](http://img.photobucket.com/albums/v695/Angelwrath/daynight5.png)[/spoiler]
[spoiler](http://img.photobucket.com/albums/v695/Angelwrath/daynight6.png)[/spoiler]

And there you have it. This method is easier than the first, but the problem with it is that you'll have a million events and switches cluttering your game (personal pet peeve of mine, I try to minimize on these things). If that doesn't bother you, go ahead and do this instead because it's probably easier to figure out than the other method I showed you.

And there you have it.
Title: Re: Day n Night and Timer Operations
Post by: Prpl_Mage on August 14, 2012, 10:12:54 PM
Sorry Nat, got one of those laying around and figured it could save you the trouble. Without doubt you seem to have it under control.

Common events (found in the database) works across all maps at all time, useful for stuff that's global.
And Eve, The example was made using real time. So unless you want it to be really slow(like watching grass grow) either remove the part with seconds so that 1 second equals 1 ingame minute. and therefore 1 minuter equals 1 in game hour.
Just like Nat here showed you. I'll let her finish though. See if there's anything left to add then.

Also, to check if stuff is working. Press F9 during test play to check the values of variables and state of switches. Just to see if variables actually get values and such.
Title: Re: Day n Night and Timer Operations
Post by: Natako on August 14, 2012, 11:42:50 PM
Sorry Nat, got one of those laying around and figured it could save you the trouble.

Was just joking with you, hehe.

Anyway, EV, I updated my "tutorial" of sorts with some screenshots now. If you change your parallel process event for the time to my modified version of purple's, it should prove much more to your liking. As for the NPC's, I listed two methods above: one would only allow you to have NPC's appear/disappear right on the hour but would eliminate a lot of events/switches/clutter from your game, but the second method is much simpler to use and you can have your NPC's appear at any time during the day you wish, although you'll have to make an event and a switch for each NPC in this fashion. Take a look and see what works for you.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 15, 2012, 01:11:20 AM
Well, I made the wait shorter. I waited it out and the event started to go to night, but then it goes to day and loops again and again. I think
I did something wrong.

You guys have been a great help. :bend:
Title: Re: Day n Night and Timer Operations
Post by: Prpl_Mage on August 15, 2012, 07:39:07 AM
Did you remember the switches? In conditional branch and such?

Does it go night and directly back to day or is the problem when it finally turns to day?
PS you can change values of variables in the F9 interface if you want to speed things up even more.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 15, 2012, 02:52:59 PM
"Does it go night and directly back to day?"

This.

Thank you for telling me about F9.
Title: Re: Day n Night and Timer Operations
Post by: Prpl_Mage on August 15, 2012, 07:59:38 PM
Okay might be a stupid question. But does both the day and the night switch start as ON? It might be causing this.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 15, 2012, 10:56:02 PM
I redid the whole event from scratch. Now it turns to night, stays night but the screen keeps being hidden and shown again and again.
You were right about the switch thing.

(http://img17.imageshack.us/img17/6955/eventid.png)
Title: Re: Day n Night and Timer Operations
Post by: Natako on August 16, 2012, 12:06:56 AM
Okay, I see why it's doing that. Because it's currently set up so that it hides the screen, tints it, and shows it again when hours >= 19, it continues to do this as there's nothing to keep the operation from carrying itself out.

There are two things that you can do.

You take out the hide/show effect so that the screen does not hide itself when the screen changes tint (in other words, you'll see the screen fade from daytime to nighttime lighting without any black screens in between). That's an easy solution, but I'm not sure that this is what you want your transition to look like.

Another thing that you can do involves multiple pages. What you'll need to do is set up a second page for when the NIGHT switch is on so that the fade out/fade in effect will stop after its first occurrence. Let me go ahead and try to make this up in RPG Maker for you and I'll post a screenshot.

Edit: Okay, here you go. This will show you how to set up your screens for either method.

Erasing Show/Hide Screen:

You'll also need to take out your sound effects. Otherwise, they would continue to play after the screen changed. If you use this method, you could select a different BGM for night and day and have the music fade out and in between each transition for greatest effect.

[spoiler](http://img.photobucket.com/albums/v695/Angelwrath/nighttime1.png)[/spoiler]

Keeping Show/Hide Screen:

You'll have to put your events in two pages. It's not necessary to use the DAY switch in this operation as the event will function without it. However, the NIGHT switch is necessary to activate the second page of the event.

[spoiler](http://img.photobucket.com/albums/v695/Angelwrath/nighttime2.png)[/spoiler]
[spoiler](http://img.photobucket.com/albums/v695/Angelwrath/nighttime4.png)[/spoiler]

I tested both of these in RPG Maker and both work. Use whichever you prefer.

Please note that with the last method, Show screen has to be placed BEFORE turning on the NIGHT switch as otherwise it will switch to the second page before the screen fades in and you'll be stuck looking at a blank screen.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 22, 2012, 06:12:36 PM
I did the first method and took out the hide screen and such. Now my character lags while walking, almost as if there is a 1 sec wait.
Title: Re: Day n Night and Timer Operations
Post by: Natako on August 22, 2012, 06:19:25 PM
Not sure if this is what's causing it, but do you have it set to wait while the screen changes color? You can uncheck the checkbox and that way it won't wait for the screen to change. Seems a bit strange, though...if it's a parallel process, it shouldn't affect the character. Can you post a screenshot of the event code?
Title: Re: Day n Night and Timer Operations
Post by: greenraven on August 22, 2012, 06:24:45 PM
Ok, here's a question. Why do you need a night and day system? Because there are simpler ways of going about coding it depending on your wants and needs.

(Unrelated FYI: It's much simpler to do pretty much everything with RMXP. There's a default "total time played" timer which has it's obvious uses and local switches are just such a freaking convenience. I know a lot of people have a sweet spot for 2K/3 but switching over to XP is really the way to go if you want less headaches. Also XP games can run without forcing people to install RTP, awesomeness all around.)

As for the 1 second wait, it might be a "wait for event" priority sensor.
Title: Re: Day n Night and Timer Operations
Post by: evmaster on August 23, 2012, 08:15:10 PM
I don't need a Day n Night system. I just wanted one. I am playing around in RPG maker. I didn't realize that RPG maker 2003 was so limited.
Title: Re: Day n Night and Timer Operations
Post by: greenraven on August 23, 2012, 10:44:56 PM
Perma-day is a perfectly acceptable form of game logic. While it's nice to have, it's too much of a hassle in 2K/3 (might even slow your game down).
Title: Re: Day n Night and Timer Operations
Post by: Prpl_Mage on August 24, 2012, 06:32:13 PM
2003 isn't exactly limited. Xp got a lot of things done for you and you can simply use scripts in that one. Makes things easier.

One easy way to make a day and night system that isn't dependable on actual time is having two switches, for day and night.
When sleeping in an Inn you simply turn one off and the other on. Tint the screen accordingly and make those switches preconditions for NPC,s and doors.