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.

True Time and Day Script

kdb424

Member

I have RPG Maker XP with SDK V1.3 and I was wondering if there are any scripts that let me use the windows clock to make the in game time and date match the real time. I am making an animal crossing game and this would be REALLY useful to me, so if I could get one that would be great. Thanks in advance!
 

poccil

Sponsor

To access the system clock's time, use the code Time.now.  That object contains details about the time, including the current month, day, and year, and the current hour, minute, and second.  Specifically:

Time.now.hour accesses the hour (24-hour clock)
Time.now.min accesses the minute
Time.now.sec accesses the second
Time.now.year accesses the year
Time.now.mon accesses the month (I think).
Time.now.day accesses the day  (I think).

See "Time" within the XP or VX help file for details.
 

kdb424

Member

I think that I get it. Can you put that in script form that makes 6 game variables (I can at least change the numbers, lol) to those so I can use them in the game. Credit will be given. I'm starting to learn RGSS, but give me a break. I started yesterday. Thanks so much for the info!
 

poccil

Sponsor

It would look something like this.  Type the following as a script event command.
Code:
$game_variables[1]=Time.now.mon
$game_variables[2]=Time.now.mday
$game_variables[3]=Time.now.year
$game_variables[4]=Time.now.hour
$game_variables[5]=Time.now.min
$game_variables[6]=Time.now.sec

It stores the month, day, year, hour, minute, and second, respectively, in variables 1 through 6.

