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.

Caldaron's Time

Caldaron's Time
Version: 1.02



Features
  • create Areas which contain Maps, e.g. for Snow Areas
  • permanent tint to prevent wrong displays
  • interactive weather system
  • Month can influence Weather effects and tints
  • Change Speed of Time
  • Time can overlap (sic, but i love it)
  • Many more

Example Setup

OK, let's just say you want a time script, that adapts to different areas, because the light in a cave isn't as bright as in the field, right?
Then, let's say we want to make a desert, because it isn't defined yet.
At first we need a new Area:
go under create_areas and type under the others:
Code:
@area[4] = Area.new(4)
Then we call it Desert:
Code:
@area[4].name = 'Desert'
And now, what? Is waether in this Area possible?
I think yes, but it won't appear often.
Code:
@area[4].weather = true
Does the Time run faster or slower?
I think we'll let it run normal
Code:
@area[4].time_speed = 1.00
Next Question: Are the times overlapping?
To let the time speeds influence the time out of this Area
Code:
@area[4].time_overlap = true
We set the weather = true before, now what % of appearance have they?
I think we set up the rain porpability to 5%, that'll look like this
Code:
@area[4].weather_prop[0] = 5
Now, does the date influence the weather propability? Nope
Code:
@area[4].prop_influence = false
As long as there is weather, there has to be a weather sound, it's set to 100%
Code:
@area[4].weather_sound = 100
As long as there is no storm there can be no thunder
Code:
@area[4].thunder = false
Now lets choose which maps are 'Desert'-Maps
Code:
@area[4].maps = [4, 5]
NOw it's getting more difficult:
In how many time parts is the day in this area divided and which range of hours are in them included?
Lets say there are the same day periods as in 'Outside'
Code:
@area[4].day_period = @area[0].day_period
Now, does the date influence the tint? No
Code:
@area[4].tint_influence = false
Now the last thing:
Hoe is tint fading?
As you can see the 'Outside'-Tint is pretty complicated, so lets just say it's the same
Code:
@area[4].tint = @area[0].tint

That's it!

Script

Code:
#==============================================================================
# Time System Script v. 1.03
# by Caldaron (23.01.2007)
#==============================================================================
SDK.log("Caldaron's Time", 'Caldaron', 1.03, '2007-01-23')

