Customizable Clock and Time (Day/Night cycle)

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by Heirukichi, Jul 11, 2018.

  1. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,040
    Likes Received:
    381
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Night/Day System - VX Ace Clock - v. 1.0.5
    by Heirukichi​

    Description
    This script adds a Day/Night cycle and in-game time to your VX Ace game. In addition to that it adds a customizable "clock" to your game. The so called clock is no real clock, it is more like an image used to display night and day cycle so it does not work as a clock but has a cycle of 24 hours instead. You can decide if your Night/Day cycle has an effect on your game screen. If that is your case your screen tone will automatically change whenever your day phase changes (dawn, day, dusk, night).

    Features
    • In-game time.
    • Tone change according to phases of the day.
    • Customizable "clock".
    • New $game_clock variable with various methods.
    • Default script configuration for easy plug and play.
    • Highly customizable.
    • A lot of freedom.

    Screenshots
    Heirukichi_NightDaySystem-VXAce.png

    Terms of Use
    This script is under the GNU General Public License v3.0. This means that:
    • You are free to use this script in both commercial and non-commercial games as long as you give proper credits to me (Heirukichi) and provide a link to this page;
    • You are free to modify this script as long as you do not pretend you wrote this and you distribute it under the same license as the original.
    You can review the full license here: https://www.gnu.org/licenses/gpl-3.0.html

    In addition I’d like to keep track of games where my scripts are used so, even if this is not mandatory, I’d like you to inform me and send me a link when a game including my script is published. As I said this is not mandatory but it really helps me and it is much appreciated.

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

    IMPORTANT NOTICE:
    If you want to post this script somewhere else please provide a link to my website instead.

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

    All the images included in the demo project are licensed under the CC 4.0 BY-SA. This means that:
    • you are free to use them in both commercial and non commercial games as long as proper credit is given to me (Heirukichi);
    • You are free to modify them as long as you do not pretend you created the original one and you distribute the modified copy under the same license as the original.
    You can review the full license here: https://creativecommons.org/licenses/by-sa/4.0/


    Instructions
    To install the script copy/paste it below Materials. If any of the scripts you are using overwrites any of the aliased methods be sure to place this script below it. By default your Clock folder path is Graphics/Clock so be sure to have something there or to change the default path in the script configuration module to be your clock path.

    Detailed instructions can be found inside the script. Be sure to follow them if you want to use this script at its full potential.

    Difficulty: Easy/Medium. Using this script is easy if you stick with the basics. Since this script gives you a lot of freedom you can use it to achieve more complex things. If you want to do that the difficulty increases.

    Script Link
    A download link to this script can be found here.

    Demo
    To give you a better understanding of how the script works I created a little demo. The demo uses a debug flag to speed up time so that you can see how time progresses fast enough to not be bored of it.

    I created two different versions of the demo: one using the default RPG Maker VX Ace packing (the bluecube.exe), another using a 7zip archive. This is because sometimes the bluecube.exe creates troubles so if that is your case feel free to download the 7zip version and use it.

    NOTE: both downloads contain the same demo. If one of them works for you do not download the other one.

    WARNING: The demo serves the sole purpose of showing how the script works in a project and where to place the clock images. This is not being updated and it still uses an old version of the script. To use the current version of the script, please download it from the link above.

    Credits

    Credits for the demo go to:
    • Enterbrain Inc. (Engine, RTP)
    • Heirukichi (this script, clock images)

    Author notes

    If you find a bug feel free to report it and I'll try to fix it as soon as possible. In addition if there is any kind-hearted guy who think my default clock image is too ugly and wants to create a new one feel free to do it. I am not that much of a pixel artist.


    Update Log

    06-26-2019 Version 1.0.5
    - Terms of Use have been updated and the software is now distributed under the GNU General Public License v3.0. This does not change what you can do with this script, it only changes how you should credit me. A link to this page has to be included when you credit me for this script. Everything else remains unchanged (you can still use this script for free, you can still use it for commercial purposes and you can still modify it, as long as you do not pretend you wrote the whole script).

    05-02-2019 Version 1.0.4
    - $game_clock.set_time now has an internal check to convert numbers into the 0-47 range. It is now possible to add extra phases to the current time using set_time, without having to worry about the new value being less than 47.
    - Fixed a but that prevented the screen tint from being updated after setting a new time.

    04-27-2019 Version 1.0.3
    - Fixed a bug that caused screen tint to be applied regardless of TINT_ON_CHANGES value.

    03-13-2019 Version 1.0.2
    - It is now possible to prevent your clock from updating when $game_player is not moving.

    02-04-2019 Version 1.0.1
    - Modified instructions. The correct usage of the DEBUG module is now correctly explained in the instructions. Few typos in instructions have been corrected.
     
    Last edited: Jun 26, 2019
    #1
    Tw0Face and Tetsune like this.
  2. tmrzrm

    tmrzrm The Dazzler Member

    Messages:
    2
    Likes Received:
    0
    Location:
    Fredericksburg VA
    First Language:
    English
    Primarily Uses:
    RMVXA
    This looks really nice and easy to use. Good work!
     
    #2
  3. AmieLK

    AmieLK Tired Veteran

    Messages:
    75
    Likes Received:
    314
    Location:
    don't worry about it.
    First Language:
    English
    Primarily Uses:
    RMMV
    @Heirukichi : Hi, howdy! Vlue's Advanced Game time keeps lagging and I'm trying to implement yours, but it seems to be speeding through cycles. Like in theory it's supposed to take a full 2 hours of real time to cycle from day to night, right? It takes about 2 min instead.

    Also, regarding the tint change, is there a way I can make it so that the tint applies only once the player transfers to a new map? Like say it hits the nighttime phase, right? it wont flash orange and then go dark, but instead the second a player moves to a new screen, it's dark outside. Does that make sense?
     
    #3
  4. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,040
    Likes Received:
    381
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    @AmieLK if you are using the script from the demo (if I am not mistaken) the time is set to be much faster for the sake of testing. Just change the value of HOUR_FRAMES in the config module (you might need a calculator to adjust it to be what you want).

    The orange tint is not necessary. The config module has four parameters you can use to determine those tints. They are DAY, NIGHT, DUSK and DAWN. If you want to remove the orange transition just change DAWN and DUSK to be the same of DAY and NIGHT (or vice versa).

    If you want to change your map tint only when changing map that is indeed possible by editing the reserve_transfer method but if you do it that way then the clock will not be stopped and time will keep flowing. The player might experience something weird like being transfered to a map right before dawn (and so it is still dark) and playing the whole day while still being dark just because he/she did not transfer to a new map. If his/her staying in that map lasts too long it might event transfer when it is dark again thus skipping a whole day. Or it might lead to very short days/night just because transfers were not properly timed. You are aware of that, are you not?
     
    #4
  5. hhldegujia

    hhldegujia Villager Member

    Messages:
    6
    Likes Received:
    1
    First Language:
    chinese
    Primarily Uses:
    RMVXA
    the clock run so fast!
     
    #5
  6. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,040
    Likes Received:
    381
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    @hhldegujia that is most likely because you either set HOUR_FRAMES too low or left the debug flag set as true. Inside the DEBUG module you have a constant called ACTIVE. If that is set to true then HOUR_FRAMES is automatically set as 60 (1 hour each second).

    It is very useful to see if your clock is running properly while debugging and if everything related to time triggers when it is supposed to trigger. When you do not have to test those things you have to set that flat as false.
     
    #6
  7. Tw0Face

    Tw0Face Chief Executive Officer Veteran

    Messages:
    180
    Likes Received:
    253
    First Language:
    German
    Primarily Uses:
    RMVXA
    This script is a great idea. I just tested it and it works as it should. It's pretty nice how you did this without letting the FPS break down. Maybe someday I'll have an idea for a game where I can make good use of this. Random ideas: How about an option of the time only moving forward when the player moves? This would give us the choice to have it either real-time or "turn-based". To make the whole thing even more dynamic, you could also offer the feature to add SEs to the day change as well. For example, the sound of an owl when the night breaks and the chirping of birds when it becomes morning. How about that?

    Greetings,
    Tw0Face
     
    Last edited: Mar 7, 2019
    #7
    Heirukichi likes this.
  8. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,040
    Likes Received:
    381
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Those look like nice ideas actually. While it is possible to achieve the last one with just events (common event -> parallel process -> when the time is right play a sound) without leading to FPS drop - a single check when necessary does not decrease your FPS - the first one sounds like something that might be useful and easy to achieve. Of course it would only work if you are moving your character in the default Game_Map. If you have a script that triggers a new scene and simulates your game map that would completely destroy how the clock works.
     
    #8
    Tw0Face likes this.
  9. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,040
    Likes Received:
    381
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    @Tw0Face It is now possible to only update your clock when the player is actually moving. The option of having a sound when switching phases has not been implemented yet as it can be done with events. I am still thinking of adding it in the future but so far events are the way to go.
     
    #9
    Tw0Face likes this.
  10. Tw0Face

    Tw0Face Chief Executive Officer Veteran

    Messages:
    180
    Likes Received:
    253
    First Language:
    German
    Primarily Uses:
    RMVXA
    @Heirukichi: I tested it and it works perfectly fine for me. The new feature turns out to be as great as I thought it would be. Great work.
    Yes, it can be easily done by having Conditional Branches for $game_clock.hour24 and $game_clock.minutes for example. Of course, if you want to do the same trick while having UPDATE_WHEN_MOVING set to true, you're going to have a hard time because the SE repeats itself once per frame until the set time is over. But, yeah, maybe I'm just not able to see how it has to be set up in a proper way.

    Greetings,
    Tw0Face
     
    #10
  11. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,040
    Likes Received:
    381
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    @Tw0Face Simply check the current time. If it is not yet a phase to perform a color transition turn a switch on, if the switch is off AND it is a phase to perform color transitions play a sound according to the phase and turn the switch on..
    This way the sound effect is played only once. All you need is a conditional branch and a switch.

    No need to check hours and minutes. Phases are there for those kind of checks after all.
     
    Last edited: Mar 16, 2019
    #11
    Tw0Face likes this.
  12. Tw0Face

    Tw0Face Chief Executive Officer Veteran

    Messages:
    180
    Likes Received:
    253
    First Language:
    German
    Primarily Uses:
    RMVXA
    @Heirukichi: I'll try it as you said. Thanks a lot. :)

    Greetings,
    Tw0Face
     
    #12
  13. hhldegujia

    hhldegujia Villager Member

    Messages:
    6
    Likes Received:
    1
    First Language:
    chinese
    Primarily Uses:
    RMVXA
    Sorry!My fault....
     
    #13
  14. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,040
    Likes Received:
    381
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Not really. On the contrary your post helped me upgrading those instructions. Since two users had issues with that debug value I thought that it could no longer be considered a coincidence and I decided to add more detailed instructions on how that value influences your test. I should actually thank you for reporting this.
     
    #14
  15. KingHazeel

    KingHazeel Veteran Veteran

    Messages:
    117
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMVXA
    Hmmm...this is a good script. I'm tempted to use it. I'm just wondering if I can make it adopt all the features my events can, i.e. setting NPC schedules. Could probably create a common event that automatically changes a "Night" switch, whenever the conditional nighttime trigger is activated. I could also do this to slow down music or speed it up too.

    Might need to keep a common event that tracks a variable's hours based on the script so if I want to set an NPC to appear somewhere at a certain hour this would be possible. Is there a way change the time? I.e. the player rests at an inn and 8 hours pass?
     
    #15
  16. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,040
    Likes Received:
    381
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Yes, there is a way to do it. Here is what is written in the script instructions:
    Code:
    # Examples:
    #   $game_clock.set_time(45) <- This sets your time to be 22:30 (10:30 PM
    #   $game_clock.set_time(2)  <- This sets your time to be 01:00 (01:00 AM)
    You can change the current time using phases (each phase represents 30 minutes).
    So if the player rests you can use
    Code:
    $game_clock.set_time(16)
    in the inn event and the clock will be set at 8:00 AM after that.
     
    Last edited: Mar 16, 2019
    #16
  17. KingHazeel

    KingHazeel Veteran Veteran

    Messages:
    117
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMVXA
    I was thinking more "current time + 8 hours", but I think I can work with that. Thanks!
     
    #17
  18. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,040
    Likes Received:
    381
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    That works as well. The script itself is quite versatile and each attribute of $game_clock is accessible from outside without having to use specific methods to read instance variables. In your case you could use the following:
    Code:
    $game_clock.set_time(($game_clock.phase + 16) % 48)
    As long as you remember that each phase is 30 in-game minutes you can do anything you want with set_time.
     
    Last edited: May 2, 2019
    #18
  19. slickdeath97

    slickdeath97 Veteran Veteran

    Messages:
    34
    Likes Received:
    0
    First Language:
    english
    Primarily Uses:
    RMVXA
    Hey @Heirukichi, first off wanted to let you know that I love your script, it works perfect in my game. I wanted to ask if you might know how to add different weather effects with the clock, so when the player is at a specific point in the game or when the clock hits a specific time the weather changes. (example: when the clock hits 10 PM, it starts to rain or it becomes windy.)
     
    #19
  20. KingHazeel

    KingHazeel Veteran Veteran

    Messages:
    117
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMVXA
    It's been awhile, but couldn't you use the fire event as an example of how to trigger something--likely a parallel process--that would create your weather between certain times?
     
    #20

Share This Page