Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Kylock's Time System Quick fix

I need an edit of this script that turns on a switch in different time blocks of 3 hours.
ex.6-9 (switch 8 off,switch 1 on)
9-12(switch 1 off, 2 on)
12-3(switch 2 off, 3 on)
and so on...
3-6(switch 7 off switch 8 on)

Thank you very much,


Code:
#==============================================================================
# Kylock's Time System
#==============================================================================
# Kylock
# Version 1.3
# 10-22-2006
#------------------------------------------------------------------------------
# Based in small parts from Dubealex's ATS and VERY small parts of
# mikah's Time Day/Night System.
#==============================================================================
# What it does!
#   Game Time will be displayed in the Play Time window.
#   Current day will be displayed in the Steps Window
#
# Script assumes 1m=60s 1h=60m 1d=24h
# If you use game variables, hours are stored in the 24-hr format
# Also note that time CANNOT be controlled by setting the variables, they are
#   updated(constantly) only.
#==============================================================================
# To adjust game time from the game (commands identical to Dube's ATS):
#     "Script: $kts.hours(5)"  <- Advances time by 5 hours
#     "Script: $kts.hours(-5)" <- Rewinds time by 5 hours
# Available clock adjustment methods:
#  $kts.stop        - Stops time (can be used for cutscenes)
#  $kts.go          - Resumes Time (if time is not stopped, no effect)
#  $kts.sec(n) - skips secs # Note that while the clock still appears to run
#  $kts.min(n) - skips nims # after $kts.stop, when you execute $kts.go, it will
#  $kts.hours(n)-skips hrs  # revert to the time when it was stopped.
#  $kts.days(n) - skips days
#  $kts.inn_rest(n) - Advances the clock FORWARD to time specified (use 24-hour notation)
#    Example: It's 06:08 => $kts.inn_rest(7) => Time is now 07:00 same day
#    Example: It's 06:08 => $kts.inn_rest(6) => Time is now 06:00 the next day
#    Could be used for anything, but practically limited to immediate 24 hours.
#    .inn_rest may also cause a couple seconds of lag when used on slower
#    systems.
#==============================================================================
# Default varialbes for time output:
# Variables: [1] Clock Seconds
#            [2] Clock Minutes
#            [3] Clock Hours
#            [4] Clock Days
#            [5] Day Name (for events based on day of week)
# To control screen tinting, place[*] in the name of your outdoor maps.  This
# will enable tinting.
#==============================================================================
# Release Notes:
#
#   1.3 - Several bugs related to the auto-tinting feature have been fixed
#           thanks to the dilliget whining- er I mean bug reporting of
#           Mike Portnoy on the rmxp.org forums. =P
#
#   1.2 - Modified the tint code so that there would be smoother tinting during
#           transitions from indoor to outdoor[*] areas and vice versa.  You
#           will no longer see situations where you see the normal tone, then
#           a quick switch to the outdoor tone.  It's much smoother and less
#           jittery looking now.
#       - Added global variable $kts_current_tone that stores the current tone
#           formatted as: Tone.new(x,x,x,x) This is useful for setting the tone
#           for pictures and sprites in outdoor areas for uniformity purposes.
#       - Fixed a bug that completely killed event driven tinting when indoors.
#
#   1.1 - Removed dependancy on a game switch to determine indoor/outdoor area
#           status.  Now you simply have to add "•" to the name of outdoor 
#           areas.
#
#   1.0 - Original release.
#==============================================================================

$data_map = load_data("Data/MapInfos.rxdata")