if SDK.state("Caldaron's Time")
#==============================================================================
class Time_System
  #--------------------------------------------------------------------------
  attr_reader   :current_weather
  attr_accessor :freeze_time
  attr_accessor :thunder
  attr_accessor :time_count
  #--------------------------------------------------------------------------
  def initialize
    @second_length = 60
    @minute_length = 60
    @hour_length = 24
    @day_length = 30
    @week_length = 7
    @month_length = 12
    @last_minute = nil
    @last_second = [0,0]
    @freeze_time = false
    @current_weather = [0, false]
    @last_map = 0
    @last_area = 0
    @thunder = false
    @speed = 1.00
    @time_count = [0, 0]
    @time_overlap = true
    @frozen = 0
    @timer = 1
    #==============================================================================
    # DATE NAMES
    #==============================================================================
    @day_name = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
    "Sunday"]
    @month_name = ["January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December"]
    #==============================================================================
    # START DATE
    #==============================================================================
    @start_time = [58, 56, 11, 25, 3, 619]
    create_areas
  end
  #==============================================================================
  # AREA DEFINITIONS
  #==============================================================================
  def create_areas
    #--------------------------------------------------------------------------
    # Areas
    #--------------------------------------------------------------------------
    @area = []
    
    @area[0] = Area.new(0)
    
    @area[1] = Area.new(1)
    
    @area[2] = Area.new(2)
    
    @area[3] = Area.new(3)
    #--------------------------------------------------------------------------
    # Area Name
    #--------------------------------------------------------------------------
    @area[0].name = "Outside"
    
    @area[1].name = "Inside"
    
    @area[2].name = "Cave"
    
    @area[3].name = "Snow Field"
    #--------------------------------------------------------------------------
    # Weather in this Area?
    #--------------------------------------------------------------------------
    @area[0].weather = true
    
    @area[1].weather = false
    
    @area[2].weather = false
    
    @area[3].weather = true
    #--------------------------------------------------------------------------
    # Speed of Time in this Area?
    # the higher the Value, the faster the Time
    #--------------------------------------------------------------------------
    @area[0].time_speed = 1.00
    
    @area[1].time_speed = 0.50
    
    @area[2].time_speed = 1.25
    
    @area[3].time_speed = 2.00
    #--------------------------------------------------------------------------
    # Time overlaps?
    # true:  Different Times with different Speed of Time in different Areas
    # false: Same Time but different Speed of Time in different Areas
    #--------------------------------------------------------------------------
    @area[0].time_overlap = true
    
    @area[1].time_overlap = true
    
    @area[2].time_overlap = true
    
    @area[3].time_overlap = true
    #--------------------------------------------------------------------------
    # Propabilities of the Weathertypes:
    # Weather at Position
    #    1 - rain
    #    2 - storm
    #    3 - snow
    #    4 - hail
    #    5 - rain with thunder and lightning
    #    6 - falling leaves (autumn)
    #    7 - blowing leaves (autumn)
    #    8 - swirling leaves (autumn)
    #    9 - falling leaves (green)
    #   10 - cherry blossom (sakura) petals
    #   11 - rose petals
    #   12 - feathers
    #   13 - blood rain
    #   14 - sparkles
    #   15 - user defined
    #   16 - blowing snow
    #   17 - meteor shower
    #   18 - falling ash
    #   19 - bubbles
    # Rest of the Percentage will be Sunshine
    #--------------------------------------------------------------------------
    for i in 0...@area.size
      @area[i].weather_prop = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    end
    # Outside                         
    @area[0].weather_prop[0] = 20 # rain
    @area[0].weather_prop[1] = 10 # storm
    @area[0].weather_prop[4] = 10 # thunder
    # Inside                          
    @area[1].weather_prop = @area[0].weather_prop
    # when @area.weather = false and @area.weather_prop is the same as the last map
    # (which is in an other area) only the sound will be played
    # Cave
    # @area[2].weather_prop needs no editing, because there is no weather ;)
    # Snow Field
    @area[3].weather_prop[2] = 20
    @area[3].weather_prop[3] = 10
    @area[3].weather_prop[15] = 10
    #--------------------------------------------------------------------------
    # Months influence Propability?
    #--------------------------------------------------------------------------
    @area[0].prop_influence = true
    
    @area[1].prop_influence = true
    
    @area[2].prop_influence = false
    
    @area[3].prop_influence = false
    #--------------------------------------------------------------------------
    # Volume of the Weather
    #--------------------------------------------------------------------------
    @area[0].weather_volume = 100
    
    @area[1].weather_volume = 80
    
    @area[2].weather_volume = 0
    
    @area[3].weather_volume = 100
    #--------------------------------------------------------------------------
    # Thunder light in this Area?
    #--------------------------------------------------------------------------
    @area[0].thunder = true
    
    @area[1].thunder = false

    @area[2].thunder = false

    @area[2].thunder = false
    #--------------------------------------------------------------------------
    # Maps included in this Area
    # Example: @area[6].maps = [6, 13, 19]
    #--------------------------------------------------------------------------
    @area[0].maps = [1, 2]
    
    @area[1].maps = [3]
    
    @area[2].maps = [4]

    @area[3].maps = [5]
    #--------------------------------------------------------------------------
    # Day Period
    # must be Range: (x..y)
    # must include all hours from 0 to @hours_length-1
    #--------------------------------------------------------------------------
    @area[0].day_period[0] = (0..3)
    @area[0].day_period[1] = (4..7)
    @area[0].day_period[2] = (8..11)
    @area[0].day_period[3] = (12..15)
    @area[0].day_period[4] = (16..19)
    @area[0].day_period[5] = (20..23)
    
    @area[1].day_period[0] = (0..23)

    @area[2].day_period[0] = (0..23)
    
    @area[3].day_period = @area[0].day_period
    #--------------------------------------------------------------------------
    # Months influence Tint?
    #--------------------------------------------------------------------------
    @area[0].tint_influence = true
    
    @area[1].tint_influence = true

    @area[2].tint_influence = false

    @area[3].tint_influence = false
  end
  #--------------------------------------------------------------------------
  # minutes_to(Area ID, Tint ID)
  # Max Distance is 1
  # Example:
  # minutes_to(0, 0) * 25
  # Value slowly grows from 0 to 25, by dividing the max reachable with the
  # current minutes in this day period
  #--------------------------------------------------------------------------
  def refresh_tints # initialize_tints
    # tints must be equal the day_period.size
    @area[0].tint[0] = [-200 + minutes_to( 0, 0) * 25, -175 + minutes_to( 0, 0) * 25,
                        -100, 32]
                                
    @area[0].tint[1] = [-175 + minutes_to( 0, 1) * 75, -150 + minutes_to( 0, 1) * 75,
                        -100 + minutes_to( 0, 1) * 50,   32 - minutes_to( 0, 1) * 16]
                        
    @area[0].tint[2] = [-100 + minutes_to( 0, 2) * 85,  -75 + minutes_to( 0, 2) * 60,
                         -50 + minutes_to( 0, 2) * 35,   16 - minutes_to( 0, 2) * 16]
                        
    @area[0].tint[3] = [ -15 - minutes_to( 0, 3) * 20,  -15 - minutes_to( 0, 3) * 35,
                         -15 - minutes_to( 0, 3) * 60,    0 + minutes_to( 0, 3) *  8]
                        
    @area[0].tint[4] = [ -35 - minutes_to( 0, 4) * 75,  -50 - minutes_to( 0, 4) * 50,
                         -75 - minutes_to( 0, 4) * 25,    8 + minutes_to( 0, 4) *  8]
                         
    @area[0].tint[5] = [-110 - minutes_to( 0, 5) * 90, -100 - minutes_to( 0, 5) * 75,
                        -100, 16 + minutes_to( 0, 5) * 16]
                        
    @area[1].tint[0] = [0, 0, 0, 0]
    
    @area[2].tint[0] = [0, 0, 0, 0]
    
    @area[3].tint = @area[0].tint
    for i in 0...@area[0].tint.size
      @area[3].tint[i][2] = @area[0].tint[i][2]-20
    end
  end
  #--------------------------------------------------------------------------
  # tone[0] = red / tone[1] = green / tone[2] = blue / tone[3] = gray
  #--------------------------------------------------------------------------
  def month_tint(tone, i)
    tona = []
    if @area[i].tint_influence
      case months
      when 1
        tona.push(tone[0]-10, tone[1]-10, tone[2], tone[3] + 8)
      else
        tona.push(tone[0], tone[1], tone[2], tone[3])
      end
    else
      tona.push(tone[0], tone[1], tone[2], tone[3])
    end
    return tona
  end
  #--------------------------------------------------------------------------
  def month_weather(prop, i)
    #    0 - rain
    #    1 - storm
    #    2 - snow
    #    3 - hail
    #    4 - rain with thunder and lightning
    #    5 - falling leaves (autumn)
    #    6 - blowing leaves (autumn)
    #    7 - swirling leaves (autumn)
    #    8 - falling leaves (green)
    #    9 - cherry blossom (sakura) petals
    #   10 - rose petals
    #   11 - feathers
    #   12 - blood rain
    #   13 - sparkles
    #   14 - user defined
    #   15 - blowing snow
    #   16 - meteor shower
    #   17 - falling ash
    #   18 - bubbles
    if @area[i].prop_influence
      case months
      when 1, 2, 12
        prop[0]  = 0
        prop[1]  = 0
        prop[2]  += @area[i].weather_prop[0]
        prop[3]  += @area[i].weather_prop[4]
        prop[4]  = 0
        prop[15] += @area[i].weather_prop[1]
      when 3..5
        prop[0]  /= 2
        prop[1]  /= 2
        prop[9]  += @area[i].weather_prop[0]/2
        prop[10] += @area[i].weather_prop[1]/2
      when 6..8
        # is the standard definition of weather_prop
      when 9..11
        prop[0] /= 2
        prop[1] /= 2
        prop[4] /= 2
        prop[5] += @area[i].weather_prop[0]/2
        prop[6] += @area[i].weather_prop[1]/2
        prop[7] += @area[i].weather_prop[4]/2
      end
    end
    return prop
  end
  #--------------------------------------------------------------------------
  # NO MORE TO EDIT
  #--------------------------------------------------------------------------
  def tone_change
    for i in 0...@area.size
      next unless @area[i].maps.include?($game_map.map_id)
      weather_control(i) unless @last_map == $game_map.map_id
      for j in 0...@area[i].day_period.size
        next unless @area[i].day_period[j].include?(hours)
        @last_map = $game_map.map_id
        @last_area = i
        @speed = @area[i].time_speed if @area[i].time_speed != 0
        @freeze_time = true if @area[i].time_speed == 0
        @time_overlap = @area[i].time_overlap
        refresh_tints
        tone = month_tint(@area[i].tint[j], i)
        tone = Tone.new(tone[0], tone[1], tone[2], tone[3])
        $game_screen.start_tone_change(tone, 0) if not @freeze_time and $game_screen.tone != tone
      end
    end
  end
  #--------------------------------------------------------------------------
  def weather_control(id)
    @thunder = @area[id].thunder
    weather = month_weather(@area[id].weather_prop.clone, id)
    if @last_area != id and weather[@current_weather[0]-1] == 0
      change_weather 
    else
      $game_screen.weather(0, 0, 0) unless @area[id].weather
      play_weather_sound(@current_weather[0], @area[id].weather_volume)
      if $game_screen.weather_type == 0 and @area[id].weather and @current_weather[1] 
        $game_screen.weather(@current_weather[0], rand(50)+1, 0)
      end
    end
  end
  #--------------------------------------------------------------------------
  def change_weather
    for i in 0...@area.size
      next unless @area[i].maps.include?($game_map.map_id)
      weather = []
      weather = month_weather(@area[i].weather_prop.clone, i)
      for j in 0...weather.size
        if weather[j] >= rand(100)+1
          if @area[i].weather
            $game_screen.weather(j+1, rand(50)+1, 500)
            @current_weather = [j+1, true]
          end
          play_weather_sound(j+1, @area[i].weather_volume)
          return
        end
      end
    end
    $game_screen.weather(0, 0, 500)
    play_weather_sound(0, 0)
    @current_weather = [0, false]
  end
  #--------------------------------------------------------------------------
  def play_weather_sound(type, volume)
    @type = type
    bgs = BGS.new
    bgs.volume = volume
    bgs.pitch = 100
    @type = 0 if volume == 0
    case @type
    when 1
      bgs.name = "005-Rain01"
      $game_system.bgs_play(bgs)
    when 2
      bgs.name = "006-Rain02"
      $game_system.bgs_play(bgs)
    when 4, 5
      bgs.name = "007-Rain03"
      $game_system.bgs_play(bgs)
    when 6
      bgs.name = "001-Wind01"
      $game_system.bgs_play(bgs)
    when 7
      bgs.name = "002-Wind02"
      $game_system.bgs_play(bgs)
    when 8
      bgs.name = "003-Wind03"
      $game_system.bgs_play(bgs)
    when 12
      bgs.name = "005-Rain01"
      $game_system.bgs_play(bgs)
    when 15
      bgs.name = "004-Wind04"
      $game_system.bgs_play(bgs)
    else
      $game_system.bgs_fade(0) unless $game_map.map.autoplay_bgs
      $game_system.bgs_play($game_map.map.bgs) if $game_map.map.autoplay_bgs
    end
  end
  #--------------------------------------------------------------------------
  def minutes_to(id, period)
    return 0 unless @area[id].day_period[period].include?(hours)
    @minutes = minutes
    @hours = hours
    area = @area[id].day_period[period]
    @minutes += (@hours - area.min) * @minute_length
    @minutes /= (((area.max - area.min) * @minute_length) + @minute_length - 1.00)
    return @minutes
  end
  #==============================================================================
  # TIME DEFINITIONS
  #==============================================================================
  def seconds(total = false)
    unless @freeze_time
      @time_count[0] = Graphics.frame_count - @frozen
      @time_count[1] += 0.12
      @timer = @time_count[0] * @speed if @time_overlap
      @timer = @time_count[1] * @speed unless @time_overlap
      @last_second[0] = @timer + @start_time[0]
      @last_second[1] = (@timer + @start_time[0]) % @second_length
      return Integer(@timer + @start_time[0]) if total
      return Integer(@timer + @start_time[0]) % @second_length
    else
      @frozen = Graphics.frame_count - @time_count[0]
      return Integer(@last_second[0]) if total
      return Integer(@last_second[1])
    end
  end
  #--------------------------------------------------------------------------
  def minutes(total = false)
    return Integer(seconds(true)/@second_length + @start_time[1]) if total
    return Integer(seconds(true)/@second_length + @start_time[1]) % @minute_length
  end
  #--------------------------------------------------------------------------
  def hours(total = false)
    return Integer(minutes(true)/@minute_length + @start_time[2]) if total
    return Integer(minutes(true)/@minute_length + @start_time[2]) % @hour_length
  end
  #--------------------------------------------------------------------------
  def days(total = false)
    return Integer(hours(true)/@hour_length + @start_time[3]-1) if total
    return Integer(hours(true)/@hour_length + @start_time[3] - 1) % @day_length + 1
  end
  #--------------------------------------------------------------------------
  def months(total = false)
    return Integer(days(true)/@day_length + @start_time[4]) if total
    return Integer(days(true)/@day_length + @start_time[4]) % @month_length
  end
  #--------------------------------------------------------------------------
  def years
    return Integer(months(true)/@month_length + @start_time[5])
  end
  #==============================================================================
  # TIME NAMES
  #==============================================================================
  def day_name
    return @day_name[(days % @week_length)-1]
  end
  #--------------------------------------------------------------------------
  def month_name
    return @month_name[(months % @month_length)-1]
  end
  #--------------------------------------------------------------------------