(In case it doesn't fit, you can use a small program I made to extend the Script dialog box while it is being displayed.)
 
kdb424":krly9ik4 said:
I have RPG Maker XP with SDK V1.3 and I was wondering if there are any scripts that let me use the windows clock to make the in game time and date match the real time. I am making an animal crossing game and this would be REALLY useful to me, so if I could get one that would be great. Thanks in advance!


I realize Poccil already posted, but here:

Here, this is a modified version of a script taken from Poccil's Pokemon Starter Kit:

Code:
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
#  Refer to "$game_temp" for the instance of this class.
#==============================================================================

class game_temp
  attr_accessor :game_time
  alias old_init initialize
  def initialize
    old_init
    @game_time = Game_Time.new
  end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#============================================================================== 

class scene_map
  alias old_update update
  def update
    old_update
    $game_temp.game_time.update
  end
end

#==============================================================================
# ** Game_Time
#------------------------------------------------------------------------------
#  This class performs all processing related to in-game time and season.
#  Refer to "$game_temp.weather_control" for the instance of this class.
#==============================================================================

class Game_Time
  #--------------------------------------------------------------------------
  # * Seasonal Color Tones
  #--------------------------------------------------------------------------
  module Time_Tones
    Spring_Hourly_Tones = [
      Tone.new(-127, -108, -58, 80),       #+#--> Begin Full Nighttime (12:00am)
      Tone.new(-127, -108, -58, 80),       #|                          (01:00am)
      Tone.new(-127, -108, -58, 80),       #|                          (02:00am)
      Tone.new(-127, -108, -58, 80),       #+#<-- End Full Nighttime   (03:00am)
      Tone.new(-107, -98, -51, 60),        #                           (04:00am)
      Tone.new(-87, -88, -45, 40),         #                           (05:00am)
      Tone.new(-67, -78, -38, 20),         #=#>-< Sunrise              (06:00am)
      Tone.new(-56, -65, -32, 17),         #                           (07:00am)
      Tone.new(-45, -52, -25, 13),         #                           (08:00am)
      Tone.new(-33, -39, -19, 10),         #                           (09:00am)
      Tone.new(-22, -26, -13, 7),          #                           (10:00am)
      Tone.new(-11, -13, -7, 4),           #                           (11:00am)
      Tone.new(0, 0, 0, 0),                #+#--> Begin Full Daylight  (12:00pm)
      Tone.new(0, 0, 0, 0),                #|                          (01:00pm)
      Tone.new(0, 0, 0, 0),                #|                          (02:00pm)
      Tone.new(0, 0, 0, 0),                #|                          (03:00pm)
      Tone.new(0, 0, 0, 0),                #|                          (04:00pm)
      Tone.new(0, 0, 0, 0),                #+#<-- End Full Daylight    (05:00pm)
      Tone.new(-17, -22, -27, 20),         #                           (06:00pm)
      Tone.new(-47, -68, -78, 45),         #=#>-< Sunset               (07:00pm)
      Tone.new(-87, -98, -68, 70),         #                           (08:00pm)
      Tone.new(-127, -108, -58, 80),       #+#--> Begin Full Nighttime (09:00pm)
      Tone.new(-127, -108, -58, 80),       #|                          (10:00pm)
      Tone.new(-127, -108, -58, 80)        #+#<-- End Full Nighttime   (11:00pm)
    ]
    Summer_Hourly_Tones = [
      Tone.new(-117, -108, -58, 80),       #+#--> Begin Full Nighttime (12:00am)
      Tone.new(-117, -108, -58, 80),       #|                          (01:00am)
      Tone.new(-117, -108, -58, 80),       #|                          (02:00am)
      Tone.new(-117, -108, -58, 80),       #+#<-- End Full Nighttime   (03:00am)
      Tone.new(-94, -90, -59, 62),         #                           (04:00am)
      Tone.new(-70, -73, -59, 43),         #                           (05:00am)
      Tone.new(-47, -55, -60, 25),         #=#>-< Sunrise              (06:00am)
      Tone.new(-38, -45, -53, 21),         #                           (07:00am)
      Tone.new(-28, -34, -46, 17),         #                           (08:00am)
      Tone.new(-19, -24, -38, 12),         #                           (09:00am)
      Tone.new(-9, -14, -31, 8),           #                           (10:00am)
      Tone.new(1, -4, -24, 4),             #                           (11:00am)
      Tone.new(10, 7, -17, 0),             #+#--> Begin Full Daylight  (12:00pm)
      Tone.new(10, 7, -17, 0),             #|                          (01:00pm)
      Tone.new(10, 7, -17, 0),             #|                          (02:00pm)
      Tone.new(10, 7, -17, 0),             #|                          (03:00pm)
      Tone.new(10, 7, -17, 0),             #|                          (04:00pm)
      Tone.new(10, 7, -17, 0),             #+#<-- End Full Daylight    (05:00pm)
      Tone.new(-6, -20, -25, 10),          #                           (06:00pm)
      Tone.new(-22, -75, -65, 40),         #=#>-< Sunset               (07:00pm)
      Tone.new(-83, -92, -62, 65),         #                           (08:00pm)
      Tone.new(-117, -108, -58, 80),       #+#--> Begin Full Nighttime (09:00pm)
      Tone.new(-117, -108, -58, 80),       #|                          (10:00pm)
      Tone.new(-117, -108, -58, 80)        #+#<-- End Full Nighttime   (11:00pm)
    ]
    Autumn_Hourly_Tones = [
      Tone.new(-105, -120, -50, 80),       #+#--> Begin Full Nighttime (12:00am)
      Tone.new(-105, -120, -50, 80),       #|                          (01:00am)
      Tone.new(-105, -120, -50, 80),       #|                          (02:00am)
      Tone.new(-105, -120, -50, 80),       #+#<-- End Full Nighttime   (03:00am)
      Tone.new(-88, -100, -43, 63),        #                           (04:00am)
      Tone.new(-72, -80, 37, 47),          #                           (05:00am)
      Tone.new(-55, -60, -30, 30),         #=#>-< Sunrise              (06:00am)
      Tone.new(-46, -56, -26, 27),         #                           (07:00am)
      Tone.new(-37, -52, -22, 23),         #                           (08:00am)
      Tone.new(-27, -47, -17, 20),         #                           (09:00am)
      Tone.new(-18, -43, -13, 17),         #                           (10:00am)
      Tone.new(-9, -39, -9, 14),           #                           (11:00am)
      Tone.new(0, -35, -5, 10),            #+#--> Begin Full Daylight  (12:00pm)
      Tone.new(0, -35, -5, 10),            #|                          (01:00pm)
      Tone.new(0, -35, -5, 10),            #|                          (02:00pm)
      Tone.new(0, -35, -5, 10),            #|                          (03:00pm)
      Tone.new(0, -35, -5, 10),            #|                          (04:00pm)
      Tone.new(0, -35, -5, 10),            #+#<-- End Full Daylight    (05:00pm)
      Tone.new(-15, -45, -25, 15),         #                           (06:00pm)
      Tone.new(-40, -65, -50, 30),         #=#>-< Sunset               (07:00pm)
      Tone.new(-85, -100, -50, 65),        #                           (08:00pm)
      Tone.new(-105, -120, -50, 80),       #+#--> Begin Full Nighttime (09:00pm)
      Tone.new(-105, -120, -50, 80),       #|                          (10:00pm)
      Tone.new(-105, -120, -50, 80)        #+#<-- End Full Nighttime   (11:00pm)
    ]
    Winter_Hourly_Tones = [
      Tone.new(-135, -145, -100, 190),     #+#--> Begin Full Nighttime (12:00am)
      Tone.new(-135, -145, -100, 190),     #|                          (01:00am)
      Tone.new(-135, -145, -100, 190),     #|                          (02:00am)
      Tone.new(-135, -145, -100, 190),     #+#<-- End Full Nighttime   (03:00am)
      Tone.new(-118, -132, -85, -178),     #                           (04:00am)
      Tone.new(-101, -118, -70, -163),     #                           (05:00am)
      Tone.new(-85, -105, -55, 150),       #=#>-< Sunrise              (06:00am)
      Tone.new(-73, -92, -46, 140),        #                           (07:00am)
      Tone.new(-60, -78, -37, 130),        #                           (08:00am)
      Tone.new(-48, -65, -27, 120),        #                           (09:00am)
      Tone.new(-35, -52, -18, 110),        #                           (10:00am)
      Tone.new(-23, -39, -9, 100),         #                           (11:00am)
      Tone.new(-10, -25, 0, 90),           #+#--> Begin Full Daylight  (12:00pm)
      Tone.new(-10, -25, 0, 90),           #|                          (01:00pm)
      Tone.new(-10, -25, 0, 90),           #|                          (02:00pm)
      Tone.new(-10, -25, 0, 90),           #|                          (03:00pm)
      Tone.new(-10, -25, 0, 90),           #|                          (04:00pm)
      Tone.new(-10, -25, 0, 90),           #+#<-- End Full Daylight    (05:00pm)
      Tone.new(-30, -55, -25, 115),        #                           (06:00pm)
      Tone.new(-80, -110, -65, 150),       #=#>-< Sunset               (07:00pm)
      Tone.new(-115, -130, -90, 180),      #                           (08:00pm)
      Tone.new(-135, -145, -100, 190),     #+#--> Begin Full Nighttime (09:00pm)
      Tone.new(-135, -145, -100, 190),     #|                          (10:00pm)
      Tone.new(-135, -145, -100, 190)      #+#<-- End Full Nighttime   (11:00pm)
    ]
  end
  #--------------------------------------------------------------------------
  # * Time System Names
  #--------------------------------------------------------------------------
  module Time_Names
    Weekdays = [
      "Sunday",
      "Monday",
      "Tuesady",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday"
    ]
    Months = [
      "January",
      "February",
      "March",
      "April",
      "May",
      "June",
      "July",
      "August",
      "September",
      "October",
      "November",
      "December"
    ]
    Seasons = [
      "spring",
      "summer",
      "autumn",
      "winter"
    ]
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # set @time to 0. @time is used in the update function.
    @time = 0
  end
  #--------------------------------------------------------------------------
  # * Object Update
  #--------------------------------------------------------------------------
  def update
    # Set now to the current time on the computer clock
    now = Time.now
    # Set @current time to the current minute on the computer clock
    @current_time = now.min
    # If @time does not equal the current minute
    if @time != @current_time
      # Set the tone of the screen for the current time
      set_time_tone
      # Set @time to equal @current time.
      @time = @current_time
    end
  end
  #--------------------------------------------------------------------------
  # * Change Screen Tone to Match Current Time
  #--------------------------------------------------------------------------
  def set_time_tone
    # Set now to the current time on the computer clock
    now = Time.now
    # Set hour to the current hour on the computer clock
    hour = now.hour
    # Set minute to the current minute on the computer clock
    minute = now.min
    # If the current season is Spring or the Wet Season
    if current_season(1) == 1
      # Set tone to the current hour's tone for Spring
      tone = Time_Tones::Spring_Hourly_Tones[hour]
      # Set next_hour_tone to the next hour's tone for Spring
      next_hour_tone = Time_Tones::Spring_Hourly_Tones[(hour+1)%24]
    # If the current season is Summer or the Dry Season
    elsif current_season(1) == 2
      # Set tone to the current hour's tone for Summer
      tone = Time_Tones::Summer_Hourly_Tones[hour]
      # Set next_hour_tone to the next hour's tone for Summer
      next_hour_tone = Time_Tones::Summer_Hourly_Tones[(hour+1)%24]
    # If the current season is Autumn
    elsif current_season(1) == 3
      # Set tone to the current hour's tone for Autumn
      tone = Time_Tones::Autumn_Hourly_Tones[hour]
      # Set next_hour_tone to the next hour's tone for Autumn
      next_hour_tone = Time_Tones::Autumn_Hourly_Tones[(hour+1)%24]
    # If the current season is Winter
    elsif current_season(1) == 4
      # Set tone to the current hour's tone for Winter
      tone = Time_Tones::Winter_Hourly_Tones[hour]
      # Set next_hour_tone to the next hour's tone for Winter
      next_hour_tone = Time_Tones::Winter_Hourly_Tones[(hour+1)%24]
    end
    # Set the color tones to the correct tones for the current minute
    tone_red = (minute*(next_hour_tone.red-tone.red)/60.0)+tone.red
    tone_green = (minute*(next_hour_tone.green-tone.green)/60.0)+tone.green
    tone_blue = (minute*(next_hour_tone.blue-tone.blue)/60.0)+tone.blue
    tone_gray = (minute*(next_hour_tone.gray-tone.gray)/60.0)+tone.gray
    # If there are clouds in the sky,
    # Set @current_tone to the current time's tone
    @current_tone = Tone.new(tone_red, tone_green, tone_blue, tone_gray)
    # If the map was just opened,
    if @open_map == true
      # If the tone is being overridden,
      if @tone_override == true
      # If the tone is not being overridden,
      else
        # Immediately set the screen to the current time's tone
        $game_screen.start_tone_change(@current_tone, 0)
        # Set @open_map to false
        @open_map = false
      end
    # If the tone is being overridden,
    elsif @tone_override == true
    # If the tone is not being overridden or the map isn't opening,
    else
      # Set the screen to the current time's tone over a period of one minute
      $game_screen.start_tone_change(@current_tone, 2400)
    end
  end
  #--------------------------------------------------------------------------
  # * Define Current Day
  #--------------------------------------------------------------------------
  def current_day(result)
    # Set now to current computer time
    now = Time.now
    # Set day to current day of the week
    day = now.strftime('%w')
    # Set day2 to the current day of the month
    day2 = now.strftime('%d')
    # If weekday number is requested,
    if result == 1
      # Return the number of the current weekday
      return day.to_i
    # If the current day of the month is requested,
    elsif result == 2
      # Return the current day of the month
      return day2.to_i
    # If current weekday is requested,
    elsif result == 3
      # Return current weekday's name using the Time_Names module
      return Time_Names::Weekdays[day.to_i]
    end
  end
  #--------------------------------------------------------------------------
  # * Define Current Month
  #--------------------------------------------------------------------------
  def current_month(result)
    # Set now to the current computer time
    now = Time.now
    # Set month to the current month of the year
    month = now.strftime('%m')
    # If the month's number is requested,
    if result == 1
      # Return the number of the current month
      return month.to_i
    # If the current month's name is requested,
    elsif result == 2
      # Return the current month's name using the Time_Names module
      return Time_Names::Months[month.to_i]
    end
  end
  #--------------------------------------------------------------------------
  # * Define Current Season
  #--------------------------------------------------------------------------
  def current_season(result)
    # Set now to current time
    now = Time.now
    # Set day to the current day of the month
    day = now.strftime('%d')
    # Set month to the current month of the year
    month =  now.strftime('%m')
    # If the current lattitude is in the northern temperate zone,
    # If it is January or February,
    if month.to_i <= 2
      # Set season to winter
      season = 4
    # If it is before the 20th of March,
    elsif month.to_i == 3 and day.to_i < 20
      # Set season to winter
      season = 4
    # If it is or is after the 20th of March,
    elsif month.to_i == 3 and day.to_i >= 20
      # Set season to spring
      season = 1
    # If it is April or May,
    elsif month.to_i == 4 or month.to_i == 5
      # Set season to spring
      season = 1
    # If it is before the 20th of June,
    elsif month.to_i == 6 and day.to_i < 20
      # Set season to spring
      season = 1
    # If it is or is after the 20th of June,
    elsif month.to_i == 6 and day.to_i >= 20
      # Set season to summer
      season = 2
    # If it is July or August,
    elsif month.to_i == 7 or month.to_i == 8
      # Set season to summer
      season = 2
    # If it is before the 22nd of September,
    elsif month.to_i == 9 and day.to_i < 22
      # Set season to summer
      season = 2
    # If it is or is after the 22nd of September,
    elsif month.to_i == 9 and day.to_i >= 22
      # Set season to autumn
      season = 3
    # If it is October or November,
    elsif month.to_i == 10 or month.to_i == 11
      # Set season to autumn
      season = 3
    # If it is beofore the 21st of December,
    elsif month.to_i >= 12 and day.to_i < 21
      # Set season to autumn
      season = 3
    # If it is or is after the 21st of December,
    elsif month.to_i >= 12 and day.to_i >= 21
      # Set season to winter
      season = 4
    end
    # If the current season's number is requested,
    if result == 1
      # Return the number of the current season, in order from Spring -> Winter
      if season == 1
        return 1
      elsif season == 2
        return 2
      elsif season == 3
        return 3
      elsif season == 4
        return 4
      end
    # If the name of the current season is requested,
    elsif result = 2
      # Return the name of the current season, using the Time_Names module
      return Time_Names::Seasons[season]
    end
  end
  #--------------------------------------------------------------------------
  # * Initialize Map Tone
  #--------------------------------------------------------------------------
  def open_map
    # Set @open_map to true and change the screen tone
    @open_map = true
    set_time_tone
  end
  #--------------------------------------------------------------------------
  # * Override Time Tone
  #--------------------------------------------------------------------------
  def tone_override(result)
    # Set @tone_override to true or false, based on method call
    @tone_override = result
  end
end
Please note that you have to use the $game_temp.game_time.tone_override(true) method call when you go inside or underground. (You will also have to use a change screen color tone event command) Then, when you go outside, you have to use the following commands:

$game_temp.game_time.tone_override(false)
$game_temp.game_time.open_map

To say the current day, use the following command:

$game_temp.game_time.current_day(result)

where result is 1 to give the number of the current weekday, 2 to give the number of gthe current day of the month, and 3 to return the name of the current weekday. (defined at the top of the script)

To say the current month, use:

$game_temp.game_time.current_month(result)

where result is 1 to give the number of the current month and 2 to give the name of gthe current month. (Like the weekday, the month name is defined towards the top of the script)

To say the current season, use:

$game_temp.game_time.current_season(result)

where result is 1 to give the number of the current season and 2 to give the name of the current season. (Once again, the name is defined toward the top of the script)

Please note that this script is still being worked on, and thus is a little quirky. (like with the current day, month, and season commands)
 

kdb424

Member

poccil":3vs820e9 said:
It would look something like this.  Type the following as a script event command.
Code:
$game_variables[1]=Time.new.mon
$game_variables[2]=Time.new.mday
$game_variables[3]=Time.new.year
$game_variables[4]=Time.new.hour
$game_variables[5]=Time.new.min
$game_variables[6]=Time.new.sec

It stores the month, day, year, hour, minute, and second, respectively, in variables 1 through 6.

(In case it doesn't fit, you can use a small program I made to extend the Script dialog box while it is being displayed.)

Oh my god. I LOVE YOU! You are amazing! GlitchFinder, sorry, but poccil's way was easier and got here first, but the help if much appreciated by the both of you!
 
kdb424":1xcqn2oj said:
poccil":1xcqn2oj said:
It would look something like this.  Type the following as a script event command.
Code:
$game_variables[1]=Time.new.mon
$game_variables[2]=Time.new.mday
$game_variables[3]=Time.new.year
$game_variables[4]=Time.new.hour
$game_variables[5]=Time.new.min
$game_variables[6]=Time.new.sec

It stores the month, day, year, hour, minute, and second, respectively, in variables 1 through 6.

(In case it doesn't fit, you can use a small program I made to extend the Script dialog box while it is being displayed.)

Oh my god. I LOVE YOU! You are amazing! GlitchFinder, sorry, but poccil's way was easier and got here first, but the help if much appreciated by the both of you!

I appear to have forgotten to mention that my script is already programmed to set the tone of the screen to the specific time of day, based on the current season.
 

Mars

Member

Is there a way in Poccil's event scripts to set the day of the week as well? (Mon. =1, Tues. =2, Wed. =3...)

I like his, as it works with VX as well! =D

Edit! Nevermind, I played around, and figured out that The day of the month was

$game_variables[2]=Time.new.mday

so I changed (mday), to (wday), and whaddya know? It worked!
 

kdb424

Member

GlitchFinder: Thanks so much, but I already had seasons covered, and the tint too, but much appreciated.
Mars: Thanks for that weekday hint. I needed that for the game also. You rock!!
 

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