class Kylock_Time
  
  #========================
  # Configuration Settings
  #========================
  def initialize
    @start_clock = 19       # in hours (24-hr format) - First hour of your game
    @start_day = 1           # in days                 - First day of your game
    @clock_speed = 10        # in frames (default: 30) - 0 = real time
    @clock_ampm = true      # time display setting: true = 12 hr clock

    #===========================
    # Script-controlled Tinting
    #===========================
    # To use auto-tinting, place "•" in tht name of your outdoors maps.
    # Example: "Outdoors[*]" will get tinting, but "Outdoors" or 
    # "Outdoors[BLAH]" will not.
    $tint_during_battle = true      # If set to false, battles will have no tint
                                    # may slightly reduce battle lag
    
    @t1 = [4, 7]   # Early Morning  # Sets time periods for tinting effects
    @t2 = [8, 11]  # Morning        # [Start Hour, End Hour] for time period
    @t3 = [12, 18] # Day            # Use 24-hour values for time periods
    @t4 = [18, 22] # Evening
    @t5 = [23, 3] # Night          # <- Ex: Night is between 23:00 and 24:00

    @c1 = [-187, -119, -17, 68, 20] # Defines tints to be used in time periods
    @c2 = [17, -51, -102, 0, 20]    # defined above.
    @c3 = [0, 0, 0, 0, 20]          # [Red, Green, Blue, Grey, Time(in frames)]
    @c4 = [-68, -136, -34, 0, 20]  
    @c5 = [-187, -119, -17, 68, 20]

    #==========================================
    # If you want custom day names, edit away!
    #==========================================
    @day_name = ["Sandi","Mandei","Tiuzdi","Wednzdi","Terzdi","Fraidi","Saterdei"]
    
    #====================================
    # Time System: Game Variable Options
    #====================================
    @use_vars = true      # assign time to game play variables
    @sec_var = 1          # Variable to which to store Seconds
    @min_var = 2          # Variable to which to store Minutes
    @hr_var = 3   # Variable to which to store Hours (stored using 24-hr format)
    @day_var = 4          # Variable to which to store Days
    @weekday_var = 5      # Variable to which to store Name of the Day
    
    #==============================================
    # Used for time adjustments called from events
    #==============================================
    @game_time_offset = (@start_clock * 3600) + (@start_day * 86400)
    $kts_tint_update_pause = false
  end

  #========================
  #  End of Configuration
  #========================

  def update
    # Calculate total number of seconds
    @total_seconds = (Graphics.frame_count / (Graphics.frame_rate - @clock_speed)) + @game_time_offset
    
    # Calculate seconds, minutes, hours and days
    total_minutes = @total_seconds / 60
    total_hours = @total_seconds / 3600
    @total_days =  @total_seconds / 86400
    @clock_seconds = @total_seconds % 60
    @clock_minutes = total_minutes % 60
    @clock_hours = total_hours % 24

    # Update Game Variables if used
    if @use_vars
      $game_variables[@sec_var] = @clock_seconds
      $game_variables[@min_var] = @clock_minutes
      $game_variables[@hr_var] = @clock_hours
      $game_variables[@day_var] = @clock_days
      $game_variables[@weekday_var] = today_name
    end
  end

  def update_tint
    #updates screen tinting
    if $data_map[$game_map.map_id].outside_tint? and $kts_tint_update_pause == false
      if @clock_hours >= @t1[0] and @clock_hours <= @t1[1]
        $game_screen.start_tone_change(Tone.new(@c1[0],@c1[1],@c1[2],@c1[3]),@c1[4])
        $kts_current_tone = Tone.new(@c1[0],@c1[1],@c1[2],@c1[3])
      elsif @clock_hours >= @t2[0] and @clock_hours <= @t2[1]
        $game_screen.start_tone_change(Tone.new(@c2[0],@c2[1],@c2[2],@c2[3]),@c2[4])
        $kts_current_tone = Tone.new(@c2[0],@c2[1],@c2[2],@c2[3])
      elsif @clock_hours >= @t3[0] and @clock_hours <= @t3[1]
        $game_screen.start_tone_change(Tone.new(@c3[0],@c3[1],@c3[2],@c3[3]),@c3[4])
        $kts_current_tone = Tone.new(@c3[0],@c3[1],@c3[2],@c3[3])
      elsif @clock_hours >= @t4[0] and @clock_hours <= @t4[1]
        $game_screen.start_tone_change(Tone.new(@c4[0],@c4[1],@c4[2],@c4[3]),@c4[4])
        $kts_current_tone = Tone.new(@c4[0],@c4[1],@c4[2],@c4[3])
      elsif @clock_hours >= @t5[0] and @clock_hours <= @t5[1]
        $game_screen.start_tone_change(Tone.new(@c5[0],@c5[1],@c5[2],@c5[3]),@c5[4])
        $kts_current_tone = Tone.new(@c5[0],@c5[1],@c5[2],@c5[3])
      end
    else
      $kts_current_tone = Tone.new(0,0,0,0)
    end
  end
  
  def instant_tint
    #updates screen tinting
    if $data_map[$game_map.map_id].outside_tint? and $kts_tint_update_pause == false
      $kts_manual_tone = false
      if @clock_hours >= @t1[0] and @clock_hours <= @t1[1]
        $game_screen.start_tone_change(Tone.new(@c1[0],@c1[1],@c1[2],@c1[3]),0)
        $kts_current_tone = Tone.new(@c1[0],@c1[1],@c1[2],@c1[3])
      elsif @clock_hours >= @t2[0] and @clock_hours <= @t2[1]
        $game_screen.start_tone_change(Tone.new(@c2[0],@c2[1],@c2[2],@c2[3]),0)
        $kts_current_tone = Tone.new(@c2[0],@c2[1],@c2[2],@c2[3])
      elsif @clock_hours >= @t3[0] and @clock_hours <= @t3[1]
        $game_screen.start_tone_change(Tone.new(@c3[0],@c3[1],@c3[2],@c3[3]),0)
        $kts_current_tone = Tone.new(@c3[0],@c3[1],@c3[2],@c3[3])
      elsif @clock_hours >= @t4[0] and @clock_hours <= @t4[1]
        $game_screen.start_tone_change(Tone.new(@c4[0],@c4[1],@c4[2],@c4[3]),0)
        $kts_current_tone = Tone.new(@c4[0],@c4[1],@c4[2],@c4[3])
      elsif @clock_hours >= @t5[0] and @clock_hours <= @t5[1]
        $game_screen.start_tone_change(Tone.new(@c5[0],@c5[1],@c5[2],@c5[3]),0)
        $kts_current_tone = Tone.new(@c5[0],@c5[1],@c5[2],@c5[3])
      end
    else
      if $kts_manual_tone == false
        $game_screen.start_tone_change(Tone.new(0,0,0,0),0)
        $kts_current_tone = Tone.new(0,0,0,0)
      end
    end
  end

  # Returns the name of the current day  
  def today_name
    weekday = (@total_days % @day_name.length)
    return @day_name[weekday]
  end
  
  # Returns the number of the current day
  def game_days
    return @total_days.to_s
  end
  
  # Formats the time string  
  def time
    if @clock_ampm
      # Formats 12-hour clock
      if @clock_hours > 12
        clock_hours_ampm = @clock_hours - 12
        if clock_hours_ampm > 9
          time = sprintf("%02d:%02d" + " PM", clock_hours_ampm, @clock_minutes)
        else
          time = sprintf("%01d:%02d" + " PM", clock_hours_ampm, @clock_minutes)
        end
        return time
      else
        if @clock_hours > 9
          time = sprintf("%02d:%02d" + " AM", @clock_hours, @clock_minutes)
        else
          time = sprintf("%01d:%02d" + " AM", @clock_hours, @clock_minutes)
        end
        return time
      end
    else
      # Formats 24-hour clock
      time = sprintf("%02d:%02d" + " ", @clock_hours, @clock_minutes)
      return time
    end
  end
  
  # Manual clock adjustment methods  
  def stop
    #capture stopping point
    @time_stopped = @total_seconds
  end

  def go
    #determine time passage while time was stopped and compensate using offset
    @total_seconds = (Graphics.frame_count / (Graphics.frame_rate - @clock_speed)) + @game_time_offset
    @game_time_offset -= @total_seconds - @time_stopped
  end

  def sec(sec = 0)
    @game_time_offest += sec
  end
  
  def min(min = 0)
    @game_time_offset += min * 60
  end
  
  def hours(hours = 0)
    @game_time_offset += hours * 3600
  end  
  
  def days(days = 0)
    @game_time_offset += days * 86400
  end
  
  def inn_rest(inn_time = 0)
    while @clock_hours != inn_time
      @game_time_offset += 1
      total_seconds = (Graphics.frame_count / (Graphics.frame_rate - @clock_speed)) + (@start_clock * 3600) + (@start_day * 86400) + @game_time_offset
      @clock_hours = total_seconds / 3600 % 24
    end
  end