end
#==============================================================================
class Time_System
  #==============================================================================
  class Area
    #--------------------------------------------------------------------------
    attr_accessor :id
    attr_accessor :name
    attr_accessor :weather
    attr_accessor :weather_prop
    attr_accessor :prop_influence
    attr_accessor :weather_volume
    attr_accessor :thunder
    attr_accessor :maps
    attr_accessor :day_period
    attr_accessor :tint
    attr_accessor :tint_influence
    attr_accessor :time_speed
    attr_accessor :time_overlap
    #--------------------------------------------------------------------------
    def initialize(id)
      @id = id
      @name = ""
      @weather = false
      @weather_prop = []
      @prop_influence = false
      @weather_volume = 100
      @thunder = false
      @maps = []
      @day_period = []
      @tint = []
      @tint_influence = false
      @time_speed = 1.00
      @time_overlap = false
    end
    #--------------------------------------------------------------------------
  end
  #==============================================================================
end
#==============================================================================
class Scene_Title
  #--------------------------------------------------------------------------
  alias caldaron_time_title_data main_database
  #--------------------------------------------------------------------------
  def main_database
    caldaron_time_title_data
    $time = Time_System.new
  end
  #--------------------------------------------------------------------------
end
#==============================================================================
class Game_Map
  #--------------------------------------------------------------------------
  attr_reader   :map
  #--------------------------------------------------------------------------
  alias caldaron_time_map_init initialize
  def initialize
    @weather_wait = 0
    caldaron_time_map_init
  end
  #--------------------------------------------------------------------------
  alias caldaron_time_map_update update
  def update
    if $scene.is_a?(Scene_Map)
      $time.tone_change 
      @weather_wait -= 1 if @weather_wait > 0
      if @weather_wait == 0
        $time.change_weather
        @weather_wait = rand(4000) + 2000
      end
    end
    caldaron_time_map_update
  end
  #--------------------------------------------------------------------------
  def autoplay
    if @map.autoplay_bgm
      $game_system.bgm_play(@map.bgm)
    end
    if @map.autoplay_bgs and $time.current_weather[0] == 0
      $game_system.bgs_play(@map.bgs)
    end
  end
  #--------------------------------------------------------------------------
