Advertisement
mjshi

Display Local Time

Nov 19th, 2016
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.50 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Display Local Time v1.1
  3. #-- Shows the local time in a message box.
  4. #-- By mjshi
  5. #-------------------------------------------------------------------------------
  6. # Usage: In an event, create a new Script command (tab 3) and type in showTime
  7. # If you chose to store the message in a variable, type \V[id] in a dialogue
  8. # box to display the message.
  9. #-------------------------------------------------------------------------------
  10. # Installation: Put anywhere above Main.
  11. #-------------------------------------------------------------------------------
  12.  
  13. module DisplayLocalTime
  14.   #-----------------------------------------------------------------------------
  15.   # **CONFIGURATION**
  16.   #-----------------------------------------------------------------------------
  17.   # Set to true for 24 hour time, false for 12 hour, AM/PM time
  18.   Time24Hour = false
  19.   #-----------------------------------------------------------------------------
  20.   # What should be shown in-between hours and minutes?
  21.   # Set to "" for something like military time (1200 hrs)
  22.   Separator = ":"
  23.   #-----------------------------------------------------------------------------
  24.   # What should the message be?
  25.   # %TIME will be replaced by something like
  26.   # 11:00 PM
  27.   # or, if you have Time24Hour = true
  28.   # 23:00
  29.   # Set this to just "%TIME" if you want just the time with no messages.
  30.   Message = "It's %TIME."
  31.   #-----------------------------------------------------------------------------
  32.   # Store the message into a variable? Set to false to directly display the
  33.   # message in a text box, or a variable ID to store it in that variable.
  34.   StoreMessage = false
  35.   #-----------------------------------------------------------------------------
  36. end
  37.  
  38. def showTime
  39.   time = Time.new
  40.   if time.min < 10
  41.     time_min = "0" + (time.min).to_s
  42.   else
  43.     time_min = (time.min).to_s
  44.   end
  45.  
  46.   if not DisplayLocalTime::Time24Hour
  47.     if time.hour >= 12
  48.       t_hr = (time.hour - 12).to_s + DisplayLocalTime::Separator + time_min
  49.       t_hr += " PM"
  50.     else
  51.       t_hr = (time.hour).to_s + DisplayLocalTime::Separator + time_min
  52.       t_hr += " AM"
  53.     end
  54.   else
  55.     t_hr = time.hour.to_s + DisplayLocalTime::Separator + time_min
  56.   end
  57.  
  58.   if !DisplayLocalTime::StoreMessage
  59.     $game_message.add(DisplayLocalTime::Message.gsub(/%TIME/, t_hr))
  60.   else
  61.     $game_variables[DisplayLocalTime::StoreMessage] = DisplayLocalTime::Message.gsub(/%TIME/, t_hr)
  62.   end
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement