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.
Hi, this is a request for two existing scripts. I would like a Day and Night system as well as a Weather system that both DO NOT REQUIRE SDK. I just want ones that simply allow time-based, editable weather, such as rain, storm, but not snow. As for the day and night system, I'd like one that you can turn off and on for indoors and can edit the screen tone of day and night. Thanks a bundle to anyone who can link me to them.
You can have my Day-Night system, which is very customizable.
To change the tones, just edit line 229 and below. Change the 4 numbers, the order is Red, Blue, Green, Gray.
It doesn't have weathers though.
You can:
pause the clock, and set it
start from an hour of your choice when the game begins,
Or use Real Time- taken from the user's computer.
To freeze the clock do: $game_clock.freeze=true
To unfreeze simply do $game_clock.unfreeze
To check the time, use: $game_clock.hour, $game_clock.min, and $game_clock.sec in a conditional branch. (if $game_clock.hour==12)
To check if it's night time(00:00~5:59) do $game_dns.night_time?
To set the clock do: $game_clock.set_time(hour,min,sec)
To turn tone on/off, use $game_dns.tone_off, $game_dns.tone_on
To use the clock in a HUD, inside the HUD add:
self.contents.draw_text(x, y, 200, 32, $game_clock.as_text)
set x and y, the screen coordinates to your needs. It goes in the 'update' method
[rgss]
#==============================================================================
# ** DNS-
#------------------------------------------------------------------------------
# Day/Night system.
# This class handles clock, screen tone and pnorama.
# refer to $game_clock or $game_dns to access this class.
# the dns saves day time/ screen tone and uses the $game_clock class.
#==============================================================================
#to start, set these first!
$use_real_time = true
$start_clock_from= {'hour' =>5, 'minute' =>59, 'second' =>50}
#---------------------------------------#
# Game_map
# new method: get map name.
#---------------------------------------#
class Game_Map
# use $game_map.name to get the name.
def name
$data_mapinfos = load_data('Data/MapInfos.rxdata')
name = $data_mapinfos[@map_id].name
return name
end
end
#-------------------------------------------------#
# game clock- #
# you can select initial hour, pause #
# and set the clock. #
#-------------------------------------------------#
class Clock
attr_reader :hour
attr_reader :min
attr_reader :sec
attr_accessor :clock
attr_accessor :real_time
attr_accessor :freeze # set this to true to pause the clock.
def initialize
@real_time=Time.now
@freeze=false
init_clock
refresh
end
def init_clock
if ($use_real_time)
@hour=@real_time.hour
@min=@real_time.min # was minute
@sec=@real_time.sec # was second
else #set to default
@hour=$start_clock_from['hour']
@min=$start_clock_from['minute']
@sec=$start_clock_from['second']
end
end
def wait_a_sec
while(true)
refresh_at_need
Graphics.update
if Graphics.frame_count / Graphics.frame_rate != @total_sec
break
end
end
#$game_system.se_play($data_system.cancel_se)
end
def wait(seconds)
for i in 0...seconds
wait_a_sec
end
end
def sec_passed?(start_time,seconds)
s = seconds%60
m = seconds/60
h = m/60
flag = true
if h>0 : flag = hour_passed?(start_time,h) end
if m>0 : flag = flag && min_passed?(start_time,m) end
old_sec = start_time['sec']
new_sec = (old_sec + s)%60
flag = flag && (@sec == new_sec)
return flag
end
def min_passed?(start_time,minutes)
m = minutes%60
h = minutes/60
flag = true
if h>0 : flag = hour_passed?(h) end
old_min = start_time['min']
new_min = (old_min + m)%60
flag = flag && (@min == new_min)
return flag
end
def hour_passed?(start_time,hours)
h = hours%24
old_hour = start_time['hour']
new_hour = (old_hour + h)%24
flag = flag && (@hour == new_hour)
return flag
end
def get_cur_time
return {'hour'=>@hour,'min'=>@min,'sec'=>@sec}
end
def as_text
return st = sprintf("%02d:%02d:%02d", @hour, @min, @sec)
end
def refresh_at_need
return if (@freeze)
if Graphics.frame_count / Graphics.frame_rate != @total_sec
refresh
end
end
def update
if (@sec==60)
@min = @min+1
@sec = 0
end
if (@min==60)
@hour = hour+1
@min = 0
end
if (@hour==24)
#restart
set_time(0,0,0)
end
if ($game_dns)
$game_dns.set_tone
end
end
def set_time(hour,min,sec)
@hour=hour
@min=min
@sec=sec
$game_dns.change_tone
end
def unfreeze
@freeze=false
refresh
end
#-----------------------------------------#
# returns curent time, in total sconds.
# can be used to check if x time passed.
#-----------------------------------------#
def cur_time
return @total_sec
end
def print
refresh_at_need
st = sprintf("%02d:%02d:%02d", @hour, @min, @sec)
p st
end
end #class end
#---------------------------------------#
# DNS system
#---------------------------------------#
class DNS
#attr_accessor :clock # game clock
attr_accessor :time_of_day # night, morning, noon, evening.
# boolean values.
#method :night_time? # is it night time?
#variable: tone_off # change screen tone to fit time of day?
attr_accessor :inside # is the current map Interior?
def initialize
$game_clock=Clock.new
@freeze=false
@inside=false
@tone_off=false
@time_of_day=find_day_time
@tones=dns_tones
change_tone # set the right screen tone
#p "It is #{@time_of_day}. night_time returned #{self.night_time?}"
#@clock.set_time(12,0,0)
#@clock.print
#while (!@freeze)
#$game_clock.update
#tone,panorama,etc
#end
end
def find_day_time
if ($game_clock.hour<6)
return 'night'
elsif ($game_clock.hour<12)
return 'morning'
elsif ($game_clock.hour<18)
return 'noon'
end
return 'evening'
end
def night_time?
b = ($game_clock.hour < 6)? true : false
return b
end
def dns_tones
#morning
tone1= Tone.new(-51,-51,-34,51)
#noon- normal
tone2= Tone.new(0,0,0,0)
#evening
tone3= Tone.new(-85,-85,-34,51)
#night
tone4= Tone.new(-153,-119,-68,68)
return {'morning'=>tone1, 'noon'=>tone2, 'evening'=>tone3,'night'=>tone4}
end
#use when the second is 0.
def set_tone
return if (tone_off)
#change screen tone if clock is 6:00, 12:00, 18:00, 00:00
return if (($game_clock.hour % 6 !=0) or ($game_clock.min!=0))
return if ($game_clock.sec>2)
change_tone
end
def change_tone
hour=$game_clock.hour
hour=hour/6
case hour
when 0: tone=@tones['night'] # hour: 0~5
when 1: tone=@tones['morning'] # hour: 6~11
when 2: tone=@tones['noon'] # hour: 12~17
when 3: tone=@tones['evening'] # hour: 18~23
else print "error: hour is out of range [0,23]"
end
duration=20
if (!tone)
tone=@tones['noon']
end
$game_screen.start_tone_change(tone, duration)
end
def tone_off
@tone_off = true
$game_screen.start_tone_change(Tone.new(0,0,0,0), 20)
end
def tone_on
@tone_off = false
change_tone
end
end #class end
class Scene_Title
def command_new_game
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Stop BGM
Audio.bgm_stop
# Reset frame count for measuring play time
Graphics.frame_count = 0
# Make each type of game object
$game_temp = Game_Temp.new
$game_system = Game_System.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
# Set up initial party
$game_party.setup_starting_members
# Set up initial map position
$game_map.setup($data_system.start_map_id)
# Move player to initial position
$game_player.moveto($data_system.start_x, $data_system.start_y)
# Refresh player
$game_player.refresh
#-----edit---------------------#
$game_dns=DNS.new
#------------------------------#
# Run automatic change for BGM and BGS set with map
$game_map.autoplay
# Update map (run parallel process event)
$game_map.update
# Switch to map screen
$scene = Scene_Map.new
end
end
class Scene_Load < Scene_File
alias dns_read_save_data read_save_data
def read_save_data(file)
dns_read_save_data(file)
$game_dns = Marshal.load(file)
end
end
class Scene_Save < Scene_File
alias dns_write_save_data write_save_data
def write_save_data(file)
dns_write_save_data(file)
Marshal.dump($game_dns, file)
end
end
class Scene_Map
alias dns_update update
def update
dns_update
$game_clock.refresh_at_need
end