end

class Interpreter
  #--------------------------------------------------------------------------
  # * Change Screen Color Tone
  #--------------------------------------------------------------------------
  alias kts_Interpreter_command_223 command_223
  def command_223
    $kts_manual_tone = true
    kts_Interpreter_command_223
  end
end

#==============================================================================
#  Creates the kylock_time object
#==============================================================================
class Scene_Title
  $kts=Kylock_Time.new
end  

#==============================================================================
#  Updates the clock using Game_System
#==============================================================================
class Game_System
  alias kts_game_system_update update
  def update      
    kts_game_system_update
    $kts.update
  end  
end

#==============================================================================
#  Initializes new map tinting using Game_Map
#==============================================================================
class Game_Map
  alias kts_game_map_setup setup
  def setup(map_id)
    kts_game_map_setup(map_id)
    $kts.update
    $kts.instant_tint
  end  
end

#==============================================================================
#  Updates screen tinting using Scene_Map
#==============================================================================
class Scene_Map
  alias kts_scene_map_update update
  def update
    kts_scene_map_update
    $kts.update_tint
  end  
end
  
class Scene_Map
  alias kts_call_battle call_battle
  def call_battle
    if $tint_during_battle == false
      $kts_tint_update_pause = true
      $game_screen.start_tone_change(Tone.new(0,0,0,0),0)
    end
    kts_call_battle
  end