end
#==============================================================================
class Scene_Save < Scene_File
  #--------------------------------------------------------------------------
  alias caldaron_time_save_write write_data
  def write_data(file)
    caldaron_time_save_write(file)
    Marshal.dump($time, file)
  end
  #--------------------------------------------------------------------------
end
#==============================================================================
class Scene_Load < Scene_File
  #--------------------------------------------------------------------------
  alias caldaron_time_load_read read_data
  def read_data(file)
    caldaron_time_load_read(file)
    $time = Marshal.load(file)
  end
  #--------------------------------------------------------------------------
end
#==============================================================================
class BGS
  #--------------------------------------------------------------------------
  attr_accessor :name
  attr_accessor :volume
  attr_accessor :pitch
  #--------------------------------------------------------------------------
  def initialize
    @name = ""
    @volume = 80
    @pitch = 100
  end
  #--------------------------------------------------------------------------
end
#==============================================================================
end

Needs ccoa's Weather Script (very slighty edited)

Merry Christmas and a happy new Year!
 
Do you have a non-sdk version? i find sdk stupid and worthless, and lags very bad on a slow computer like mine when it has more scripts running besides it.
 
nope, sry, make a request for it, i won't step back in 'Script-Evolution' ;)
(SDK makes scripts more compatible, so you don't have always to merge scripts or ask about it)
think about it, i first thought SDK sucks too, but then i got what it is used and created for...
 

KazeN

Member

Is there a way to show the actual in-game time with this script? Like if I wanted to show it in the upper-right corner while on the field.
Also, is there a way to jump the in-game time? E.g. if the hero goes to sleep he will wake up at 7.00 in the morning.
Another thing that would be awesome and probably quite good to use is if you could use the time to make stuff happen only in certain intervals. For example, you could only get a quest by a guy that is around town between 10.00 pm and 4.00 am.

Is there a way to make any of these possible? It doesn't sound to hard, at least probably not to a scripter, but to me it is because I'm not a scripter ^_^
 
hmm, okay, too many people did request a time restriction, so here are some examples:
To let open the doors, when time is between x and y:
1. Create a door event :)
2. Make a conditional branch which calls this script:
Code:
$time.hours >= X and $time.hours < Y
# X is the opening time, Y the colsing time
That's all. if the Condition is given, let the door open and the actor enter the shop, if not, just give a message like "Shopping Hours: 8-16"
extend the conditional branch with:
Code:
and [Saturday,Sunday].include?($time.day_name)
This one is more circumstantially. you need 2 Events, the first is a "update event" the second the event you want to appear/disappear.
do the same as said in the "Opening times" spoiler, but when the condition is given, make a call script:
Code:
key = [$game_map.map_id, [COLOR=Red]ID[/COLOR], "[COLOR=Red]SELF[/COLOR]"]
$game_self_switches[key] = [COLOR=Blue]true[/COLOR]
# ID: The ID of the event
# SELF: The SelfSwitch |A, B, C, D|
do the same when the condition is not given, but change true to false
The Condition SelfSwitch SELF must be enabled
About the Time Change: A really need to edit this, that's some big crap i scripted...
About the Time in Map: Put it on my to do list (but first i got to update my ABS things, so you'd better ask s.o. else for it ;) )
 
!UPDATE!

I edited the time_change thingy so you only have to change the main variable and it will immediately take effect.

You can change the time via 'call script' and write in:
Code:
$time.time[x] = whatever
What x can be
Code:
0 -> Seconds
1 -> Minutes
2 -> Hours
3 -> Days
4 -> Months
5 -> Years

I also added $time.freeze_tone
-> freezes the tone fade; e.g. to let the hero collapse and fade the screen black

#==============================================================================
# Time System Script v. 1.04
# by Caldaron (16.05.2007)
#==============================================================================
SDK.log("Caldaron's Time", 'Caldaron', 1.04, '2006-11-1')

if SDK.state("Caldaron's Time")
#==============================================================================
class Time_System
#--------------------------------------------------------------------------
attr_reader :current_weather
attr_accessor :freeze_time
attr_accessor :freeze_tone
attr_accessor :thunder
attr_accessor :time_count
attr_accessor :time
#--------------------------------------------------------------------------
def initialize
@second_length = 60
@minute_length = 60
@hour_length = 24
@day_length = 30
@week_length = 7
@month_length = 12
@last_minute = nil
@last_second = [0,0]
@freeze_time = false
@freeze_tone = false
@current_weather = [0, false]
@last_map = 0
@last_area = 0
@thunder = false
@speed = 1.00
@time_count = [0, 0]
@time_overlap = true
@frozen = 0
@timer = 1
#==============================================================================
# DATE NAMES
#==============================================================================
@day_name = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday"]
@month_name = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]
#==============================================================================
# START DATE
#==============================================================================
@time = [58, 56, 11, 25, 3, 619]
create_areas
end
#==============================================================================
# AREA DEFINITIONS
#==============================================================================
def create_areas
#--------------------------------------------------------------------------
# Areas
#--------------------------------------------------------------------------
@area = []

