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.

Day/Night System question

ROMP

Member

I found this script for a day/night system and im not quite sure how to use it completely.

Code:
#-------------------------------------------
# Day/Night System
# Use "*" to call the Script
# Time is based on Computer Time
#-------------------------------------------
module Realtime
  #-------------------------------------------
  # * Object Initialization
  #-------------------------------------------
  def self.initialize
    # integers
    @time       = Time.now
    @second     = @time.sec
    @minute     = @time.min
    @hour       = @time.hour
    @day        = @time.day
    @week       = @time.strftime("%W").to_i
    @month      = @time.month
    @year       = @time.year
    # strings
    @dayame     = @time.strftime("%A")
    @monthname  = @time.strftime("%B")
    @timezone   = @time.strftime("%Z")
    @meridian   = @time.strftime("%p")
  end
  
  #-------------------------------------------
  # * Second ( 0...59 )
  #-------------------------------------------
  def self.second
    return @second
  end
  #-------------------------------------------
  # * Minute ( 0...59 )
  #-------------------------------------------
  def self.minute
    return @minute
  end
  #-------------------------------------------
  # * Hour ( 0...24 )
  #-------------------------------------------
  def self.hour
    return @hour
  end
  #-------------------------------------------
  # * Day ( 1...366 )
  #------------------------------------------
  def self.day
    return @day
  end
  #-------------------------------------------
  # * Week ( 0...53 )
  #-------------------------------------------
  def self.week
    return @week
  end
  #-------------------------------------------
  # * Month ( 1...12 )
  #-------------------------------------------
  def self.month
    return @month
  end
  #-------------------------------------------
  # * Year ( current year )
  #-------------------------------------------
  def self.year
    return @year 
  end
  
  #-------------------------------------------
  # * Day Name ( Monday...Sunday )
  #------------------------------------------
  def self.dayname
    return @dayname.capitalize!
  end
  #-------------------------------------------
  # * Month Name ( January...December )
  #-------------------------------------------
  def self.monthname
    return @monthname.capitalize!
  end
  #-------------------------------------------
  # * Timezone ( GTM / CST )
  #-------------------------------------------
  def self.timezone
    return @timezone
  end
  #-------------------------------------------
  # * Meridian ( AM / PM )
  #-------------------------------------------
  def self.meridian
    return @meridian
  end
  #-------------------------------------------
  # * Now
  #-------------------------------------------
  def self.now
    return @time
  end
  
  #-------------------------------------------
  # * Time Update
  #-------------------------------------------
  def self.update
    # integers
    @time       = Time.now
    @second     = @time.sec
    @minute     = @time.min
    @hour       = @time.hour
    @day        = @time.day
    @week       = @time.strftime("%W").to_i
    @month      = @time.month
    @year       = @time.year
    # strings
    @dayame     = @time.strftime("%A")
    @monthname  = @time.strftime("%B")
    @timezone   = @time.strftime("%Z")
    @meridian   = @time.strftime("%p")
    
    tint_screen
  end
  
  #-------------------------------------------
  # * Tint screen
  #-------------------------------------------
  def self.tint_screen
    if !$scene.is_a?(Scene_Map)
      @tone = $game_screen.tone
      return
    end
    if $scene.is_a?(Scene_Map)
      # added.
      # tint screen only works if map has '*' in the name
      if !$game_map.name.include?("*")
        @tone = Tone.new(0,0,0,0)
        @duration = 0
        $game_screen.start_tone_change(@tone, @duration)
        return
      end

      # change tone and duration here depending on times
      # tone     : screen tone
      # duration : duration of tone change
      if @hour >= 0
        tone = Tone.new(-238, -204, -170, 221)
        duration = 600
      end
      if @hour >= 5
        tone = Tone.new(17, -51, -102, 0)
        duration = 600
      end
      if @hour >= 10
        tone = Tone.new(0, 0, 0, 0)
        duration = 600
      end
      if @hour >= 15
        tone = Tone.new(-68, -136, -34, 0)
        duration = 600
      end
      if @hour >= 20
        tone = Tone.new(-187, -119, -17, 68)
        duration = 600
      end
      @tone = tone
      $game_screen.start_tone_change(@tone, duration)
    end
  end
end

module Graphics
  class << self
    unless @reboot_fix == 1
      alias realtime_update update
      @reboot_fix = 1
    end
    
    def update
      Realtime.update if $game_screen != nil
      realtime_update
    end
  end
end

class Game_Map
  def name
    $map_infos = load_data("Data/MapInfos.rxdata")
    return $map_infos[@map_id].name
  end
end

i already have the * placed in my maps titles, and the time goes by while you leave it idle or walk around.

but if anyone could answer these questions id really appreciate it:

1. how would i simply change the time using an event? say i just wanted time to pass from 6am to 3pm, how would i do that?

2. how could i set a requirement for a time? (not sure if i worded that right)
ex. there is an NPC named john, i would like to make it so if you talk to john in the evening he says one thing, or if you speak to him in the morning he says another... how could i do that?
i know id have to call a script , i just dont know what script to call
 

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