08-04-2015, 05:02 PM 
	
	
	Time
Version: 1.0
Version: 1.0
Introduction
This is just a simple time system. It adds and tracks years, months, days, hours and minutes--and you get to set that actual playtime which is accounts for each.
Features
- tracks time in a single global variable '$time'
 
- shaded maps which signify night
 
- 'indoor maps' where time has no effect on shade
 
- disable system with a switch
 
- name both weekdays and months
 
- set shading to reduce slowly though the day and night so that it becomes dark and light more fluidly as time passes
 
- adds a 'button callable' time window with switch enabling
 
- methods to form conditional branches from $time variable
 
Screenshots
![[Image: Y4sCCkQ.png]](http://i.imgur.com/Y4sCCkQ.png)
Script
 script
  			Code:
################################################################################
#                                TIME
#                            By: Ixfuru
#                              Version 1.0
#                          Created 12/24/14
################################################################################
#
# This is a pretty basic time system.  This does NOT track playtime, but rather
# creates a time system like that of the ElderScrolls games, where you are set in
# the fake time of an alternate reality universe, (and such:))  This script, though
# basic in its concept, has some really cool settings.  You are able to name
# the months, the weekdays and the seasons.  You are further able to set the 
# frames per minute, minutes per hour, etc.  Furthere still, you can set the 
# 'start time' of your game, down to the minute.  The system has a 'shade' feature, 
# which controls a graphic that is overlain over the map scene, which produces
# night and evening effects.  This feature is really cool, because you set the 
# opacity for each and every hour of the day.  This makes it so it won't just
# get bright or dark all of a sudden, but gradually, the way it should.
# This system comes with the ability to call a 'time window' from the map, 
# which you will align how you want.  You select the button to be pushed in order
# to hide/show the window.  Furthermore, you can set specific maps to ignore
# shading, (like interior maps that shouldn't be effected by the darkness. You 
# can also set maps that disallow you to call the time window.  (For cutscenes
# and what not.   Lastly, you can turn the entire system off with a switch that
# you specify!
#
# Make sure you place an image to use for the shade in your Graphics/Pictures
# folder.  A simple, 544x416 gray image will suffice, as the opacity is altered
# and can be changed to be completely transparent during daylight hours.
################################################################################
# This script was created by Ixfuru.  If you use this script, you MUST give 
# credit to him.  If you want to use the script commercially, contact him
# via Rpgarden.com.  Further, don't claim you created this script or post 
# elsewhere without his expressed permission!
################################################################################
#
#                         ***SCRIPT CALLS****
################################################################################
#
# This script allows you to make special script calls from the 3rd page of an
# event under the 'script' command, or from a common event respectively.  The 
# calls will allow the player to use minutes, hours, days, weekday, month, 
# year, season, all as comparable and conditional basis of in game events.  In 
# addition there is a script to move the clock forward by elapsing given time
# down to the minute.
#
# $time.minute                     : returns the minute of the hour
# $time.hour                       : returns the hour of the day
# $time.day                        : returns the day of the month
# $time.weekday                    : returns the weekday (by ID)
# $time.month                      : returns the month of the year (by ID)
# $time.season                     : returns the season of the year (by ID)
# $time.year                       : return s the year
#
# You could use the above to set in game variables, or make conditional branches
# like:
#
#             if $time.hour > 10
#               # do stuff after ten o'clock
#             end
#
# The following script call enables you to lapse a bit of time.  This would be 
# good for inns, or sleeping.  This would also be good for like an 'Elder Scrolls'ish
# 'Wait' system.  
#
#                 $time.lapse_time(minutes, hours, days, months, years)
#
# So to jump ahead four hours, you'd do:
#
#                 $time.lapse_time(0, 4, 0, 0, 0)
#
# This system hasn't been scrutinized well just yet.  Furthermore, the way the 
# 'months' are set up in the module, it may be best to ensure you never 
# skip more than the days in your shortest month, else you may have innaccurate
# results.  If you choose to jump more than that, it may be best to do so, using
# a loop that jumps 28 days, repeatedly, until you've advanced the time 
# you need to.  If you find an issue with this part of the script, feel free 
# to contact Ixfuru on the RPGarden.com forums or PM so that he can attempt to 
# fix it.
#-------------------------------------------------------------------------------
module IxfuruAce
  module TimeAce
    
    
    FRAMES_PER_MINUTE = 90       # How many frames go by before a 'minute increases
    MINUTES_PER_HOUR = 60         # how many minutes are there in an hour        
    HOURS_PER_DAY = 24            # how many hours are there in a day
    
    # The months hash is important.  If you want there to be 12 months in a year, 
    # then make sure there's 12 entries in the hash. (As there is by default).
    # For each entry, you can give a name of the month and also set the number
    # of days in the specified month.
    MONTHS = {                    
    
      0 => ["January", 30],
      1 => ["February", 28],
      2 => ["March", 31],
      3 => ["April", 31],
      4 => ["May", 30],
      5 => ["June", 30],
      6 => ["July", 31],
      7 => ["August", 31],
      8 => ["September", 30],
      9 => ["October", 31],
      10 => ["November", 31],
      11 => ["December", 31],
      
    }
    
    # First of all, make sure you place as many entries into the hash, as the 
    # days you want in a week (7 by default).  You can then name each and
    # every one of them.
    WEEKDAYS = {
    
      0 => "Sunday",
      1 => "Monday",
      2 => "Tuesday",
      3 => "Wednesday",
      4 => "Thursday",
      5 => "Friday",
      6 => "Saturday",
      
    }
    
    # The following tell the system what time it should be at the beginning
    # of a new game.
    START_MINUTE = 0
    START_HOUR = 6
    START_DAY = 30
    START_WEEKDAY = 6
    START_MONTH = 4
    START_YEAR = 1313
    
    # In this hash, you will set the opacity (or how dark) the overhead shade
    # image should be during each hour of the day.  Keep in mind that you must
    # have one entry in the hash for each hour you stated in the 'HOURS PER DAY'
    # variable above. (There's 24 in the hash by default!).   The max you can
    # set the opacity to is 255.  This is utter and complete darkness.  If you set
    # the value to that, it will be as if the player can't see ANYTHING. 
    # The lightest is of course zero (0).  Setting it to zero means that you can't
    # see that shade image at all, because it's been rendered transparent.  This 
    # is perfect for daylight hours.  And the system will revert to this if 
    # the player is on a map that has been called a 'NO_SHADE_MAP'.   If you 
    # don't really know how to set this up, it may be best to just play around
    # with the numbers until you find the right settings.
    HOUR_SHADE_OPACITY = {
    
      0 => 180,
      1 => 180,
      2 => 180,
      3 => 180,
      4 => 160,
      5 => 120,
      6 => 60,
      7 => 0,
      8 => 0,
      9 => 0, 
      10 => 0, 
      11 => 0, 
      12 => 0,
      13 => 0,
      14 => 0,
      15 => 0, 
      16 => 0,
      17 => 0, 
      18 => 20,
      19 => 60,
      20 => 120,
      21 => 160,
      22 => 180,
      23 => 180,
      
    }
    
    # This is basically used to determine what season it is.  Not useful without
    # some additional weather system or what-have-you.  But it basically gives
    # each season an ID, then connects the id to a two-element array.
    # The first element array is a sub-array of two elements with the 
    # first and last month of the season as the elements.  The second element of 
    # main array is the name of the season.
    SEASONS = {
    
      0 => [[0, 2], "Spring"],
      1 => [[3, 5], "Summer"],
      2 => [[6, 8], "Autumn"],
      3 => [[9, 11], "Winter"],
      
    }
    
    DISABLE_TIME_SWITCH = 9               # in game switch which will stop time
    TIME_WINDOW_CALL_INPUT = Input::R     # the button to press to call the time window
    
    # The following value corresponds to where you want the time window to 
    # appear and show on the map scene when called. 
    #
    # 0 : top, aligned to the left
    # 1 : top, centered
    # 2 : top, aligned to the right
    # 3 : bottom, aligned to the left
    # 4 : bottom, centered
    # 5 : bottom, aligned to the right
    TIME_WINDOW_MAP_ALIGNMENT = 4         
    
    # Place the IDs of maps you want to have no 'shade' effect on.  Good for 
    # interior maps or cutscene maps.  When player is on the given maps, the
    # shade opacity will be set to zero (0).
    NO_SHADE_MAPS = [2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
    
    # Placing the IDs of maps in this array, makes it so that the time window
    # cannot be called through Input of player when they are on the given map.
    NO_TIME_WINDOW_MAPS = [1]
    
    TIME_WINDOW_BACK_COLOR1 = 22 
    TIME_WINDOW_BACK_COLOR2 = 14
    
  end
end
#===============================================================================
#                             Cache
#===============================================================================
module Cache
  
  #-----------------------------------------------------------------------------
  # Shade
  #-----------------------------------------------------------------------------
  def self.shade
    load_bitmap("Graphics/Pictures/", "Shade")
  end
  
end
#===============================================================================
#                              Time
#===============================================================================
class Time
  
  attr_reader :minute
  attr_reader :hour
  attr_reader :day
  attr_reader :weekday
  attr_reader :month
  attr_reader :year
  
  #-----------------------------------------------------------------------------
  # Initialize
  #-----------------------------------------------------------------------------
  def initialize
    @frame = 0
    @minute = IxfuruAce::TimeAce::START_MINUTE
    @hour = IxfuruAce::TimeAce::START_HOUR
    @day = IxfuruAce::TimeAce::START_DAY
    @weekday = IxfuruAce::TimeAce::START_WEEKDAY
    @month = IxfuruAce::TimeAce::START_MONTH
    @year = IxfuruAce::TimeAce::START_YEAR
  end
  
  #-----------------------------------------------------------------------------
  # Time String
  #-----------------------------------------------------------------------------
  def time_string
    return weekday_string + ", " + month_string + " " + @day.to_s + ", " + 
    @year.to_s + ", " + hour_string + ":" + minute_string + " " + meridian_string
  end
  
  #-----------------------------------------------------------------------------
  # Weekday String
  #-----------------------------------------------------------------------------
  def weekday_string
    return IxfuruAce::TimeAce::WEEKDAYS[@weekday]
  end
  
  #-----------------------------------------------------------------------------
  # Month String
  #-----------------------------------------------------------------------------
  def month_string
    return IxfuruAce::TimeAce::MONTHS[@month][0]
  end
  
  #-----------------------------------------------------------------------------
  # Meridian String
  #-----------------------------------------------------------------------------
  def meridian_string
    if @hour > 12
      return "PM"
    else
      return "AM"
    end
  end
  
  #-----------------------------------------------------------------------------
  # Hour String
  #-----------------------------------------------------------------------------
  def hour_string
    if @hour > 12
      h = @hour - 12
    else 
      h = @hour
    end
    if h < 10
      return "0" + h.to_s
    else
      return h.to_s
    end
  end
  
  #-----------------------------------------------------------------------------
  # Minute String
  #-----------------------------------------------------------------------------
  def minute_string
    if @minute < 10
      return "0" + @minute.to_s
    else
      return @minute.to_s
    end
  end
  
  #-----------------------------------------------------------------------------
  # Fpm
  #-----------------------------------------------------------------------------
  def fpm
    return IxfuruAce::TimeAce::FRAMES_PER_MINUTE
  end
  
  #-----------------------------------------------------------------------------
  # Mph
  #-----------------------------------------------------------------------------
  def mph
    return IxfuruAce::TimeAce::MINUTES_PER_HOUR
  end
  
  #-----------------------------------------------------------------------------
  # Hpd
  #-----------------------------------------------------------------------------
  def hpd
    return IxfuruAce::TimeAce::HOURS_PER_DAY
  end
  
  #-----------------------------------------------------------------------------
  # Dpw
  #-----------------------------------------------------------------------------
  def dpw
    return IxfuruAce::TimeAce::WEEKDAYS.size
  end
  
  #-----------------------------------------------------------------------------
  # Dpm
  #-----------------------------------------------------------------------------
  def dpm
    return IxfuruAce::TimeAce::MONTHS[@month][1]
  end
  
  #-----------------------------------------------------------------------------
  # Mpy
  #-----------------------------------------------------------------------------
  def mpy
    return IxfuruAce::TimeAce::MONTHS.size
  end
  
  #-----------------------------------------------------------------------------
  # Update
  #-----------------------------------------------------------------------------
  def update
    @frame += 1
    if @frame >= fpm
      update_minute
      @frame = 0
    end
  end
  
  #-----------------------------------------------------------------------------
  # Update Minute
  #-----------------------------------------------------------------------------
  def update_minute
    @minute += 1
    if @minute >= mph
      update_hour
      @minute = 0
    end
  end
  
  #-----------------------------------------------------------------------------
  # Update Hour
  #-----------------------------------------------------------------------------
  def update_hour
    @hour += 1
    if @hour >= hpd
      update_day
      @hour = 0
    end
    $game_map.refresh
  end
  
  #-----------------------------------------------------------------------------
  # Update Day
  #-----------------------------------------------------------------------------
  def update_day
    @weekday += 1
    if @weekday >= dpw
      update_week
      @weekday = 0
    end
    @day += 1
    if @day > dpm
      update_month
      @day = 1
    end
  end
  
  #-----------------------------------------------------------------------------
  # Update Week
  #-----------------------------------------------------------------------------
  def update_week
    
  end
  
  #-----------------------------------------------------------------------------
  # Update Month
  #-----------------------------------------------------------------------------
  def update_month
    @month += 1
    if @month >= mpy
      update_year
      @month = 0
    end
  end
  
  #-----------------------------------------------------------------------------
  # Update Year
  #-----------------------------------------------------------------------------
  def update_year
    @year += 1
  end
  
  #-----------------------------------------------------------------------------
  # Lapse Time
  #-----------------------------------------------------------------------------
  def lapse_time(mi, h, d, mo, y)
    # SET THE MINUTE
    total_minutes = @minute + mi
    hr_plus = total_minutes / mph
    @minute = total_minutes % mph
    # SET THE HOUR
    total_hours = @hour + h + hr_plus
    day_plus = total_hours / hpd
    @hour = total_hours % hpd
    # SET THE DAY
    total_days = @day + d + day_plus
    @weekday = total_days % dpw
    month_plus = total_days / dpm
    @day = total_days % dpm
    # SET THE MONTH
    total_months = @month + mo + month_plus
    year_plus = total_months / mpy
    @month = total_months % mpy
    # SET THE YEAR
    @year = @year + y + year_plus
  end
  
  #-----------------------------------------------------------------------------
  # Phase Shade Opacity
  #-----------------------------------------------------------------------------
  def phase_shade_opacity
    return IxfuruAce::TimeAce::HOUR_SHADE_OPACITY[@hour]
  end
  
  #-----------------------------------------------------------------------------
  # Seasons
  #-----------------------------------------------------------------------------
  def season
    IxfuruAce::TimeAce::SEASONS.each { |ss, mths|
    if @month.between?(mths[0][0], mths[0][1])
      return ss
    end
    }
  end
  
  #-----------------------------------------------------------------------------
  # Season Text
  #-----------------------------------------------------------------------------
  def season_text
    return IxfuruAce::TimeAce::SEASONS[season][1]
  end
  
  #-----------------------------------------------------------------------------
  # Disable Switch
  #-----------------------------------------------------------------------------
  def disable_switch
    return $game_switches[IxfuruAce::TimeAce::DISABLE_TIME_SWITCH]
  end
  
  #-----------------------------------------------------------------------------
  # Window Alignment
  #-----------------------------------------------------------------------------
  def window_alignment
    align = IxfuruAce::TimeAce::TIME_WINDOW_MAP_ALIGNMENT
    case align
    when 0 
      return [0, 0]
    when 1
      return [0, 1]
    when 2
      return [0, 2]
    when 3 
      return [372, 0]
    when 4
      return [372, 1]
    when 5
      return [372, 2]
    end
  end
  
  #-----------------------------------------------------------------------------
  # Window Rect Colors
  #-----------------------------------------------------------------------------
  def window_rect_colors
    return [IxfuruAce::TimeAce::TIME_WINDOW_BACK_COLOR1, 
    IxfuruAce::TimeAce::TIME_WINDOW_BACK_COLOR2]
  end
  
end
#===============================================================================
#                              Spriteset Map
#===============================================================================
class Spriteset_Map
  
  #-----------------------------------------------------------------------------
  # Initialize (Aliased)
  #-----------------------------------------------------------------------------
  alias ixatassmpini initialize unless $@
  def initialize
    ixatassmpini
    create_shade
  end
  
  #-----------------------------------------------------------------------------
  # Dispose (Aliased)
  #-----------------------------------------------------------------------------
  alias ixatmassmpdisps dispose unless $@
  def dispose
    ixatmassmpdisps
    dispose_shade
  end
  
  #--------------------------------------------------------------------------
  # * Create Viewport (Aliased)
  #--------------------------------------------------------------------------
  alias ixatassmpcvp create_viewports unless $@
  def create_viewports
    ixatassmpcvp
    @viewport4 = Viewport.new
    @viewport4.z = 120
  end
  
  #-----------------------------------------------------------------------------
  # Create Shade
  #-----------------------------------------------------------------------------
  def create_shade
    @shade_sprite = Sprite.new(@viewport4)
    @shade_sprite.bitmap = Cache.shade
    update_shade
  end
  
  #-----------------------------------------------------------------------------
  # Update Shade
  #-----------------------------------------------------------------------------
  def update_shade
    if IxfuruAce::TimeAce::NO_SHADE_MAPS.include?($game_map.map_id)
      @shade_sprite.opacity = 0
    else
      @shade_sprite.opacity = $time.phase_shade_opacity
    end
    @shade_sprite.update
  end
  
  #-----------------------------------------------------------------------------
  # Dispose Shade
  #-----------------------------------------------------------------------------
  def dispose_shade
    @shade_sprite.dispose
  end
  
  #-----------------------------------------------------------------------------
  # Dispose Viewports (Aliased)
  #-----------------------------------------------------------------------------
  alias ixatassmpdvp dispose_viewports unless $@
  def dispose_viewports
    ixatassmpdvp
    @viewport4.dispose
  end
  
  #-----------------------------------------------------------------------------
  # Update Viewports (Aliased)
  #-----------------------------------------------------------------------------
  alias ixtassmpupdvp update_viewports unless $@
  def update_viewports
    ixtassmpupdvp
    @viewport4.update
  end
  
end
#===============================================================================
#                             Scene Title
#===============================================================================
class Scene_Title < Scene_Base
  
  #------------------------------------------------------------------------------
  # Command New Game (Aliased)
  #-----------------------------------------------------------------------------
  alias ixatmasctitcng command_new_game unless $@
  def command_new_game
    $time = Time.new
    ixatmsactitcng
  end
  
end
#===============================================================================
#                             DataManager
#===============================================================================
module DataManager
  class << self
  
    #--------------------------------------------------------------------------
    # * Make Save Contents 
    #--------------------------------------------------------------------------
    def make_save_contents
      contents = {}
      contents[:system]        = $game_system
      contents[:timer]         = $game_timer
      contents[:message]       = $game_message
      contents[:switches]      = $game_switches
      contents[:variables]     = $game_variables
      contents[:self_switches] = $game_self_switches
      contents[:actors]        = $game_actors
      contents[:party]         = $game_party
      contents[:troop]         = $game_troop
      contents[:map]           = $game_map
      contents[:player]        = $game_player
      contents[:time]          = $time
      contents
    end
  
    #--------------------------------------------------------------------------
    # * Extract Save Contents (Aliased)
    #--------------------------------------------------------------------------
    alias ixatmascflesc extract_save_contents unless $@
    def extract_save_contents(contents)
      ixatmascflesc(contents)
      $time          = contents[:time]
    end
  
  end
end
#===============================================================================
#                                Game Map
#===============================================================================
class Game_Map
  
  #-----------------------------------------------------------------------------
  # Setup (Aliased)
  #------------------------------------------------------------------------------
  alias ixatmgmmpsu setup unless $@
  def setup(map_id)
    ixatmgmmpsu(map_id)
    if SceneManager.scene_is?(Scene_Map)
      SceneManager.scene.spriteset.update_shade
    end
  end
  
  #-----------------------------------------------------------------------------
  # Update
  #-----------------------------------------------------------------------------
  alias ixatmagmmpupd update unless $@
  def update(main = false)
    ixatmagmmpupd(main)
    $time = Time.new if $time.nil?
    unless $time.disable_switch
      $time.update
    end
  end
  
end
#===============================================================================
#                                 Window Time
#===============================================================================
class Window_TimeAce < Window_Base
  
  #-----------------------------------------------------------------------------
  # Initialize
  #-----------------------------------------------------------------------------
  def initialize
    super(0, $time.window_alignment[0], 544, 48)
    @minute = $time.minute
    refresh
    self.hide
    self.opacity = 0
  end
  
  #-----------------------------------------------------------------------------
  # Refresh
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    c1 = text_color($time.window_rect_colors[0])
    c2 = text_color($time.window_rect_colors[1])
    rect = Rect.new(0, 0, contents_width, contents_height)
    self.contents.gradient_fill_rect(rect, c1, c2)
    time_string = $time.time_string
    self.contents.draw_text(0, 0, contents_width, line_height, time_string,
    $time.window_alignment[1])
  end
  
  #-----------------------------------------------------------------------------
  # Update Minute
  #-----------------------------------------------------------------------------
  def update_minute
    if $time.minute != @minute
      refresh
      @minute = $time.minute
    end
  end
  
  
end
#===============================================================================
#                                 Scene Map
#===============================================================================
class Scene_Map < Scene_Base
  
  attr_accessor :spriteset
  
  #-----------------------------------------------------------------------------
  # Start (Aliased)
  #-----------------------------------------------------------------------------
  alias ixatmascmpstart start unless $@
  def start
    ixatmascmpstart
    @win_time = Window_TimeAce.new
  end
  
  #-----------------------------------------------------------------------------
  # Update
  #-----------------------------------------------------------------------------
  alias ixatmascmpupd update unless $@
  def update
    ixatmascmpupd
    if IxfuruAce::TimeAce::NO_TIME_WINDOW_MAPS.include?($game_map.map_id)
      @win_time.hide
    else
      update_time_call
    end
  end
  
  #-----------------------------------------------------------------------------
  # Update Time Call
  #-----------------------------------------------------------------------------
  def update_time_call
    if @win_time.visible
      @win_time.update_minute
      if Input.trigger?(IxfuruAce::TimeAce::TIME_WINDOW_CALL_INPUT)
        Sound.play_ok
        @win_time.hide
      end
    else
      if Input.trigger?(IxfuruAce::TimeAce::TIME_WINDOW_CALL_INPUT)
        Sound.play_ok
        @win_time.show
      end
    end
  end
  
  #-----------------------------------------------------------------------------
  # Terminate (Aliased)
  #-----------------------------------------------------------------------------
  alias ixatmascmpterm terminate unless $@
  def terminate
    @win_time.dispose
    ixatmascmpterm
  end
    
endInstructions
I tried to cover everything in the script itself, (as I try to do in all my scripts), but I'll break it down here for you.
Settings
You need to set the 'DISABLE TIME SWITCH' to be whatever game switch you want to use in order to enable/disable the
switch. Then, set up the 'TIME_WINDOW_CALL_INPUT' to whatever button you want to use to call the window from the
map scene. From there, you can set up things to your liking by following the instructions of each part of the settings module. This includes where you name the weekdays and months, set the 'no shade maps' and where you alter the shade itself given
what time of day or night it is.
Compatibility
Since this system saves and reloads time as a global variable via the 'Data_Manager', this script may cause issues with other scripts which do the same. You can try sticking the script above other such scripts. Usually, this can be fixed by simply creating a little patch to consolidate all the scripts with additional global variables. If you have an issue with the save/load, let me know and I'll try to help patch it up and make it work with what you're using.
Author's Notes
I made this script because I needed it and sometimes I'd rather write my own script as opposed to using someone else's
 But I know there are probably ten other time scripts out there and if you like them better, use theirs.  I wanted to release this script here now, I made other scripts that are compatible with this script that I may want to share in the future.
 But I know there are probably ten other time scripts out there and if you like them better, use theirs.  I wanted to release this script here now, I made other scripts that are compatible with this script that I may want to share in the future.Terms and Conditions
You must credit me if you use this script even if it is modified by you or someone else.
In non-commercial games, it's free to use. For commercial projects, I would just like a free copy and the credit!
Don't claim this is your script because it isn't!
And lastly, if you want to post the script on another site, you must have my permission first.

 
 
 Time
 Time
 

 