@area[0] = Area.new(0)

@area[1] = Area.new(1)

@area[2] = Area.new(2)

@area[3] = Area.new(3)
#--------------------------------------------------------------------------
# Area Name
#--------------------------------------------------------------------------
@area[0].name = "Outside"

@area[1].name = "Inside"

@area[2].name = "Cave"

@area[3].name = "Snow Field"
#--------------------------------------------------------------------------
# Weather in this Area?
#--------------------------------------------------------------------------
@area[0].weather = true

@area[1].weather = false

@area[2].weather = false

@area[3].weather = true
#--------------------------------------------------------------------------
# Speed of Time in this Area?
# the higher the Value, the faster the Time
#--------------------------------------------------------------------------
@area[0].time_speed = 1.00

@area[1].time_speed = 0.50

@area[2].time_speed = 1.25

@area[3].time_speed = 2.00
#--------------------------------------------------------------------------
# Time overlaps?
# true: Different Times with different Speed of Time in different Areas
# false: Same Time but different Speed of Time in different Areas
#--------------------------------------------------------------------------
@area[0].time_overlap = true

@area[1].time_overlap = true

@area[2].time_overlap = true

@area[3].time_overlap = true
#--------------------------------------------------------------------------
# Propabilities of the Weathertypes:
# Weather at Position
# 1 - rain
# 2 - storm
# 3 - snow
# 4 - hail
# 5 - rain with thunder and lightning
# 6 - falling leaves (autumn)
# 7 - blowing leaves (autumn)
# 8 - swirling leaves (autumn)
# 9 - falling leaves (green)
# 10 - cherry blossom (sakura) petals
# 11 - rose petals
# 12 - feathers
# 13 - blood rain
# 14 - sparkles
# 15 - user defined
# 16 - blowing snow
# 17 - meteor shower
# 18 - falling ash
# 19 - bubbles
# Rest of the Percentage will be Sunshine
#--------------------------------------------------------------------------
for i in 0...@area.size
@area.weather_prop = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
end
# Outside
@area[0].weather_prop[0] = 20 # rain
@area[0].weather_prop[1] = 10 # storm
@area[0].weather_prop[4] = 10 # thunder
# Inside
@area[1].weather_prop = @area[0].weather_prop
# when @area.weather = false and @area.weather_prop is the same as the last map
# (which is in an other area) only the sound will be played
# Cave
# @area[2].weather_prop needs no editing, because there is no weather ;)
# Snow Field
@area[3].weather_prop[2] = 20
@area[3].weather_prop[3] = 10
@area[3].weather_prop[15] = 10
#--------------------------------------------------------------------------
# Months influence Propability?
#--------------------------------------------------------------------------
@area[0].prop_influence = true

