Help - Search - Members - Calendar
Full Version: ~[Kylock's Time System VX 1.5]~
RPG RPG Revolution Forums > Scripting > Script Submissions > RGSS2-Submissions
Pages: 1, 2, 3, 4
Kylock


feedback required


Kylock's Time System VX 1.5
by Kylock


This script will track game time as well as automatically tint the screen for a day/night effect.
You can make events dependent on time thanks to game variable output support.
You can customize how dark you want it to be at what time.
You can designate certain maps as "outside" so they are the only ones that are dark at night! (Add [KTS] to map name.)
You can choose the speed of your game's clock.
Because the entire time system is an object, its possible to instance or have more than one game clock. PM me for details if you really need this functionality.

Detailed installation and script usage instructions are included in the script header, just like all my other scripts. The usage is VERY similar to the XP version that I wrote over a year ago - if you are familiar with it at all.

To answer a few question before they are asked:
- I am not including weeks, months and years because it gets too complicated when you have a different amount of days in each month for example. The primary intention of this script is to allow you to build your events based on hours in the day and time periods throughout the day. (Ex: The time-locked vault can only be opened between 2 and 3. or The guy with the password can only be found drinking in the bar at midnight.)
- The [KTS] that you put in your map names remains hidden to other scripts, like Map Name Popups and such.
- For script compatibility reasons, if you use a CMS, you might get better results if this script is located ABOVE your CMS. If you have a CMS and want a time window added to it, this is a really easy hack for any scripter, so please make a request in the appropriate Script Requests Forum.
- There are no screenshots because that would be pointless. You can define your own screen tones and there is an added window for time right above the gold window in the default menu. That's all there is, I promise!

Now, the script itself:


CODE
#==============================================================================
# ■ Kylock's Time System VX 1.5
#     6.3.2008
#------------------------------------------------------------------------------
#  Script by: Kylock
#==============================================================================
#    Mostly rewritten since XP version.  Cleaner code and less intrusive (more
#  compatible).  This is my comprehensive time and day/night system.  This
#  script adds a new window to the game menu, so if you use a CMS, then place
#  this script ABOVE it so that it won't mess up your CMS.  If you use a custom
#  script that makes changes to the battle background, place KTS below it so
#  that you don't get the delayed-tone effect in you battles.  Other than that,
#  there shouldn't be any other script compatibility issues.
#    I've tried to make this script as customizable as possible, the settings
#  are found immediately following this header.  Although time output to game
#  variables is optional, I strongly suggest using it so that its easier to
#  build your events based on the time in the game.
#==============================================================================
# ● Change Log
#------------------------------------------------------------------------------
#  1.0 - Original Release.
#  1.1 - Corrected tinting issue at the start of a battle.  Place this script
#          below any battle background scripts if you experience "jumpy tinting"
#  1.2 - Corrected the accuracy of $kts.stop and $kts.go
#  1.3 - $kts.stop really stops everything now.  Also added game switches for
#          even easier eventing.
#  1.4 - Fixed Battle Test compatibility (simulates normal daylight for battle
#          test instead of darkness).
#        Now switches and variables will only update when the map loads so that
#          events don't suddenly dissappear when their time is up.
#        Added $kts_anti_tone - returns an inverse tone color to allow sprites
#          to appear normally on a tinted screen.
#  1.5 - Rewrote the regexp that finds the [KTS] in the map name.  Hopefully
#          this resolves the wrong maps being tinted problem.
#==============================================================================
# ● Auto-tone Instructions
#------------------------------------------------------------------------------
#    Maps designated as outdoors are the only maps to be affected by this
#  scripts use of auto-toning.  To signify a map to be "outdoors", you must
#  include [KTS] In the name of the map.  For example, you world map could be
#  named "World Map [KTS]" or "[KTS] World Map".  Provisions are made later in
#  the script to remove [KTS] from the map name when it's read by another
#  script.  This means that "[KTS]" won't show up in your Map Name Popup
#  windows.
#==============================================================================
# ● Script Function Calls
#------------------------------------------------------------------------------
#    The following are script commands that can be executed by using the
#  "Script..." command in your events.
#    ● $kts.stop            - Stops time (can be used for cutscenes)
#    ● $kts.go              - Resumes time (don't forget to use this!)
#    ● $kts.sec(n)          - progresses time forward (n) seconds
#    ● $kts.min(n)          - progresses time forward (n) minutes
#    ● $kts.hours(n)        - progresses time forward (n) hours
#    ● $kts.days(n)         - progresses time forward (n) days
#    ● $kts.jump_to_hour(n) - progresses time forward TO the specified hour.
#                             Particularly useful in a situation where you
#                             want a certain event to happen at a certain time,
#                             or an Innkeeper who should wake the party up at
#                             a certain hour.  This command MAY cause your game
#                             to appear to freeze for a few seconds on slower
#                             computers.
#==============================================================================
# ● Game Database Setup
#------------------------------------------------------------------------------
#    This script, by defult, uses the following game variables and switches:
#  Database Variables:
#    [1] The Current Time            [4] The Current Hour
#    [2] The Current Second          [5] The Current Day
#    [3] The Current Minute          [6] Name of the Current Day
#  Database Switches
#    [1] ON during night hours   (2200-0400)(10pm-4am)
#    [2] ON during dawn hours    (0500-0800)( 5am-8am)
#    [3] ON during daytime hours (0900-1800)( 9am-6pm)
#    [4] ON during sunset hours  (1900-2100)( 7pm-9pm)
#==============================================================================

#==============================================================================
# Stores variables and user defined settings for the time system.
#==============================================================================
module KTS
  #-----------------------------------------------------------------------
  # User Definable Clock Settings
  #-----------------------------------------------------------------------
  # Sets the speed multiplier of the clock.  1 is real time.  A higher
  #   value will give you a faster clock.  Default is 100.
  SPEED      = 100
  #AMPM (True: 12-hour clock, False: 24-hour clock)
  AMPM       = false
  # Sets the time at the start of your game.
  START_HOUR = 1
  START_DAY  = 1
  #-----------------------------------------------------------------------
  # If you want custom day names, edit away!
  #-----------------------------------------------------------------------
  DAY_NAMES = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
  #-----------------------------------------------------------------------
  # Settings for Time Periods
  #-----------------------------------------------------------------------
  T1 = [ 0,5 ] # Night         # Sets time periods for tinting effects
  T2 = [ 6,8 ] # Dawn          # [Start Hour, End Hour] for time period
  T3 = [ 9,18] # Day           # Use 24-hour values for time periods
  T4 = [19,21] # Sunset
  T5 = [22,24] # Night         # <- Ex: Night is between 23:00 and 24:00
  #-----------------------------------------------------------------------
  # Settings for Output to Game Variables option.
  #-----------------------------------------------------------------------
  # Set this to true to output the current time to game variables.
  DATABASE_OUTPUT = true
    # Game Variable to be used for time output.
    TIME    = 1 #(Time in string format. Ex: "2:48 AM" or "02:48")
    SECONDS = 2
    MINUTES = 3
    HOURS   = 4
    DAYS    = 5
    DAYNAME = 6
    # Game Switches to be used for time output.
    NIGHT   = 1 # This switch is on during night hours   (2200-0400)(10pm-4am)
    DAWN    = 2 # This switch is on during dawn hours    (0500-0800)( 5am-8am)
    DAY     = 3 # This switch is on during daytime hours (0900-1800)( 9am-6pm)
    SUNSET  = 4 # This switch is on during sunset hours  (1900-2100)( 7pm-9pm)
  #-----------------------------------------------------------------------
  # Settings for time controlled screen toning
  #-----------------------------------------------------------------------
  # True will enable screen toning to be used by the script.
  USE_TONE = true
  # Sets the duration of tone changes (in frames)
  FADE_LENGTH = 120
  # Defines tones to be used in the corresponding time periods defined above.
  #              RED, GREEN, BLUE, GREY
  C1 = Tone.new(-187,  -119,  -17,  68)
  C2 = Tone.new(  17,   -51, -102,   0)
  C3 = Tone.new(   0,     0,    0,   0)
  C4 = Tone.new( -68,  -136,  -34,   0)
  C5 = Tone.new(-187,  -119,  -17,  68)
  # Defines anti-tones
  A1 = Tone.new( 187,   119,   17, -68)
  A2 = Tone.new( -17,    51,  102,   0)
  A3 = Tone.new(   0,     0,    0,   0)
  A4 = Tone.new(  68,   136,   34,   0)
  A5 = Tone.new( 187,   119,   17, -68)
end

#==============================================================================
# Core Time System Engine
#==============================================================================
class Kylock_Time_System
  # sets instance variables
  def initialize
    $kts_map_data = load_data("Data/MapInfos.rvdata")
    @event_offset = (KTS::START_HOUR * 3600) + (KTS::START_DAY * 86400)
    @kts_stop = false
    $kts_event_tone = false
    $kts_battle_tone = true
    $kts_anti_tone = Tone.new(0,0,0,0)
  end
  
  # Computes current time and updates variables if used
  def update
    if !@kts_stop
      @total_seconds = (Graphics.frame_count * KTS::SPEED / 60) + @event_offset
      @seconds = (@total_seconds) % 60
      @minutes = (@total_seconds / 60) % 60
      @hours   = (@total_seconds / 3600) % 24
      @days    = (@total_seconds / 86400)
      update_tint
      if KTS::DATABASE_OUTPUT
        $game_variables[KTS::TIME]    = getTime
      end
    end
  end

  def update_variables
    $game_variables[KTS::SECONDS] = @seconds
    $game_variables[KTS::MINUTES] = @minutes
    $game_variables[KTS::HOURS]   = @hours
    $game_variables[KTS::DAYS]    = @days
    $game_variables[KTS::DAYNAME] = getDayName
  end

  def update_switches
    if @period == 1 || @period == 5
      $game_switches[KTS::NIGHT] = true
    else
      $game_switches[KTS::NIGHT] = false
    end
    if @period == 2
      $game_switches[KTS::DAWN] = true
    else
      $game_switches[KTS::DAWN] = false
    end
    if @period == 3
      $game_switches[KTS::DAY] = true
    else
      $game_switches[KTS::DAY] = false
    end
    if @period == 4
      $game_switches[KTS::SUNSET] = true
    else
      $game_switches[KTS::SUNSET] = false
    end
  end

  def getTime
    if KTS::AMPM
      # Formats a 12-Hour Clock
      if @hours > 12
        hours1 = @hours - 12
        if hours1 > 9
          time = sprintf("%02d:%02d" + " PM", hours1, @minutes)
        else
          time = sprintf("%01d:%02d" + " PM", hours1, @minutes)
        end
      else
        if @hours > 9
          time = sprintf("%02d:%02d" + " AM", @hours, @minutes)
        else
          time = sprintf("%01d:%02d" + " AM", @hours, @minutes)
        end
      end
      return time
    else
      # Formats a 24-Hour Clock
      time = sprintf("%02d:%02d", @hours, @minutes)
      return time
    end
  end
  #-----------------------------------------------------------------------
  # Script Command Functions
  #-----------------------------------------------------------------------
  def stop
    @time_stopped = @total_seconds
    @kts_stop = true
  end
  def go
    total_seconds = (Graphics.frame_count * KTS::SPEED / 60) + @event_offset
    @event_offset -= (total_seconds - @time_stopped)
    @kts_stop = false
  end
  def sec(sec = 0)
    @event_offset += sec
  end
  def min(min = 0)
    @event_offset += min * 60
  end
  def hours(hours = 0)
    @event_offset += hours * 3600
  end
  def days(days = 0)
    @event_offset += days * 86400
  end
  def jump_to_hour(jhour = 0)
    while @hours != jhour
      @event_offset += 1
      $kts.update
    end
  end
  #-----------------------------------------------------------------------
  # Script Support/Misc Functions
  #-----------------------------------------------------------------------
  def getDayName
    weekday = (@days % KTS::DAY_NAMES.length)
    return KTS::DAY_NAMES[weekday]
  end

  #-----------------------------------------------------------------------
  # Screen Tone Functions
  #-----------------------------------------------------------------------
  def update_tint(duration = KTS::FADE_LENGTH)
    return if $BTEST
    if KTS::USE_TONE && !$kts_event_tone && $kts_map_data[$game_map.map_id].outside_tint?
      if @hours >= KTS::T1[0] and @hours <= KTS::T1[1]
        @period = 1
        screen.start_tone_change(KTS::C1,duration)
        $kts_anti_tone = KTS::A1
      elsif @hours >= KTS::T2[0] and @hours <= KTS::T2[1]
        @period = 2
        screen.start_tone_change(KTS::C2,duration)
        $kts_anti_tone = KTS::A2
      elsif @hours >= KTS::T3[0] and @hours <= KTS::T3[1]
        @period = 3
        screen.start_tone_change(KTS::C3,duration)
        $kts_anti_tone = KTS::A3
      elsif @hours >= KTS::T4[0] and @hours <= KTS::T4[1]
        @period = 4
        screen.start_tone_change(KTS::C4,duration)
        $kts_anti_tone = KTS::A4
      elsif @hours >= KTS::T5[0] and @hours <= KTS::T5[1]
        @period = 5
        screen.start_tone_change(KTS::C5,duration)
        $kts_anti_tone = KTS::A5
      end
    else
      # no tone if indoors
      if !$kts_map_data[$game_map.map_id].outside_tint?
        screen.start_tone_change(Tone.new(0,0,0,0),duration)
      end
    end
  end
  def screen
    if $game_temp.in_battle
      return $game_troop.screen
    else
      return $game_map.screen
    end
  end
end

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias kts_initialize initialize
  def initialize
    $kts.update_switches if !@kts_stop && KTS::DATABASE_OUTPUT
    $kts.update_variables if !@kts_stop && KTS::DATABASE_OUTPUT
    kts_initialize
  end
end

#==============================================================================
# Instantly updates screen tone when a new map is loaded.
#==============================================================================
class Game_Map
  alias kts_setup setup
  def setup(map_id)
    kts_setup(map_id)
    $kts_event_tone = false
    $kts.update
    $kts.update_tint(0)
  end
end

#==============================================================================
# Instantly updates screen tone when a battle starts.
#==============================================================================
class Spriteset_Battle
  alias kts_create_battleback create_battleback
  def create_battleback
    $kts.update_tint(0)
    kts_create_battleback
  end
end

#==============================================================================
# Temporarily disables auto-toning if an event tints the screen.
#==============================================================================
class Game_Interpreter
  alias kts_Interpreter_command_223 command_223
  def command_223
    $kts_event_tone = true
    kts_Interpreter_command_223
  end
end

#==============================================================================
# Integrates the Time System into the Game System.
#==============================================================================
class Game_System
  # inits a KTS object
  alias kts_initialize initialize
  def initialize
    $kts=Kylock_Time_System.new
    kts_initialize
  end
  # Updates kts every game frame
  alias kts_update update
  def update
    $kts.update
    kts_update
  end
end

#==============================================================================
# Scans Map Names for Toning
#==============================================================================
class RPG::MapInfo
  def name # Definition prevents location scripts from reading anything within
    return @name.gsub(/\[.*\]/) {""} # brackets, including the brackets
  end
  def original_name
    return @name
  end
  def outside_tint?
    return @name.scan(/\[KTS\]/).size > 0
    # old regexp: return @name.scan(/[\KTS]/).size > 0
  end
end

#==============================================================================
# Sets up the time window for the menu.
#==============================================================================
class Window_KTS < Window_Base
  def initialize(x, y)
    super(x, y, 160, WLH + 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.draw_text(4, -6, 120, 32, $kts.getTime, 2)
  end
  def update
    super
    $kts.update
    self.contents.clear
    self.contents.draw_text(4, -6, 120, 32, $kts.getTime, 2)
  end
end

#==============================================================================
# Adds the time window to the menu.
#==============================================================================
class Scene_Menu < Scene_Base
  alias kts_start start
  def start
    kts_start
    @kts_window = Window_KTS.new(0,305)
  end
  alias kts_terminate terminate
  def terminate
    kts_terminate
    @kts_window.dispose
  end
  alias kts_update update
  def update
    kts_update
    @kts_window.update
  end
end

#==============================================================================
# Saves and Loads game time to/from save game file.
#==============================================================================
class Scene_File
  alias kts_write_save_data write_save_data
  def write_save_data(file)
    kts_write_save_data(file)
    Marshal.dump($kts, file)
  end
  alias kts_read_save_data read_save_data
  def read_save_data(file)
    kts_read_save_data(file)
    $kts = Marshal.load(file)
  end
end



[Show/Hide] Sample Event

For my example, I'll make a set of events that only exist at night after 9pm and 5am.
First, make a common event that looks like this:

You'll notice that Switch 9 has to be on for this event to work, so you need to make sure that you turn it on before any important maps show up. So maybe turn on Switch 9 in your game opening sequence.

Now, for any event you want to show up only at night, all you have to do is this:


Piece of cake for any self-proclaimed eventers out there!


I am open to requests not covered above.

Enjoy,
Kylock
YanXie
Like I what said in #RMVXP, this script is great,it will add many variety and possiblity for the game,good job :3

cheers,puppeto4. smile.gif
TheBloodRed
I like this script a lot. Thanks for putting it up! biggrin.gif
Kylock
Version updated. Bugfixes. Original post updated as well.

I appreciate your comments =p
Namio
is it possible to make night time with different music?
Kylock
QUOTE (Namio @ May 9 2008, 11:40 PM) *
is it possible to make night time with different music?


All you would need to do is take the sample event I have in the original post, and where you see "Control Switches: [0010:Night time People] = ON" just replace, or add next to it, a Play BGM command.

That's the whole idea here, to be able to make events that can work straight from the clock! biggrin.gif
prinsu kun
thanks for the great script

it's possible to make a counting days depend on my computer clock ?
for example I was trying to make a school game with 30 days (based on real time)
the idea is counting the first time you play (new game date) and give you 30 days based on your computer clock
after the 30 days passed you will forcing to enter to the exam
Ilikepie123
QUOTE (Kylock @ May 8 2008, 10:50 PM) *
Kylock's Time System VX 1.2
by Kylock


This script will track game time as well as automatically tint the screen for a day/night effect.
You can make events dependent on time thanks to game variable output support.
You can customize how dark you want it to be at what time.
You can designate certain maps as "outside" so they are the only ones that are dark at night! (Add [KTS] to map name.)
You can choose the speed of your game's clock.
Because the entire time system is an object, its possible to instance or have more than one game clock. PM me for details if you really need this functionality.

Detailed installation and script usage instructions are included in the script header, just like all my other scripts. The usage is VERY similar to the XP version that I wrote over a year ago - if you are familiar with it at all.

To answer a few question before they are asked:
- I am not including weeks, months and years because it gets too complicated when you have a different amount of days in each month for example. The primary intention of this script is to allow you to build your events based on hours in the day and time periods throughout the day. (Ex: The time-locked vault can only be opened between 2 and 3. or The guy with the password can only be found drinking in the bar at midnight.)
- The [KTS] that you put in your map names remains hidden to other scripts, like Map Name Popups and such.
- For script compatibility reasons, if you use a CMS, you might get better results if this script is located ABOVE your CMS. If you have a CMS and want a time window added to it, this is a really easy hack for any scripter, so please make a request in the appropriate Script Requests Forum.
- There are no screenshots because that would be pointless. You can define your own screen tones and there is an added window for time right above the gold window in the default menu. That's all there is, I promise!

Now, the script itself:


CODE
#==============================================================================
# ■ Kylock's Time System VX 1.2
#     9.5.2008
#------------------------------------------------------------------------------
#  Script by: Kylock
#==============================================================================
#    Mostly rewritten since XP version.  Cleaner code and less intrusive (more
#  compatible).  This is my comprehensive time and day/night system.  This
#  script adds a new window to the game menu, so if you use a CMS, then place
#  this script ABOVE it so that it won't mess up your CMS.  Other than that,
#  there shouldn't be any other script compatibility issues.
#    I've tried to make this script as customizable as possible, the settings
#  are found immediately following this header.  Although time output to game
#  variables is optional, I strongly suggest using it so that its easier to
#  build your events based on the time in the game.
#==============================================================================
# ● Change Log
#  1.0 - Original Release.
#  1.1 - Corrected tinting issue at the start of a battle.  Place this script
#        below any battle background scripts if you experience "jumpy tinting"
#==============================================================================
# ● Auto-tone Tnstructions
#------------------------------------------------------------------------------
#    Maps designated as outdoors are the only maps to be affected by this
#  scripts use of auto-toning.  To signify a map to be "outdoors", you must
#  include [KTS] In the name of the map.  For example, you world map could be
#  named "World Map [KTS]" or "[KTS] World Map".  Provisions are made later in
#  the script to remove [KTS] from the map name when it's read by another
#  script.  This means that "[KTS]" won't show up in your Map Name Popup
#  windows.
#==============================================================================
#    The following are script commands that can be executed by using the
#  "Script..." command in your events.
#    ● $kts.stop            - Stops time (can be used for cutscenes)
#    ● $kts.go              - Resumes time (don't forget to use this!)
#    ● $kts.sec(n)          - progresses time forward (n) seconds
#    ● $kts.min(n)          - progresses time forward (n) minutes
#    ● $kts.hours(n)        - progresses time forward (n) hours
#    ● $kts.days(n)         - progresses time forward (n) days
#    ● $kts.jump_to_hour(n) - progresses time forward TO the specified hour.
#                             Particularly useful in a situation where you
#                             want a certain event to happen at a certain time,
#                             or an Innkeeper who should wake the party up at
#                             a certain hour.  This command MAY cause your game
#                             to appear to freeze for a few seconds on slower
#                             computers.
#==============================================================================

#==============================================================================
# Stores variables and user defined settings for the time system.
#==============================================================================
module KTS
  #-----------------------------------------------------------------------
  # User Definable Clock Settings
  #-----------------------------------------------------------------------
  # Sets the speed multiplier of the clock.  1 is real time.  A higher
  #   value will give you a faster clock.  Default is 100.
  SPEED      = 100
  #AMPM (True: 12-hour clock, False: 24-hour clock)
  AMPM       = false
  # Sets the time at the start of your game.
  START_HOUR = 0
  START_DAY  = 1
  #-----------------------------------------------------------------------
  # If you want custom day names, edit away!
  #-----------------------------------------------------------------------
  DAY_NAMES = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
  #-----------------------------------------------------------------------
  # Settings for Time Periods
  #-----------------------------------------------------------------------
  T1 = [ 0,4 ] # Early Morning # Sets time periods for tinting effects
  T2 = [ 5,11] # Morning       # [Start Hour, End Hour] for time period
  T3 = [12,18] # Day           # Use 24-hour values for time periods
  T4 = [19,22] # Evening
  T5 = [23,24] # Night         # <- Ex: Night is between 23:00 and 24:00
  #-----------------------------------------------------------------------
  # Settings for Output to Game Variables option.
  #-----------------------------------------------------------------------
  # Set this to true to output the current time to game variables.
  VARIABLES_OUTPUT = true
  # Defines the Game Variable to be used for time output.
  TIME    = 1 #(Time in string format. Ex: "2:48 AM" or "02:48")
  SECONDS = 2
  MINUTES = 3
  HOURS   = 4
  DAYS    = 5
  PERIOD  = 6 # (Value of 1-5 indicating the current time period)
  DAYNAME = 7
  #-----------------------------------------------------------------------
  # Settings for time controlled screen toning
  #-----------------------------------------------------------------------
  # True will enable screen toning to be used by the script.
  USE_TONE = true
  # Sets the duration of tone changes (in frames)
  FADE_LENGTH = 120
  # Defines tones to be used in the corresponding time periods defined above.
  #              RED, GREEN, BLUE, GREY
  C1 = Tone.new(-187,  -119,  -17,  68)
  C2 = Tone.new(  17,   -51, -102,   0)
  C3 = Tone.new(   0,     0,    0,   0)
  C4 = Tone.new( -68,  -136,  -34,   0)
  C5 = Tone.new(-187,  -119,  -17,  68)
end

#==============================================================================
# Core Time System Engine
#==============================================================================
class Kylock_Time_System
  # sets instance variables
  def initialize
    $kts_map_data = load_data("Data/MapInfos.rvdata")
    @event_offset = (KTS::START_HOUR * 3600) + (KTS::START_DAY * 86400)
    $kts_event_tone = false
    $kts_battle_tone = true
  end
  
  # Computes current time and updates variables if used
  def update
    @total_seconds = (Graphics.frame_count * KTS::SPEED / 60) + @event_offset
    @seconds = (@total_seconds) % 60
    @minutes = (@total_seconds / 60) % 60
    @hours   = (@total_seconds / 3600) % 24
    @days    = (@total_seconds / 86400)
    update_tint
    if KTS::VARIABLES_OUTPUT
      $game_variables[KTS::TIME]    = getTime
      $game_variables[KTS::SECONDS] = @seconds
      $game_variables[KTS::MINUTES] = @minutes
      $game_variables[KTS::HOURS]   = @hours
      $game_variables[KTS::DAYS]    = @days
      $game_variables[KTS::PERIOD]  = @period
      $game_variables[KTS::DAYNAME] = getDayName
    end
  end
    
  def getTime
    if KTS::AMPM
      # Formats a 12-Hour Clock
      if @hours > 12
        hours1 = @hours - 12
        if hours1 > 9
          time = sprintf("%02d:%02d" + " PM", hours1, @minutes)
        else
          time = sprintf("%01d:%02d" + " PM", hours1, @minutes)
        end
      else
        if @hours > 9
          time = sprintf("%02d:%02d" + " AM", @hours, @minutes)
        else
          time = sprintf("%01d:%02d" + " AM", @hours, @minutes)
        end
      end
      return time
    else
      # Formats a 24-Hour Clock
      time = sprintf("%02d:%02d", @hours, @minutes)
      return time
    end
  end
  #-----------------------------------------------------------------------
  # Script Command Functions
  #-----------------------------------------------------------------------
  def stop
    @time_stopped = @total_seconds
  end
  def go
    @event_offset -= (@total_seconds - @time_stopped)
  end
  def sec(sec = 0)
    @event_offset += sec
  end
  def min(min = 0)
    @event_offset += min * 60
  end
  def hours(hours = 0)
    @event_offset += hours * 3600
  end
  def days(days = 0)
    @event_offset += days * 86400
  end
  def jump_to_hour(jhour = 0)
    while @hours != jhour
      @event_offset += 1
      $kts.update
    end
  end
  #-----------------------------------------------------------------------
  # Script Support/Misc Functions
  #-----------------------------------------------------------------------
  def getDayName
    weekday = (@days % KTS::DAY_NAMES.length)
    return KTS::DAY_NAMES[weekday]
  end

  #-----------------------------------------------------------------------
  # Screen Tone Functions
  #-----------------------------------------------------------------------
  def update_tint(duration = KTS::FADE_LENGTH)
    if KTS::USE_TONE && !$kts_event_tone && $kts_map_data[$game_map.map_id].outside_tint?
      if @hours >= KTS::T1[0] and @hours <= KTS::T1[1]
        @period = 1
        screen.start_tone_change(KTS::C1,duration)
      elsif @hours >= KTS::T2[0] and @hours <= KTS::T2[1]
        @period = 2
        screen.start_tone_change(KTS::C2,duration)
      elsif @hours >= KTS::T3[0] and @hours <= KTS::T3[1]
        @period = 3
        screen.start_tone_change(KTS::C3,duration)
      elsif @hours >= KTS::T4[0] and @hours <= KTS::T4[1]
        @period = 4
        screen.start_tone_change(KTS::C4,duration)
      elsif @hours >= KTS::T5[0] and @hours <= KTS::T5[1]
        @period = 5
        screen.start_tone_change(KTS::C5,duration)
      end
    else
      # no tone if indoors
      if !$kts_map_data[$game_map.map_id].outside_tint?
        screen.start_tone_change(Tone.new(0,0,0,0),duration)
      end
    end
  end
  def screen
    if $game_temp.in_battle
      return $game_troop.screen
    else
      return $game_map.screen
    end
  end
end

#==============================================================================
# Instantly updates screen tone when a new map is loaded.
#==============================================================================
class Game_Map
  alias kts_setup setup
  def setup(map_id)
    kts_setup(map_id)
    $kts_event_tone = false
    $kts.update
    $kts.update_tint(0)
  end
end

#==============================================================================
# Instantly updates screen tone when a battle starts.
#==============================================================================
class Spriteset_Battle
  alias kts_create_battleback create_battleback
  def create_battleback
    $kts.update_tint(0)
    kts_create_battleback
  end
end

#==============================================================================
# Temporarily disables auto-toning if an event tints the screen.
#==============================================================================
class Game_Interpreter
  alias kts_Interpreter_command_223 command_223
  def command_223
    $kts_event_tone = true
    kts_Interpreter_command_223
  end
end

#==============================================================================
# Integrates the Time System into the Game System.
#==============================================================================
class Game_System
  # inits a KTS object
  alias kts_initialize initialize
  def initialize
    $kts=Kylock_Time_System.new
    kts_initialize
  end
  # Updates kts every game frame
  alias kts_update update
  def update
    $kts.update
    kts_update
  end
end

#==============================================================================
# Scans Map Names for Toning
#==============================================================================
class RPG::MapInfo
  def name # Definition prevents location scripts from reading anything within
    return @name.gsub(/\[.*\]/) {""} # brackets, including the brackets
  end
  def original_name
    return @name
  end
  def outside_tint?
    return @name.scan(/[\KTS]/).size > 0
  end
end

#==============================================================================
# Sets up the time window for the menu.
#==============================================================================
class Window_KTS < Window_Base
  def initialize(x, y)
    super(x, y, 160, WLH + 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.draw_text(4, -6, 120, 32, $kts.getTime, 2)
  end
  def update
    super
    $kts.update
    self.contents.clear
    self.contents.draw_text(4, -6, 120, 32, $kts.getTime, 2)
  end
end

#==============================================================================
# Adds the time window to the menu.
#==============================================================================
class Scene_Menu < Scene_Base
  alias kts_start start
  def start
    kts_start
    @kts_window = Window_KTS.new(0,305)
  end
  alias kts_terminate terminate
  def terminate
    kts_terminate
    @kts_window.dispose
  end
  alias kts_update update
  def update
    kts_update
    @kts_window.update
  end
end

#==============================================================================
# Saves and Loads game time to/from save game file.
#==============================================================================
class Scene_File
  alias kts_write_save_data write_save_data
  def write_save_data(file)
    kts_write_save_data(file)
    Marshal.dump($kts, file)
  end
  alias kts_read_save_data read_save_data
  def read_save_data(file)
    kts_read_save_data(file)
    $kts = Marshal.load(file)
  end
end



[Show/Hide] Sample Event

For my example, I'll make a set of events that only exist at night after 9pm and 5am.
First, make a common event that looks like this:

You'll notice that Switch 9 has to be on for this event to work, so you need to make sure that you turn it on before any important maps show up. So maybe turn on Switch 9 in your game opening sequence.

Now, for any event you want to show up only at night, all you have to do is this:


Piece of cake for any self-proclaimed eventers out there!


I am open to requests not covered above.

Enjoy,
Kylock

OMFG MAN! I HAVE ALWAYS NEEDED A SCRIPT LIKE THIS XD Im like so psyched about this lol, Im using it ASAP.
Thanks for posting it biggrin.gif
Kylock
QUOTE (prinsu kun @ May 10 2008, 08:44 AM) *
thanks for the great script

it's possible to make a counting days depend on my computer clock ?
for example I was trying to make a school game with 30 days (based on real time)
the idea is counting the first time you play (new game date) and give you 30 days based on your computer clock
after the 30 days passed you will forcing to enter to the exam


The way that this script determines time is fundamentally different than any method that could be used to base time off of the system clock. It counts frames and makes assumptions based on the FPS of RMVX. To make a timer based on the system clock is completely outside the scope of this script and is like requesting a whole different script =p

So in short, no, unfortunately you cannot do that with this script. I think the KCG day/night script has a mode for the system clock though.
Kylock
Updated to 1.3
* $kts.stop now REALLY stops everything (as far as time is concerned)
* Implemented game switch output. Now if you want an event to exist only at night, Just require that Switch 1 is ON. (see script header for more details)
matty0828
Great work!!

I was just wondering...

Is it possible to have a HUD thingy with the time, day or phase outside of the menu? And if so, how would I make it disappear when an event is taking place but reappear when it's over? Like as in if I spoke to somebody it wouldn't be on the screen but when I'm just walking around it would?
Kylock
QUOTE (matty0828 @ May 11 2008, 01:56 AM) *
Great work!!

I was just wondering...

Is it possible to have a HUD thingy with the time, day or phase outside of the menu? And if so, how would I make it disappear when an event is taking place but reappear when it's over? Like as in if I spoke to somebody it wouldn't be on the screen but when I'm just walking around it would?


It's possible, but not supported by the script. The time is easily accessible by other scripts, so if you want a custom HUD, then you'll need to make a request for one =p

It might be something I add later on, but no time soon.
randalbr
Kylock, a question... Is possible to create a event to slow or speed up the "fictional" time in the game? Like the Breath of fire itens, to call the night or the sun?
Kylock
you can use the jump_to command to skip to the night or the day. As far as changing the speed of the clock, at this time the answer is no.
wii19
where i place your script because everywhere i put it the script doesn't work
Kylock
QUOTE (wii19 @ May 16 2008, 04:49 PM) *
where i place your script because everywhere i put it the script doesn't work


Below battle backgrounds if you have them, and above your CMS if you have one. If you don't see the time, then you'll need to modify your CMS to have a time window. You can print the time using $kts.getTime

Even if you don't see anything, it IS still working. Hit F9 in your game to look at the variables and switches to test.
Speed@
this is really a cool system!
vavalar
When I load a saved game I get this message:

"Script 'Kylock's Time System VX 1.3' line 408: EOFError occured:

End of file reached"


Also, is it possible to edit when the time starts so it doesn't always start at night for a new game?


One more thing, whenever I open and close the menu after an autorun event, the event starts over.
slayerofman
I'm sure this script works amazingly, though i can't get mine to operate. I get an error every time i try to test play. I don't think i'm putting it in the right place... you said that i would have to put it after battle backgrounds, and before CMS. i don't think i have either, or i'm not looking in the right places. So, i tried to put it in the script editor, under game objects. and i named it Game_Time (see SS). maybe a little help here?
Kylock
QUOTE (vavalar @ May 18 2008, 11:56 AM) *
When I load a saved game I get this message:

"Script 'Kylock's Time System VX 1.3' line 408: EOFError occured:

End of file reached"


Also, is it possible to edit when the time starts so it doesn't always start at night for a new game?


One more thing, whenever I open and close the menu after an autorun event, the event starts over.


The time is saved with your game. If you saved game was created before you installed the time system, then it doesn't have time. If that makes sense. Basically, only games started AFTER you added this script will work.

The settings for the time of day when the game starts is in the script. Look for:
CODE
  START_HOUR = 0

I will look into the autorun thing.

QUOTE (slayerofman @ May 18 2008, 03:04 PM) *
I'm sure this script works amazingly, though i can't get mine to operate. I get an error every time i try to test play. I don't think i'm putting it in the right place... you said that i would have to put it after battle backgrounds, and before CMS. i don't think i have either, or i'm not looking in the right places. So, i tried to put it in the script editor, under game objects. and i named it Game_Time (see SS). maybe a little help here?


Put it after materials and above main. ANY script you add should be in this place. What you call it is only for your own reference, so Game_Time or whatever, that part won't matter.
Mecha
Nice script Kylock smile.gif

I'm having one issue though where even though a map doesn't have [KTS] in it's name, it's still tinting the map. I've tried everything but it doesn't seem to budge in terms of staying light.

Any help with this issue would be appreciated.
Dann Woolf
Uh, nice script but I have one little question.

I'm using Dargor's Map Name Popup script, so if I use this script, on maps with [KTS] in the name the map name popup will probably say "Map Name [KTS]". Is there anyway to prevent this?
Mecha
QUOTE (Kylock @ May 8 2008, 10:50 PM) *
- The [KTS] that you put in your map names remains hidden to other scripts, like Map Name Popups and such.


Hopefully that answers your question.

Basically, half way through the script a call is made to not show the [KTS] part, therefore this works with any Map Popup Script.

I'm using the one you mentioned just fine smile.gif
Dann Woolf
Excellent! *air guitar solo*

Now, here's another question.

The script uses four switches for night, dawn, day, and sunset, right? But at the start of this thread Kylock makes a sample event using what I assume are not part of aforementioned quadret of switches.

Can't I just use the switches used by the script for events that only appear at certain times?

Also: I'd like to be able to change the bgs in certain areas depending on what time it is, how can I do this?
Bt255
QUOTE (Mecha @ May 24 2008, 08:55 AM) *
Nice script Kylock smile.gif

I'm having one issue though where even though a map doesn't have [KTS] in it's name, it's still tinting the map. I've tried everything but it doesn't seem to budge in terms of staying light.

Any help with this issue would be appreciated.


I'm having the same problem as you. Some of the inside of houses are tinted depending on the time, while others are not, and I only put [KTS] on the outdoor maps so can anyone tell me a solution for this problem? I'm only a noob at scripting but I have the basics to make it work. Thanks.
Dann Woolf
QUOTE (Dann Woolf @ May 25 2008, 03:42 AM) *
Excellent! *air guitar solo*

Now, here's another question.

The script uses four switches for night, dawn, day, and sunset, right? But at the start of this thread Kylock makes a sample event using what I assume are not part of aforementioned quadret of switches.

Can't I just use the switches used by the script for events that only appear at certain times?

Also: I'd like to be able to change the bgs in certain areas depending on what time it is, how can I do this?
Dann Woolf
QUOTE (Dann Woolf @ May 27 2008, 02:58 AM) *
QUOTE (Dann Woolf @ May 25 2008, 03:42 AM) *
Excellent! *air guitar solo*

Now, here's another question.

The script uses four switches for night, dawn, day, and sunset, right? But at the start of this thread Kylock makes a sample event using what I assume are not part of aforementioned quadret of switches.

Can't I just use the switches used by the script for events that only appear at certain times?

Also: I'd like to be able to change the bgs in certain areas depending on what time it is, how can I do this?



While I hate double-posting, I really need to know this.
maker2008
thanks.gif
Dann Woolf
Never mind, I changed my mind, I'm not using this script anymore.
mystic0008
Hi, I was just wondering if there was any reason why you included day names in the script? I must be blind or something 'cus i haven't actually seen them anywhere...anyway, it's not an urgent question I was just wondering, cheers.
Kylock
QUOTE (Dann Woolf @ May 25 2008, 07:42 AM) *
Excellent! *air guitar solo*

Now, here's another question.

The script uses four switches for night, dawn, day, and sunset, right? But at the start of this thread Kylock makes a sample event using what I assume are not part of aforementioned quadret of switches.

Can't I just use the switches used by the script for events that only appear at certain times?

Also: I'd like to be able to change the bgs in certain areas depending on what time it is, how can I do this?


Yes, the sample event in my first post was created before I added those switches to the script. They sure do make life easier, but I left the sample pictures there so that people could understand how the script works and can be used.


QUOTE (mystic0008 @ May 31 2008, 12:25 PM) *
Hi, I was just wondering if there was any reason why you included day names in the script? I must be blind or something 'cus i haven't actually seen them anywhere...anyway, it's not an urgent question I was just wondering, cheers.

No reason at all. You can use them if you want, as the day can be sent to a variable, but they really aren't used for anything important.
mystic0008
Ah, good to know. Now....I have a problem.

I am currently using your script and I am getting the weirdest problem, it doesnt matter wether I have put [KTS] in the map name, the map still gets auto-tinted and through testing I have found out that this only occurs if the start of the map name is a capital letter so if I made a map name Store it would auto tint but if it was store it wouldn't. I understand this sounds weird but it is happening, any help would be appreciated, cheers again.
Kylock
QUOTE (mystic0008 @ Jun 3 2008, 02:05 AM) *
Ah, good to know. Now....I have a problem.

I am currently using your script and I am getting the weirdest problem, it doesnt matter wether I have put [KTS] in the map name, the map still gets auto-tinted and through testing I have found out that this only occurs if the start of the map name is a capital letter so if I made a map name Store it would auto tint but if it was store it wouldn't. I understand this sounds weird but it is happening, any help would be appreciated, cheers again.



I'm unsure what the patten is, but capitol letters isn't it. I'm aware of the problem, but have no idea why it's happening. All my maps start with capitol letters, but it's only tinting one that it's supposed to. Changing the name of the map in any way seems to make it work, but I don't know what the problem is, since I can't seem to determine any sort of method or pattern to which maps are being tinted.

[edit]
Updated to 1.5

# 1.4 - Fixed Battle Test compatibility (simulates normal daylight for battle
# test instead of darkness).
# Now switches and variables will only update when the map loads so that
# events don't suddenly dissappear when their time is up.
# Added $kts_anti_tone - returns an inverse tone color to allow sprites
# to appear normally on a tinted screen.
# 1.5 - Rewrote the regexp that finds the [KTS] in the map name. Hopefully
# this resolves the wrong maps being tinted problem.
Mecha
This is working great for me so far. Maps that would tint without permission no longer do so (without any need to change Map Name), nice one Kylock smile.gif

Funnily enough though, I did try the smaller case trick and it did work. I found that rather random, but a fix is a fix as they say.

Thanks again thumbsup.gif
Kylock
QUOTE (Mecha @ Jun 3 2008, 04:11 PM) *
This is working great for me so far. Maps that would tint without permission no longer do so (without any need to change Map Name), nice one Kylock smile.gif

Funnily enough though, I did try the smaller case trick and it did work. I found that rather random, but a fix is a fix as they say.

Thanks again thumbsup.gif


I'm glad to hear that it worked for someone other than myself. Due to the nature of the issue, it's hard to know weather or not it's really fixed until many people test it.
mystic0008
Ths new version is working fine now so good work with that.

A good script and thanks for making it Kylock,
cheers.
slayerofman
QUOTE (Kylock @ May 19 2008, 08:51 PM) *
QUOTE (vavalar @ May 18 2008, 11:56 AM) *
When I load a saved game I get this message:

"Script 'Kylock's Time System VX 1.3' line 408: EOFError occured:

End of file reached"


Also, is it possible to edit when the time starts so it doesn't always start at night for a new game?


One more thing, whenever I open and close the menu after an autorun event, the event starts over.


The time is saved with your game. If you saved game was created before you installed the time system, then it doesn't have time. If that makes sense. Basically, only games started AFTER you added this script will work.

The settings for the time of day when the game starts is in the script. Look for:
CODE
  START_HOUR = 0

I will look into the autorun thing.

QUOTE (slayerofman @ May 18 2008, 03:04 PM) *
I'm sure this script works amazingly, though i can't get mine to operate. I get an error every time i try to test play. I don't think i'm putting it in the right place... you said that i would have to put it after battle backgrounds, and before CMS. i don't think i have either, or i'm not looking in the right places. So, i tried to put it in the script editor, under game objects. and i named it Game_Time (see SS). maybe a little help here?


Put it after materials and above main. ANY script you add should be in this place. What you call it is only for your own reference, so Game_Time or whatever, that part won't matter.


sorry it took so long to reply. I eventually found that out, but thanks for the push in the right direction!
bausa
I put the script into my game and everything seems to be working great. I have a time clock in my menu that goes to the pace and time I set it at. However, I am not seeing any change in the screen. Am I missing a step here? How do I get the screen to change?
Kylock
QUOTE (bausa @ Jun 9 2008, 03:50 AM) *
I put the script into my game and everything seems to be working great. I have a time clock in my menu that goes to the pace and time I set it at. However, I am not seeing any change in the screen. Am I missing a step here? How do I get the screen to change?

The only thing that would prevent the screen tone from changing is if you changed
CODE
  USE_TONE = true

or if you didn't put [KTS] in the name of your outdoor maps.
Da Bee
Is it possible to have certain events happen depending on what day it is, rather than what time it is?

Also, when I go to the left or right on my screen, I often see something... like a wave moving up the screen. And it keeps happening, ever since I installed this system. Any ideas on what's causing it?

And one final thing; any events I create using the day/night system, they don't update unless I pause and then unpause. It's kinda annoying that in order for the night lamps to switch on I have to pause the game. Speaking of which, is there also a way to stop time when you pause the game?
sargunster
in the map names do i put KTS or [KTS]?
EDIT: nvm figured it out laugh.gif
sargunster
amazing!
is this the final or will you add furthur updates?
and for the the events only happening at night i have to pause, then unpause
could you fix this?
i really need to know now...
wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif
Kylock
QUOTE (sargunster @ Jun 12 2008, 11:08 PM) *
amazing!
is this the final or will you add furthur updates?
and for the the events only happening at night i have to pause, then unpause
could you fix this?
i really need to know now...
wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif wallbash.gif


Events are only scanned for conditions when the map is loaded and event page conditions are evaluated. This is part of how rpg maker works. I don't see this as something that needs to be "fixed" with this script.

As far as when time periods change, these are updated when maps are reloaded as well. Without that, events, such as people just sort of appear and disappear and this doesn't give any game a very polished feel.

As far as your issue with pausing... not sure what it is exactly that you are doing to "pause" the game, but use these functions: 'Script: $kts.stop' and 'Script: $kts.go' They can be called from events or other scripts. This system shouldn't be so difficult to incorporate into other system or function scripts.... at all.

To answer the question about updates, this can be considered final unless bugs are discovered or someone recommends a feature that makes sense. I have no plans to integrate "weather effects" or "shadow effects" type systems. Day/Night and Time are enough. The game switches can be treated as global variables for the purposes of making other scripts that can use the time to function. I believe there is a certain amount of features that a person can add to a script to make it so that it's not as useful to everyone as it would be were it not so basic. I hope this makes sense...
andani
Thanks Kylock for this amazing script. I will more than likely use this for my RPG. I also like your light effect system. Very nice.
rgangsta
QUOTE (Kylock @ May 8 2008, 10:50 PM) *
Kylock's Time System VX 1.5
by Kylock


This script will track game time as well as automatically tint the screen for a day/night effect.
You can make events dependent on time thanks to game variable output support.
You can customize how dark you want it to be at what time.
You can designate certain maps as "outside" so they are the only ones that are dark at night! (Add [KTS] to map name.)
You can choose the speed of your game's clock.
Because the entire time system is an object, its possible to instance or have more than one game clock. PM me for details if you really need this functionality.

Detailed installation and script usage instructions are included in the script header, just like all my other scripts. The usage is VERY similar to the XP version that I wrote over a year ago - if you are familiar with it at all.

To answer a few question before they are asked:
- I am not including weeks, months and years because it gets too complicated when you have a different amount of days in each month for example. The primary intention of this script is to allow you to build your events based on hours in the day and time periods throughout the day. (Ex: The time-locked vault can only be opened between 2 and 3. or The guy with the password can only be found drinking in the bar at midnight.)
- The [KTS] that you put in your map names remains hidden to other scripts, like Map Name Popups and such.
- For script compatibility reasons, if you use a CMS, you might get better results if this script is located ABOVE your CMS. If you have a CMS and want a time window added to it, this is a really easy hack for any scripter, so please make a request in the appropriate Script Requests Forum.
- There are no screenshots because that would be pointless. You can define your own screen tones and there is an added window for time right above the gold window in the default menu. That's all there is, I promise!

Now, the script itself:


CODE
#==============================================================================
# ■ Kylock's Time System VX 1.5
#     6.3.2008
#------------------------------------------------------------------------------
#  Script by: Kylock
#==============================================================================
#    Mostly rewritten since XP version.  Cleaner code and less intrusive (more
#  compatible).  This is my comprehensive time and day/night system.  This
#  script adds a new window to the game menu, so if you use a CMS, then place
#  this script ABOVE it so that it won't mess up your CMS.  If you use a custom
#  script that makes changes to the battle background, place KTS below it so
#  that you don't get the delayed-tone effect in you battles.  Other than that,
#  there shouldn't be any other script compatibility issues.
#    I've tried to make this script as customizable as possible, the settings
#  are found immediately following this header.  Although time output to game
#  variables is optional, I strongly suggest using it so that its easier to
#  build your events based on the time in the game.
#==============================================================================
# ● Change Log
#------------------------------------------------------------------------------
#  1.0 - Original Release.
#  1.1 - Corrected tinting issue at the start of a battle.  Place this script
#          below any battle background scripts if you experience "jumpy tinting"
#  1.2 - Corrected the accuracy of $kts.stop and $kts.go
#  1.3 - $kts.stop really stops everything now.  Also added game switches for
#          even easier eventing.
#  1.4 - Fixed Battle Test compatibility (simulates normal daylight for battle
#          test instead of darkness).
#        Now switches and variables will only update when the map loads so that
#          events don't suddenly dissappear when their time is up.
#        Added $kts_anti_tone - returns an inverse tone color to allow sprites
#          to appear normally on a tinted screen.
#  1.5 - Rewrote the regexp that finds the [KTS] in the map name.  Hopefully
#          this resolves the wrong maps being tinted problem.
#==============================================================================
# ● Auto-tone Instructions
#------------------------------------------------------------------------------
#    Maps designated as outdoors are the only maps to be affected by this
#  scripts use of auto-toning.  To signify a map to be "outdoors", you must
#  include [KTS] In the name of the map.  For example, you world map could be
#  named "World Map [KTS]" or "[KTS] World Map".  Provisions are made later in
#  the script to remove [KTS] from the map name when it's read by another
#  script.  This means that "[KTS]" won't show up in your Map Name Popup
#  windows.
#==============================================================================
# ● Script Function Calls
#------------------------------------------------------------------------------
#    The following are script commands that can be executed by using the
#  "Script..." command in your events.
#    ● $kts.stop            - Stops time (can be used for cutscenes)
#    ● $kts.go              - Resumes time (don't forget to use this!)
#    ● $kts.sec(n)          - progresses time forward (n) seconds
#    ● $kts.min(n)          - progresses time forward (n) minutes
#    ● $kts.hours(n)        - progresses time forward (n) hours
#    ● $kts.days(n)         - progresses time forward (n) days
#    ● $kts.jump_to_hour(n) - progresses time forward TO the specified hour.
#                             Particularly useful in a situation where you
#                             want a certain event to happen at a certain time,
#                             or an Innkeeper who should wake the party up at
#                             a certain hour.  This command MAY cause your game
#                             to appear to freeze for a few seconds on slower
#                             computers.
#==============================================================================
# ● Game Database Setup
#------------------------------------------------------------------------------
#    This script, by defult, uses the following game variables and switches:
#  Database Variables:
#    [1] The Current Time            [4] The Current Hour
#    [2] The Current Second          [5] The Current Day
#    [3] The Current Minute          [6] Name of the Current Day
#  Database Switches
#    [1] ON during night hours   (2200-0400)(10pm-4am)
#    [2] ON during dawn hours    (0500-0800)( 5am-8am)
#    [3] ON during daytime hours (0900-1800)( 9am-6pm)
#    [4] ON during sunset hours  (1900-2100)( 7pm-9pm)
#==============================================================================

#==============================================================================
# Stores variables and user defined settings for the time system.
#==============================================================================
module KTS
  #-----------------------------------------------------------------------
  # User Definable Clock Settings
  #-----------------------------------------------------------------------
  # Sets the speed multiplier of the clock.  1 is real time.  A higher
  #   value will give you a faster clock.  Default is 100.
  SPEED      = 100
  #AMPM (True: 12-hour clock, False: 24-hour clock)
  AMPM       = false
  # Sets the time at the start of your game.
  START_HOUR = 1
  START_DAY  = 1
  #-----------------------------------------------------------------------
  # If you want custom day names, edit away!
  #-----------------------------------------------------------------------
  DAY_NAMES = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
  #-----------------------------------------------------------------------
  # Settings for Time Periods
  #-----------------------------------------------------------------------
  T1 = [ 0,5 ] # Night         # Sets time periods for tinting effects
  T2 = [ 6,8 ] # Dawn          # [Start Hour, End Hour] for time period
  T3 = [ 9,18] # Day           # Use 24-hour values for time periods
  T4 = [19,21] # Sunset
  T5 = [22,24] # Night         # <- Ex: Night is between 23:00 and 24:00
  #-----------------------------------------------------------------------
  # Settings for Output to Game Variables option.
  #-----------------------------------------------------------------------
  # Set this to true to output the current time to game variables.
  DATABASE_OUTPUT = true
    # Game Variable to be used for time output.
    TIME    = 1 #(Time in string format. Ex: "2:48 AM" or "02:48")
    SECONDS = 2
    MINUTES = 3
    HOURS   = 4
    DAYS    = 5
    DAYNAME = 6
    # Game Switches to be used for time output.
    NIGHT   = 1 # This switch is on during night hours   (2200-0400)(10pm-4am)
    DAWN    = 2 # This switch is on during dawn hours    (0500-0800)( 5am-8am)
    DAY     = 3 # This switch is on during daytime hours (0900-1800)( 9am-6pm)
    SUNSET  = 4 # This switch is on during sunset hours  (1900-2100)( 7pm-9pm)
  #-----------------------------------------------------------------------
  # Settings for time controlled screen toning
  #-----------------------------------------------------------------------
  # True will enable screen toning to be used by the script.
  USE_TONE = true
  # Sets the duration of tone changes (in frames)
  FADE_LENGTH = 120
  # Defines tones to be used in the corresponding time periods defined above.
  #              RED, GREEN, BLUE, GREY
  C1 = Tone.new(-187,  -119,  -17,  68)
  C2 = Tone.new(  17,   -51, -102,   0)
  C3 = Tone.new(   0,     0,    0,   0)
  C4 = Tone.new( -68,  -136,  -34,   0)
  C5 = Tone.new(-187,  -119,  -17,  68)
  # Defines anti-tones
  A1 = Tone.new( 187,   119,   17, -68)
  A2 = Tone.new( -17,    51,  102,   0)
  A3 = Tone.new(   0,     0,    0,   0)
  A4 = Tone.new(  68,   136,   34,   0)
  A5 = Tone.new( 187,   119,   17, -68)
end

#==============================================================================
# Core Time System Engine
#==============================================================================
class Kylock_Time_System
  # sets instance variables
  def initialize
    $kts_map_data = load_data("Data/MapInfos.rvdata")
    @event_offset = (KTS::START_HOUR * 3600) + (KTS::START_DAY * 86400)
    @kts_stop = false
    $kts_event_tone = false
    $kts_battle_tone = true
    $kts_anti_tone = Tone.new(0,0,0,0)
  end
  
  # Computes current time and updates variables if used
  def update
    if !@kts_stop
      @total_seconds = (Graphics.frame_count * KTS::SPEED / 60) + @event_offset
      @seconds = (@total_seconds) % 60
      @minutes = (@total_seconds / 60) % 60
      @hours   = (@total_seconds / 3600) % 24
      @days    = (@total_seconds / 86400)
      update_tint
      if KTS::DATABASE_OUTPUT
        $game_variables[KTS::TIME]    = getTime
      end
    end
  end

  def update_variables
    $game_variables[KTS::SECONDS] = @seconds
    $game_variables[KTS::MINUTES] = @minutes
    $game_variables[KTS::HOURS]   = @hours
    $game_variables[KTS::DAYS]    = @days
    $game_variables[KTS::DAYNAME] = getDayName
  end

  def update_switches
    if @period == 1 || @period == 5
      $game_switches[KTS::NIGHT] = true
    else
      $game_switches[KTS::NIGHT] = false
    end
    if @period == 2
      $game_switches[KTS::DAWN] = true
    else
      $game_switches[KTS::DAWN] = false
    end
    if @period == 3
      $game_switches[KTS::DAY] = true
    else
      $game_switches[KTS::DAY] = false
    end
    if @period == 4
      $game_switches[KTS::SUNSET] = true
    else
      $game_switches[KTS::SUNSET] = false
    end
  end

  def getTime
    if KTS::AMPM
      # Formats a 12-Hour Clock
      if @hours > 12
        hours1 = @hours - 12
        if hours1 > 9
          time = sprintf("%02d:%02d" + " PM", hours1, @minutes)
        else
          time = sprintf("%01d:%02d" + " PM", hours1, @minutes)
        end
      else
        if @hours > 9
          time = sprintf("%02d:%02d" + " AM", @hours, @minutes)
        else
          time = sprintf("%01d:%02d" + " AM", @hours, @minutes)
        end
      end
      return time
    else
      # Formats a 24-Hour Clock
      time = sprintf("%02d:%02d", @hours, @minutes)
      return time
    end
  end
  #-----------------------------------------------------------------------
  # Script Command Functions
  #-----------------------------------------------------------------------
  def stop
    @time_stopped = @total_seconds
    @kts_stop = true
  end
  def go
    total_seconds = (Graphics.frame_count * KTS::SPEED / 60) + @event_offset
    @event_offset -= (total_seconds - @time_stopped)
    @kts_stop = false
  end
  def sec(sec = 0)
    @event_offset += sec
  end
  def min(min = 0)
    @event_offset += min * 60
  end
  def hours(hours = 0)
    @event_offset += hours * 3600
  end
  def days(days = 0)
    @event_offset += days * 86400
  end
  def jump_to_hour(jhour = 0)
    while @hours != jhour
      @event_offset += 1
      $kts.update
    end
  end
  #-----------------------------------------------------------------------
  # Script Support/Misc Functions
  #-----------------------------------------------------------------------
  def getDayName
    weekday = (@days % KTS::DAY_NAMES.length)
    return KTS::DAY_NAMES[weekday]
  end

  #-----------------------------------------------------------------------
  # Screen Tone Functions
  #-----------------------------------------------------------------------
  def update_tint(duration = KTS::FADE_LENGTH)
    return if $BTEST
    if KTS::USE_TONE && !$kts_event_tone && $kts_map_data[$game_map.map_id].outside_tint?
      if @hours >= KTS::T1[0] and @hours <= KTS::T1[1]
        @period = 1
        screen.start_tone_change(KTS::C1,duration)
        $kts_anti_tone = KTS::A1
      elsif @hours >= KTS::T2[0] and @hours <= KTS::T2[1]
        @period = 2
        screen.start_tone_change(KTS::C2,duration)
        $kts_anti_tone = KTS::A2
      elsif @hours >= KTS::T3[0] and @hours <= KTS::T3[1]
        @period = 3
        screen.start_tone_change(KTS::C3,duration)
        $kts_anti_tone = KTS::A3
      elsif @hours >= KTS::T4[0] and @hours <= KTS::T4[1]
        @period = 4
        screen.start_tone_change(KTS::C4,duration)
        $kts_anti_tone = KTS::A4
      elsif @hours >= KTS::T5[0] and @hours <= KTS::T5[1]
        @period = 5
        screen.start_tone_change(KTS::C5,duration)
        $kts_anti_tone = KTS::A5
      end
    else
      # no tone if indoors
      if !$kts_map_data[$game_map.map_id].outside_tint?
        screen.start_tone_change(Tone.new(0,0,0,0),duration)
      end
    end
  end
  def screen
    if $game_temp.in_battle
      return $game_troop.screen
    else
      return $game_map.screen
    end
  end
end

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias kts_initialize initialize
  def initialize
    $kts.update_switches if !@kts_stop && KTS::DATABASE_OUTPUT
    $kts.update_variables if !@kts_stop && KTS::DATABASE_OUTPUT
    kts_initialize
  end
end

#==============================================================================
# Instantly updates screen tone when a new map is loaded.
#==============================================================================
class Game_Map
  alias kts_setup setup
  def setup(map_id)
    kts_setup(map_id)
    $kts_event_tone = false
    $kts.update
    $kts.update_tint(0)
  end
end

#==============================================================================
# Instantly updates screen tone when a battle starts.
#==============================================================================
class Spriteset_Battle
  alias kts_create_battleback create_battleback
  def create_battleback
    $kts.update_tint(0)
    kts_create_battleback
  end
end

#==============================================================================
# Temporarily disables auto-toning if an event tints the screen.
#==============================================================================
class Game_Interpreter
  alias kts_Interpreter_command_223 command_223
  def command_223
    $kts_event_tone = true
    kts_Interpreter_command_223
  end
end

#==============================================================================
# Integrates the Time System into the Game System.
#==============================================================================
class Game_System
  # inits a KTS object
  alias kts_initialize initialize
  def initialize
    $kts=Kylock_Time_System.new
    kts_initialize
  end
  # Updates kts every game frame
  alias kts_update update
  def update
    $kts.update
    kts_update
  end
end

#==============================================================================
# Scans Map Names for Toning
#==============================================================================
class RPG::MapInfo
  def name # Definition prevents location scripts from reading anything within
    return @name.gsub(/\[.*\]/) {""} # brackets, including the brackets
  end
  def original_name
    return @name
  end
  def outside_tint?
    return @name.scan(/\[KTS\]/).size > 0
    # old regexp: return @name.scan(/[\KTS]/).size > 0
  end
end

#==============================================================================
# Sets up the time window for the menu.
#==============================================================================
class Window_KTS < Window_Base
  def initialize(x, y)
    super(x, y, 160, WLH + 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.draw_text(4, -6, 120, 32, $kts.getTime, 2)
  end
  def update
    super
    $kts.update
    self.contents.clear
    self.contents.draw_text(4, -6, 120, 32, $kts.getTime, 2)
  end
end

#==============================================================================
# Adds the time window to the menu.
#==============================================================================
class Scene_Menu < Scene_Base
  alias kts_start start
  def start
    kts_start
    @kts_window = Window_KTS.new(0,305)
  end
  alias kts_terminate terminate
  def terminate
    kts_terminate
    @kts_window.dispose
  end
  alias kts_update update
  def update
    kts_update
    @kts_window.update
  end
end

#==============================================================================
# Saves and Loads game time to/from save game file.
#==============================================================================
class Scene_File
  alias kts_write_save_data write_save_data
  def write_save_data(file)
    kts_write_save_data(file)
    Marshal.dump($kts, file)
  end
  alias kts_read_save_data read_save_data
  def read_save_data(file)
    kts_read_save_data(file)
    $kts = Marshal.load(file)
  end
end



[Show/Hide] Sample Event

For my example, I'll make a set of events that only exist at night after 9pm and 5am.
First, make a common event that looks like this:

You'll notice that Switch 9 has to be on for this event to work, so you need to make sure that you turn it on before any important maps show up. So maybe turn on Switch 9 in your game opening sequence.

Now, for any event you want to show up only at night, all you have to do is this:


Piece of cake for any self-proclaimed eventers out there!


I am open to requests not covered above.

Enjoy,
Kylock

i no this might be stupid to ask but where do i put the script? huh.gif
toboisgreat
~Hello~
Im thinking of making a Harvest moon game for Vx and I've got all the rest of the things pretty much sorted in my head but I don't think I could implement the Days/Seasons with this script and events alone. Is there any way that this script could be adjusted to add a function that resets the Time, so that when you go to sleep time reverts back to 6.00 or whatever. I think I may be able to do the seasons with variables and events but it will be alot of work. Could this possibly be done with the script?
Thank you for your time.
~Toboisgreat~

drebenk
I get this error when I enter a battle and kill an enemy:



Here is what it is on line 839 in Game_Interpreter: $game_variables[i] -= value

So is this a problem from the scirpt or the Interpreter?
doobyman
This System Worked Great, Until I Tried To Enter The Skills Section In The Menu. Then It Told Me There Was A
Error Line 332 Unidentified 'Dispose' Im Not Shore If It Is One Of The Other Scrips I Have Doing It But I Just
Wanted To Know If Any One Else Had This Prob And No How To Fix Her.
YanXie
@drebenk :

I don't think it's the problem on the Game_Interpreter, rather it's the time script that did this.

Rather what seem causing is this script. Looks like it happened because 21:15 is a string, rather than interger, thus the interpreter couldn't subtract it(the interpreter can only substract interger)

@doobyman :

It isn't caused by this script, since this script didn't use any dispose method for windows, and it didn't modify anthing involving Skill Screen script at all. Try to look what you have in your script editor.

cheers, puppeto4. smile.gif
ell
Hi its a great script but I was just wondering does it automaticly turn on the "on during night" switch or do you have to do it with conditional branches in a common event?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.