end

class Scene_Battle
  alias kts_battle_end battle_end
  def battle_end(result)
    $kts_tint_update_pause = false
    kts_battle_end(result)
  end
end

#==============================================================================
#  Scans Map Names for Tinting
#==============================================================================
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(/[\*]/).size > 0
  end
end

#==============================================================================
#  Changes the Play Time Window to Game Time!
#==============================================================================
class Window_PlayTime < Window_Base
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 120, 32, "Game Time")
    $kts.update
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 32, 120, 32, $kts.time, 2)
  end
end

#==============================================================================
#  Changes Steps Window to Day
#==============================================================================
class Window_Steps < Window_Base
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 120, 32, "Day")
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 120, 32, $kts.game_days, 2)
    self.contents.draw_text(4, 32, 120, 32, $kts.today_name, 2)
  end
end

#==============================================================================
#  Saves time to save game file
#==============================================================================
class Scene_Save
  alias kts_write_save_data write_save_data
  def write_save_data(file)
    kts_write_save_data(file)
    Marshal.dump($kts, file)
  end
end  

#==============================================================================
#  Loads time from save game file
#==============================================================================
class Scene_Load
  alias kts_read_save_data read_save_data
  def read_save_data(file)
    kts_read_save_data(file)
    $kts = Marshal.load(file)
  end
end
 
I would need switches because let's say I want a shop to only open from 9 to 12pm having a switch that could be triggered by time would make my life alot easier than having to call script a bunch of mombo jombo I don't know.
 
I was wanting to know if you can tell me step by step how to use the switches so I can move the clock foward and backwards by however hours I would like. I'm new to useing switches and varialbes and call script. So can you plz help me and thank you very much.....
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top