@area[1].prop_influence = true

@area[2].prop_influence = false

@area[3].prop_influence = false
#--------------------------------------------------------------------------
# Volume of the Weather
#--------------------------------------------------------------------------
@area[0].weather_volume = 100

@area[1].weather_volume = 80

@area[2].weather_volume = 0

@area[3].weather_volume = 100
#--------------------------------------------------------------------------
# Thunder light in this Area?
#--------------------------------------------------------------------------
@area[0].thunder = true

@area[1].thunder = false

@area[2].thunder = false

@area[2].thunder = false
#--------------------------------------------------------------------------
# Maps included in this Area
# Example: @area[6].maps = [6, 13, 19]
#--------------------------------------------------------------------------
@area[0].maps = [1, 2]

@area[1].maps = [3]

@area[2].maps = [4]

@area[3].maps = [5]
#--------------------------------------------------------------------------
# Day Period
# must be Range: (x..y)
# must include all hours from 0 to @hours_length-1
#--------------------------------------------------------------------------
@area[0].day_period[0] = (0..3)
@area[0].day_period[1] = (4..7)
@area[0].day_period[2] = (8..11)
@area[0].day_period[3] = (12..15)
@area[0].day_period[4] = (16..19)
@area[0].day_period[5] = (20..23)

@area[1].day_period[0] = (0..23)

@area[2].day_period[0] = (0..23)

@area[3].day_period = @area[0].day_period
#--------------------------------------------------------------------------
# Months influence Tint?
#--------------------------------------------------------------------------
@area[0].tint_influence = true

@area[1].tint_influence = true

@area[2].tint_influence = false

@area[3].tint_influence = false
end
#--------------------------------------------------------------------------
# minutes_to(Area ID, Tint ID)
# Max Distance is 1
# Example:
# minutes_to(0, 0) * 25
# Value slowly grows from 0 to 25, by dividing the max reachable with the
# current minutes in this day period
#--------------------------------------------------------------------------
def refresh_tints # initialize_tints
# tints must be equal the day_period.size
@area[0].tint[0] = [-200 + minutes_to( 0, 0) * 25, -175 + minutes_to( 0, 0) * 25,
-100, 32]

@area[0].tint[1] = [-175 + minutes_to( 0, 1) * 75, -150 + minutes_to( 0, 1) * 75,
-100 + minutes_to( 0, 1) * 50, 32 - minutes_to( 0, 1) * 16]

@area[0].tint[2] = [-100 + minutes_to( 0, 2) * 85, -75 + minutes_to( 0, 2) * 60,
-50 + minutes_to( 0, 2) * 35, 16 - minutes_to( 0, 2) * 16]

@area[0].tint[3] = [ -15 - minutes_to( 0, 3) * 20, -15 - minutes_to( 0, 3) * 35,
-15 - minutes_to( 0, 3) * 60, 0 + minutes_to( 0, 3) * 8]

@area[0].tint[4] = [ -35 - minutes_to( 0, 4) * 75, -50 - minutes_to( 0, 4) * 50,
-75 - minutes_to( 0, 4) * 25, 8 + minutes_to( 0, 4) * 8]

@area[0].tint[5] = [-110 - minutes_to( 0, 5) * 90, -100 - minutes_to( 0, 5) * 75,
-100, 16 + minutes_to( 0, 5) * 16]

@area[1].tint[0] = [0, 0, 0, 0]

@area[2].tint[0] = [0, 0, 0, 0]

