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.

In need of a script that displays the time and day.

I am currently using a Real Time script that adjusts the screen tone based on the time a day in the real world(like at the timing of this post, the screen tone is almost pitch black).

My Request:I need a add-on of sorts that would display the time(12 hour day) and day/month/year on-screen by reading the PC's clock(as does the script).

I've done a forum search(both browsing and using the search feature) and have come up with no results.

Any help would be appreciated.

(bah, spelling error in title)
 
In which screen would you like those to appear? (i.e. map screen, menu screen, etc.) And how would you like them to appear (make a scratch in Paint or use Window-Scene Wizard)?

One more thing, what is the format of the time? I assume its hh:mm AM/PM (seconds are excluded).

I think it's fairly easy enough to make...
 
Sorry for late response.

Could you give me (either posting here or via PM) the real-time script you're currently using? I didn't find it anywhere here, so currently I can't make it...

Thank you.

EDIT:
Well, so I don't violate the 72-hours bump...

Here is the script. Hope you like it. Should there be any errors (I've tested it and no errors occured) or anything you'd like to ask, you can always ask me.
Code:
=begin
**************************************************
CUSTOMIZATION
**************************************************

WINDOW_POS:
Specify in which corner you'd like the time window to appear
1 = upper left
2 = upper right
3 = lower left
4 = lower right
Default: 4 (lower right)
(note that if your game is using a resolution other than 640x480,
which is the RMXP default game resolution, this will not work properly)

POSTALITY_KNIGHT:
Set it to true if you're using RMXP Postality Knight Edition
Set it to false if you're using original RMXP 1.0.2 to prevent errors
Default: false

OPACITY:
In case you want to set the window opacity, specify it here
Range: 0 (transparent) to 255 (opaque)
Default: 255

WINDOWSKIN (not tested, but hope works):
If you want to change the windowskin to be different than others,
you can specify it here
Default: 001-Blue01
=end

WINDOW_POS = 4
POSTALITY_KNIGHT = false
OPACITY = 255
WINDOWSKIN = "001-Blue01"

# CUSTOMIZATION ENDS HERE

class Game_Time
  attr_accessor :timestr, :monthstr, :datestr
  
  alias time_initialize initialize
  def initialize
    get_time_string
  end
  def get_time_string
    @timestr = Time.now.strftime("%I:%M %p")
    @monthstr = Time.now.strftime("%A")
    @datestr = Time.now.strftime("%b %d")
    # using "st", "nd", "rd", or "th"?
    datenow = Time.now.day
    case datenow
    when 1, 21, 31
      daysuffix = "st"
    when 2, 22
      daysuffix = "nd"
    when 3, 23
      daysuffix = "rd"
    else
      daysuffix = "th"
    end
    # now combine date with its suffix
    @datestr += daysuffix
  end
end

class Window_Time < Window_Base
  #--------------------------------------------------------------------------
  def initialize
    case WINDOW_POS
    when 1 #upper left
      x, y, width, height = 0, 0, 320, 64
    when 2 #upper right
      x, y, width, height = 320, 0, 320, 64
    when 3 #lower left
      x, y, width, height = 0, 416, 320, 64
    when 4 #lower right
      x, y, width, height = 320, 416, 320, 64
    end
    super(x, y, width, height)
    self.windowskin = RPG::Cache.windowskin(WINDOWSKIN)
    self.contents = Bitmap.new(width - 32, height - 32)
    if POSTALITY_KNIGHT
      self.contents.font.name = $defaultfonttype # "Time" window font
      self.contents.font.size = $defaultfontsize
    end
    self.opacity = OPACITY
    refresh
  end

  #--------------------------------------------------------------------------
  def refresh
    $game_time.get_time_string
    @minute=$game_time.minutess
    self.contents.clear
    @total_sec = Graphics.frame_count / Graphics.frame_rate
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, 92, 32, $game_time.timestr)
    self.contents.draw_text(96, 0, 92, 32, $game_time.monthstr)
    self.contents.draw_text(192, 0, 92, 32, $game_time.datestr)
  end

  #--------------------------------------------------------------------------
  def update
    $game_time.get_time
    if $game_time.minutess != @minute
    refresh
    end
  end
end


class Scene_Map
  alias time_main main
  def main
    @time_window = Window_Time.new
    time_main
    @time_window.dispose
  end
  
  alias time_update update
  def update
    @time_window.update
    time_update
  end
end

You don't need to credit me if you wish ;)
 

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