Time / Day/Night System
#1
Time / Day/Night System
by mikah
Sep 26 2006

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Replace your Sprite_Timer with this script.

To make it light inside a building at night, name switch 1 "Inside" and turn it on when inside, off when outside.

Edit : Fixed day transitions, and added support for banking system with interest
(make sure variable #3 is not used, name it "days" use it in calc for interest)

Code:
#==============================================================================
# ** Sprite_Clock
#------------------------------------------------------------------------------
#  This sprite is used to display the clock. It observes the $game_system
#  class and automatically changes sprite conditions.
#  Compiled by GAM
#==============================================================================

class Sprite_Timer < Sprite
  

  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super
    self.bitmap = Bitmap.new(88, 48)
    self.bitmap.font.name = "Arial" #Replace with whatever font you want
    self.bitmap.font.size = 32
    self.x = 640 - self.bitmap.width
    self.y = 0
    self.z = 500
    update
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    self.visible = true
    if Graphics.frame_count / Graphics.frame_rate != @total_sec
         @total_sec = Graphics.frame_count / Graphics.frame_rate  # mod this line to change speed of clock
    $min = @total_sec / 60 % 24
    @sec = @total_sec % 60
    
    
    if $min == 00
      $night = 1
      $game_variables[3]+=1
    end
    
  
    if $min == 12
      $night = 2
    end
    
#----------------------------------------------------------------
#   Inside/Outside
#     Day / Night
# mod these for different tones, faster/slower tones,
# or more tones
#----------------------------------------------------------------
    if $game_switches[1] #==true
    $game_screen.start_tone_change(Tone.new(0,0,0), 5)
    else
      if $min < 5
        $game_screen.start_tone_change(Tone.new(-170,-170,68), 20)
      elsif $min >= 5 and $min < 7
        $game_screen.start_tone_change(Tone.new(-51,-102,-102), 20)
      elsif $min >= 7 and $min < 9
        $game_screen.start_tone_change(Tone.new(0,-51,-68), 20)
      elsif $min >= 9 and $min < 18
        $game_screen.start_tone_change(Tone.new(0,0,0), 20)
      elsif $min >= 18 and $min < 21
        $game_screen.start_tone_change(Tone.new(-34,-68,-119), 20)
      elsif $min >= 21
        $game_screen.start_tone_change(Tone.new(-170,-170,68), 20)        
      end
    end    

#----------------------------------------------------------------
#       Am / Pm
#  
#----------------------------------------------------------------    
    
    
    if $night == 2
      ampm = " PM"
      mins = $min - 12
      $day = 0
    else
      ampm = " AM"
      mins = $min
      
      
    end
    
#----------------------------------------------------------------
#   Makes the clock more clock looking
#
#----------------------------------------------------------------    
    
    if $min == 0 or $min == 12
      mins = 12
    end
    if $min == 10
      clock = sprintf("%02d:%02d", mins, @sec)
    elsif $min == 11
      clock = sprintf("%02d:%02d", mins, @sec)
    elsif $min == 12
      clock = sprintf("%02d:%02d", mins, @sec)
    else
    clock = sprintf("%01d:%02d", mins, @sec)
    end
    clock += ampm

    
    $clock = clock
      # Clear window contents
      self.bitmap.clear
      if $clock != nil
      text = clock
      # Draw clock
      self.bitmap.font.color.set(255, 255, 255)
      self.bitmap.draw_text(self.bitmap.rect, text, 1)
      @timer = clock
      end
    end
  end
  
end

And then replace your Window_PlayTime with this, it shall turn the "Play time" in the menu to a "World Clock"

Code:
class Window_PlayTime < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 120, 32, "World Clock")
    @total_sec = Graphics.frame_count / Graphics.frame_rate
    $min = @total_sec / 60 % 24
    @sec = @total_sec % 60
    
    if $min == 00
      $night = 1
      $day =+ 1
    end
      
    if $min == 12
      $night = 2
    end
    
    
    if $night == 2
      ampm = " PM"
      mins = $min - 12
    else
      ampm = " AM"
      mins = $min
    end
    
    if $min == 0 or $min == 12
      mins = 12
    end
    
    
    
    if $min == 10
      clock = sprintf("%02d:%02d", mins, @sec)
    elsif $min == 11
      clock = sprintf("%02d:%02d", mins, @sec)
    elsif $min == 12
      clock = sprintf("%02d:%02d", mins, @sec)
    else
    clock = sprintf("%01d:%02d", mins, @sec)
    end
    clock += ampm
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 32, 120, 32, clock, 2)
    $clock = clock
  end

  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------

  def update
    super
    if Graphics.frame_count / Graphics.frame_rate != @total_sec
      refresh
    end
  end
end

BTW you don't need the second script to make it work, just adds more authenticity to it instead of seeing the time is really the play timer.
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dynamic Weather and Time System ThallionDarkshine 0 2,848 05-25-2012, 01:00 PM
Last Post: ThallionDarkshine
  SP drain/increase over time Cavi 0 2,785 05-20-2011, 01:00 PM
Last Post: Cavi
  Tutorial system Jimmie 0 2,687 08-14-2009, 01:00 PM
Last Post: Jimmie
  New and Easy Cache system azrith001 0 2,765 09-02-2008, 01:00 PM
Last Post: azrith001
  Vehicle System El Conductor 0 2,775 12-22-2007, 01:00 PM
Last Post: El Conductor
  IMPROVED Fog of War System Samo the thief 0 2,503 05-06-2007, 01:00 PM
Last Post: Samo the thief
  Weight Equip System and Limit Samo the thief 0 2,557 01-29-2007, 01:00 PM
Last Post: Samo the thief
  Prize Points System Dark Ruby 0 2,538 01-28-2007, 01:00 PM
Last Post: Dark Ruby
  Export and Import System EmilyAnnCoons 0 2,414 12-29-2006, 01:00 PM
Last Post: EmilyAnnCoons
  Hawk's Mouse Control System Hawk-McKain 0 2,746 11-05-2006, 01:00 PM
Last Post: Hawk-McKain



Users browsing this thread: 1 Guest(s)