@area[3].tint = @area[0].tint
for i in 0...@area[0].tint.size
@area[3].tint[2] = @area[0].tint[2]-20
end
end
#--------------------------------------------------------------------------
# tone[0] = red / tone[1] = green / tone[2] = blue / tone[3] = gray
#--------------------------------------------------------------------------
def month_tint(tone, i)
tona = []
if @area.tint_influence
case @time[4]
when 1
tona.push(tone[0]-10, tone[1]-10, tone[2], tone[3] + 8)
else
tona.push(tone[0], tone[1], tone[2], tone[3])
end
else
tona.push(tone[0], tone[1], tone[2], tone[3])
end
return tona
end
#--------------------------------------------------------------------------
def month_weather(prop, i)
# 0 - rain
# 1 - storm
# 2 - snow
# 3 - hail
# 4 - rain with thunder and lightning
# 5 - falling leaves (autumn)
# 6 - blowing leaves (autumn)
# 7 - swirling leaves (autumn)
# 8 - falling leaves (green)
# 9 - cherry blossom (sakura) petals
# 10 - rose petals
# 11 - feathers
# 12 - blood rain
# 13 - sparkles
# 14 - user defined
# 15 - blowing snow
# 16 - meteor shower
# 17 - falling ash
# 18 - bubbles
if @area.prop_influence
case @time[4]
when 1, 2, 12
prop[0] = 0
prop[1] = 0
prop[2] += @area.weather_prop[0]
prop[3] += @area.weather_prop[4]
prop[4] = 0
prop[15] += @area.weather_prop[1]
when 3..5
prop[0] /= 2
prop[1] /= 2
prop[9] += @area.weather_prop[0]/2
prop[10] += @area.weather_prop[1]/2
when 6..8
# is the standard definition of weather_prop
when 9..11
prop[0] /= 2
prop[1] /= 2
prop[4] /= 2
prop[5] += @area.weather_prop[0]/2
prop[6] += @area.weather_prop[1]/2
prop[7] += @area.weather_prop[4]/2
end
end
return prop
end
#--------------------------------------------------------------------------
# NO MORE TO EDIT
#--------------------------------------------------------------------------
def tone_change
for i in 0...@area.size
next unless @area.maps.include?($game_map.map_id)
weather_control(i) unless @last_map == $game_map.map_id
for j in 0...@area.day_period.size
next unless @area.day_period[j].include?(@time[2])
@last_map = $game_map.map_id
@last_area = i
@speed = @area.time_speed if @area.time_speed != 0
@freeze_time = true if @area.time_speed == 0
@time_overlap = @area.time_overlap
refresh_tints
tone = month_tint(@area.tint[j], i)
tone = Tone.new(tone[0], tone[1], tone[2], tone[3])
$game_screen.start_tone_change(tone, 0) if not @freeze_time and $game_screen.tone != tone
end
end
end
#--------------------------------------------------------------------------
def weather_control(id)
@thunder = @area[id].thunder
weather = month_weather(@area[id].weather_prop.clone, id)
if @last_area != id and weather[@current_weather[0]-1] == 0
change_weather
else
$game_screen.weather(0, 0, 0) unless @area[id].weather
play_weather_sound(@current_weather[0], @area[id].weather_volume)
if $game_screen.weather_type == 0 and @area[id].weather and @current_weather[1]
$game_screen.weather(@current_weather[0], rand(50)+1, 0)
end
end
end
#--------------------------------------------------------------------------
def change_weather
for i in 0...@area.size
next unless @area.maps.include?($game_map.map_id)
weather = []
weather = month_weather(@area.weather_prop.clone, i)
for j in 0...weather.size
if weather[j] >= rand(100)+1
if @area.weather
$game_screen.weather(j+1, rand(50)+1, 500)
@current_weather = [j+1, true]
end
play_weather_sound(j+1, @area.weather_volume)
return
end
end
end
$game_screen.weather(0, 0, 500)
play_weather_sound(0, 0)
@current_weather = [0, false]
end
#--------------------------------------------------------------------------
def play_weather_sound(type, volume)
@type = type
bgs = BGS.new
bgs.volume = volume
bgs.pitch = 100
@type = 0 if volume == 0
case @type
when 1
bgs.name = "005-Rain01"
$game_system.bgs_play(bgs)
when 2
bgs.name = "006-Rain02"
$game_system.bgs_play(bgs)
when 4, 5
bgs.name = "007-Rain03"
$game_system.bgs_play(bgs)
when 6
bgs.name = "001-Wind01"
$game_system.bgs_play(bgs)
when 7
bgs.name = "002-Wind02"
$game_system.bgs_play(bgs)
when 8
bgs.name = "003-Wind03"
$game_system.bgs_play(bgs)
when 12
bgs.name = "005-Rain01"
$game_system.bgs_play(bgs)
when 15
bgs.name = "004-Wind04"
$game_system.bgs_play(bgs)
else
$game_system.bgs_fade(0) unless $game_map.map.autoplay_bgs
$game_system.bgs_play($game_map.map.bgs) if $game_map.map.autoplay_bgs
end
end
#--------------------------------------------------------------------------
def minutes_to(id, period)
return 0 unless @area[id].day_period[period].include?(@time[2])
@minutes = @time[1]
@hours = @time[2]
area = @area[id].day_period[period]
@minutes += (@hours - area.min) * @minute_length
@minutes /= (((area.max - area.min) * @minute_length) + @minute_length - 1.00)
return @minutes
end
#--------------------------------------------------------------------------
def play
@sec_wait = 0 unless @sec_wait
@sec_wait += 1
if @sec_wait >= Graphics.frame_rate
@time[0] += 1
end
# Seconds > Minutes
if @time[0] >= @second_length
@time[0] -= @second_length
@time[1] += 1
end
# Minutes > Hours
if @time[1] >= @minute_length
@time[1] -= @minute_length
@time[2] += 1
end
# Hours > Days
if @time[2] >= @hour_length
@time[2] -= @hour_length
@time[3] += 1
end
# Days > Months
if @time[3] >= @day_length
@time[3] -= @day_length
@time[4] += 1
end
# Months > Years
if @time[4] >= @month_length
@time[4] -= @month_length
@time[5] += 1
end
end
#==============================================================================
# TIME NAMES
#==============================================================================
def day_name
return @day_name[(@time[3] % @week_length)-1]
end
#--------------------------------------------------------------------------
def month_name
return @month_name[(@time[4] % @month_length)-1]
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Time_System
#==============================================================================
class Area
#--------------------------------------------------------------------------
attr_accessor :id
attr_accessor :name
attr_accessor :weather
attr_accessor :weather_prop
attr_accessor :prop_influence
attr_accessor :weather_volume
attr_accessor :thunder
attr_accessor :maps
attr_accessor :day_period
attr_accessor :tint
attr_accessor :tint_influence
attr_accessor :time_speed
attr_accessor :time_overlap
#--------------------------------------------------------------------------
def initialize(id)
@id = id
@name = ""
@weather = false
@weather_prop = []
@prop_influence = false
@weather_volume = 100
@thunder = false
@maps = []
@day_period = []
@tint = []
@tint_influence = false
@time_speed = 1.00
@time_overlap = false
end
#--------------------------------------------------------------------------
end
#==============================================================================
end
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
alias caldaron_time_title_data main_database
#--------------------------------------------------------------------------
def main_database
caldaron_time_title_data
$time = Time_System.new
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
attr_reader :map
#--------------------------------------------------------------------------
alias caldaron_time_map_init initialize
def initialize
@weather_wait = 0
caldaron_time_map_init
end
#--------------------------------------------------------------------------
alias caldaron_time_map_update update
def update
if $scene.is_a?(Scene_Map)
unless $time.freeze_time
$time.play
end
unless $time.freeze_tone
$time.tone_change
end
@weather_wait -= 1 if @weather_wait > 0
if @weather_wait == 0
$time.change_weather
@weather_wait = rand(4000) + 2000
end
end
caldaron_time_map_update
end
#--------------------------------------------------------------------------
def autoplay
if @map.autoplay_bgm
$game_system.bgm_play(@map.bgm)
end
if @map.autoplay_bgs and $time.current_weather[0] == 0
$game_system.bgs_play(@map.bgs)
end
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Scene_Save < Scene_File
#--------------------------------------------------------------------------
alias caldaron_time_save_write write_data
def write_data(file)
caldaron_time_save_write(file)
Marshal.dump($time, file)
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Scene_Load < Scene_File
#--------------------------------------------------------------------------
alias caldaron_time_load_read read_data
def read_data(file)
caldaron_time_load_read(file)
$time = Marshal.load(file)
end
#--------------------------------------------------------------------------
end
#==============================================================================
class BGS
#--------------------------------------------------------------------------
attr_accessor :name
attr_accessor :volume
attr_accessor :pitch
#--------------------------------------------------------------------------
def initialize
@name = ""
@volume = 80
@pitch = 100
end
#--------------------------------------------------------------------------
end
#==============================================================================
end

IF you want to see da Time
class Time_Screen < Window_Base

def initialize
super(0, 0, 304, 64)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end

def refresh
self.contents.clear
@sec = $time.time[0]
@min = $time.time[1]
@hour = $time.time[2]
@day = $time.time[3]
@mon = $time.time[4]
@year = $time.time[5]
text = sprintf("%02d:%02d:%02d Day %02d Month %d Year %d", @hour, @min, @sec, @day, @mon, @year)
self.contents.draw_text(0, 0, 272, 32, text, 1)
end

end

class Game_Map

alias caldaron_timer_map_initialize initialize
def initialize
@timer_window = Time_Screen.new
caldaron_timer_map_initialize
end

alias caldaron_timer_map_update update
def update
@timer_window.refresh
caldaron_timer_map_update
end
end
 
can you make it so:

when you are in the a House and it is Thunder,
at the time the bolt came a var should be true.

EDIT:

can you make, that if you dont have the script from ccoa,
the weather did not function, but the time system?
 

Fox

Member

Caldaron":33sss994 said:
!UPDATE!

I edited the time_change thingy so you only have to change the main variable and it will immediately take effect.

You can change the time via 'call script' and write in:
Code:
$time.time[x] = whatever
What x can be
Code:
0 -> Seconds
1 -> Minutes
2 -> Hours
3 -> Days
4 -> Months
5 -> Years

Does this progress time? Like if I put in $time.time[2] = 6 would it add 6 hours to go to 6:00?

Edit: I also just noticed that your updated script continually returns the following error:
     
Script 'Time System' line 135 NoMethodError occured.
               undefined method 'weathor_prop=' for #<Array:0x2349248>

I've noticed that [ i ] (no spaces) is missing from a lot of the @area[ i ]. sections. @area[ i ].tint_influence, @area[ i ].weather_prop, etc.
I don't know much about scripting or even if that matters, it's just an observation I've made after comparing the two scripts.
 

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