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.

Need this to be modified to include AM and PM

Yin

Member

Script Request Template
Hey all, this is a request to modify a day/night script to include am and pm. Meaning 24 hours, but only up to 12 for am and 12 for pm. And also, tell me how I would make a condition for something to happen in my game depending on what time it is.

Script Title:
Modified Day Night

RMXP or RMVX:
XP
Detailed Description:
Here is the script
Code:
#==============================================================================

# ** Window_PlayTime + Day & Night Settings Script

#    Window_PlayTime Add-on

#    modified by shadowball

#

#  On the Menu scene you'll see the current in-game day and time...

#==============================================================================

 

class Window_GameStats < Window_Base

 

 def initialize

   super(0, 0, 160, 96)

   self.contents = Bitmap.new(width - 32, height - 32)

   refresh

 end

 

 def refresh

   self.contents.clear

   @total_sec = Graphics.frame_count / Graphics.frame_rate

   day = @total_sec / 60 / 24 % 7

   hour = @total_sec / 60 % 24

   minute = @total_sec % 60

   text = sprintf("%02d:%02d", hour, minute)

   self.contents.font.color = system_color

   shb_day = 'Sunday'    if day == 0

   shb_day = 'Monday'    if day == 1

   shb_day = 'Tuesday'   if day == 2

   shb_day = 'Wednesday' if day == 3

   shb_day = 'Thursday'  if day == 4

   shb_day = 'Friday'    if day == 5

   shb_day = 'Saturday'  if day == 6

   shb_weekday = shb_day

   self.contents.draw_text(4, -10, 120, 32, shb_weekday, 0)

   self.contents.font.color = normal_color

   self.contents.draw_text(4, 4, 120, 32, text, 2)

   

   case $game_party.gold

   when 0..9999

     gold = $game_party.gold

   when 10000..99999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+","+array[2].to_s+array[3].to_s+array[4].to_s

   when 100000..999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+array[2].to_s+","+array[3].to_s+array[4].to_s+array[5].to_s

   when 1000000..9999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+","+array[1].to_s+array[2].to_s+array[3].to_s+","+array[4].to_s+array[5].to_s+array[6].to_s

   end

#Draw Gold

 self.contents.font.color = system_color

 gold_word = $data_system.words.gold.to_s

 cx = contents.text_size(gold_word).width

 cx2=contents.text_size(gold.to_s).width

 self.contents.draw_text(4, 18, 120-cx-2, 32, gold_word)

 self.contents.font.color = normal_color

 self.contents.draw_text(124-cx2+1,32, cx2, 32, gold.to_s, 2)

 self.contents.font.color = system_color

 end

 

 def update

   super

   if Graphics.frame_count / Graphics.frame_rate != @total_sec

     refresh

   end

 end

end

 

#==============================================================================

#  *  Scene_Map - Modified

#     modified by shadowball

#

#  Screen tone will change depending on the in-game play time automatically

#==============================================================================

class Scene_Map

 alias shb_map_up update

 def update

   @total_sec = Graphics.frame_count / Graphics.frame_rate

   @shb_hour = @total_sec / 60 % 24

   if @shb_hour < 5 || @shb_hour > 18     # 7 p.m. - 5 a.m.

     $game_screen.start_tone_change(Tone.new(-120, -120, -120, 0), 1)

   elsif @shb_hour > 4 && @shb_hour < 7   # 5 a.m. - 7 a.m.

     $game_screen.start_tone_change(Tone.new(-40, -40, 0, 0), 1)

   elsif @shb_hour > 6 && @shb_hour < 16  # 7 a.m. - 4 p.m.

     $game_screen.start_tone_change(Tone.new(0, 0, 0, 0), 1)

   elsif @shb_hour > 15 && @shb_hour < 19 # 4 p.m. - 7 p.m.

     $game_screen.start_tone_change(Tone.new(30, 10, 0, 0), 1)

   end

   shb_map_up

 end

end

 

#=======================================================

#  *  Game_System Add-on v 1.0

#     by shadowball

#     08.02.2008

#

#  You can set the time in minutes, hours, days

#  Syntax:  $game_system.set_time(0, 30, 2, 3)

#=======================================================

class Game_System

 def set_time(alter = 0, minute = 0, hour = 0, day = 0)

   if minute >= 0

     if minute >= 60

       minute = 59

     end

     set_min = Graphics.frame_rate * minute

   end

   if hour >= 0

     if hour >= 24

       hour = 23

     end

     set_hour = Graphics.frame_rate * 60 * hour

   end

   if day >= 0

     if day >= 31

       day = 30

     end

     set_day = Graphics.frame_rate * 60 * 24 * day

   end

   

   case alter

   when 0 # sets the time

     Graphics.frame_count = 0 + set_day + set_hour + set_min

   when 1 # adds the hours, minutes you specified to the current in-game playtime

     Graphics.frame_count = Graphics.frame_count + set_day + set_hour + set_min

   when 2 # this one does exactly the opposite...

     Graphics.frame_count = Graphics.frame_count - set_day - set_hour - set_min

   end

 end

end
Screen shots:
No screen shot, just tinted screens and stuff.

Other Scripts I am using (in order):
I don't think adding AM and PM will conflict with any of my other scripts, but I have a lot of scripts installed.
Here is my scripts.rxdata. Just paste it and you will see exactly what scripts I am using and by who they were made.
http://www.sendspace.com/file/51gdqc

Thank you to anyone who is willing to take on this task.

EDIT:
Also, it can keep it's 24 hour scheme, but I just want it to DISPLAY in 12 hour format in the menu. Meaning, you don't really have to change anything in the script if you can get it to display it in 12 hour AM and PM format. Also, class Window_GameStats is really class Window_PlayTime if it matters or makes it any easier.
 
Okay. This should do the trick. Though you should know that the additional AM and PM makes the clock hit the Y in the day name. You might need to play around with the size of the window and the positioning of the info.

Code:
#==============================================================================

# ** Window_PlayTime + Day & Night Settings Script

#    Window_PlayTime Add-on

#    modified by shadowball

#

#  On the Menu scene you'll see the current in-game day and time...

#==============================================================================

 

class Window_GameStats < Window_Base

 

 def initialize

   super(0, 0, 160, 96)

   self.contents = Bitmap.new(width - 32, height - 32)

   refresh

 end

 

 def refresh

   self.contents.clear

   @total_sec = Graphics.frame_count / Graphics.frame_rate

   day = @total_sec / 60 / 24 % 7

   hour = @total_sec / 60 % 24

   minute = @total_sec % 60

   if hour >= 12

     meridian = " pm"

   else

     meridian = " am"

   end

   if hour == 0 then hour = 12 end

   if hour > 12 then hour -= 12 end

   text = sprintf("%02d:%02d", hour, minute)

   text = text + meridian

   self.contents.font.color = system_color

   shb_day = 'Sunday'    if day == 0

   shb_day = 'Monday'    if day == 1

   shb_day = 'Tuesday'   if day == 2

   shb_day = 'Wednesday' if day == 3

   shb_day = 'Thursday'  if day == 4

   shb_day = 'Friday'    if day == 5

   shb_day = 'Saturday'  if day == 6

   shb_weekday = shb_day

   self.contents.draw_text(4, -10, 120, 32, shb_weekday, 0)

   self.contents.font.color = normal_color

   self.contents.draw_text(4, 4, 120, 32, text, 2)

   

   case $game_party.gold

   when 0..9999

     gold = $game_party.gold

   when 10000..99999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+","+array[2].to_s+array[3].to_s+array[4].to_s

   when 100000..999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+array[2].to_s+","+array[3].to_s+array[4].to_s+array[5].to_s

   when 1000000..9999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+","+array[1].to_s+array[2].to_s+array[3].to_s+","+array[4].to_s+array[5].to_s+array[6].to_s

   end

#Draw Gold

 self.contents.font.color = system_color

 gold_word = $data_system.words.gold.to_s

 cx = contents.text_size(gold_word).width

 cx2=contents.text_size(gold.to_s).width

 self.contents.draw_text(4, 18, 120-cx-2, 32, gold_word)

 self.contents.font.color = normal_color

 self.contents.draw_text(124-cx2+1,32, cx2, 32, gold.to_s, 2)

 self.contents.font.color = system_color

 end

 

 def update

   super

   if Graphics.frame_count / Graphics.frame_rate != @total_sec

     refresh

   end

 end

end

 

#==============================================================================

#  *  Scene_Map - Modified

#     modified by shadowball

#

#  Screen tone will change depending on the in-game play time automatically

#==============================================================================

class Scene_Map

 alias shb_map_up update

 def update

   @total_sec = Graphics.frame_count / Graphics.frame_rate

   @shb_hour = @total_sec / 60 % 24

   if @shb_hour < 5 || @shb_hour > 18     # 7 p.m. - 5 a.m.

     $game_screen.start_tone_change(Tone.new(-120, -120, -120, 0), 1)

   elsif @shb_hour > 4 && @shb_hour < 7   # 5 a.m. - 7 a.m.

     $game_screen.start_tone_change(Tone.new(-40, -40, 0, 0), 1)

   elsif @shb_hour > 6 && @shb_hour < 16  # 7 a.m. - 4 p.m.

     $game_screen.start_tone_change(Tone.new(0, 0, 0, 0), 1)

   elsif @shb_hour > 15 && @shb_hour < 19 # 4 p.m. - 7 p.m.

     $game_screen.start_tone_change(Tone.new(30, 10, 0, 0), 1)

   end

   shb_map_up

 end

end

 

#=======================================================

#  *  Game_System Add-on v 1.0

#     by shadowball

#     08.02.2008

#

#  You can set the time in minutes, hours, days

#  Syntax:  $game_system.set_time(0, 30, 2, 3)

#=======================================================

class Game_System

 def set_time(alter = 0, minute = 0, hour = 0, day = 0)

   if minute >= 0

     if minute >= 60

       minute = 59

     end

     set_min = Graphics.frame_rate * minute

   end

   if hour >= 0

     if hour >= 24

       hour = 23

     end

     set_hour = Graphics.frame_rate * 60 * hour

   end

   if day >= 0

     if day >= 31

       day = 30

     end

     set_day = Graphics.frame_rate * 60 * 24 * day

   end

   

   case alter

   when 0 # sets the time

     Graphics.frame_count = 0 + set_day + set_hour + set_min

   when 1 # adds the hours, minutes you specified to the current in-game playtime

     Graphics.frame_count = Graphics.frame_count + set_day + set_hour + set_min

   when 2 # this one does exactly the opposite...

     Graphics.frame_count = Graphics.frame_count - set_day - set_hour - set_min

   end

 end

end
 

Yin

Member

This is great! Thank you second_crimson! You work fast! I'll put your name in the script so I can know who to put in the credits (I noticed you didn't do it). It works perfectly, just as I wanted it.
Thanks again.

Also, does anyone know how I would go about setting events to happen at a certain time with this script?
 
You're most welcome. :)

If you want to set things to happen at a certain time, you'll have to pass the hour, minute, etc. values into some variables.

To do that, just insert this code above Main as a new script.
Code:
#===========================================

# Pass Time into Variables

# a quick fix by Second_Crimson - 3/30/09

#===========================================

class Scene_Map

  alias crimson_update update

  def update

    @total_sec = Graphics.frame_count / Graphics.frame_rate

    $game_variables[1] = (@total_sec / 60 / 24) % 7

    $game_variables[2] = (@total_sec / 60) % 24

    $game_variables[3] = (@total_sec % 60)

    crimson_update

  end

end

Now the day of the week will be in variable 1 (should be 0 for Sunday, 1 for Monday, etc.) Hour will be in variable 2, and minutes will be in variable 3. Hours will still be in 24 hour time, so as to reduce the complexity of handling the variables.

If you're already using 1, 2, and 3 (likely you are), you can change any of them by changing the number in the brackets (i.e., $game_variables 
 

Yin

Member

OK, so I edited the script a little more and it works like it should. But now, when I try to manually tint the screen, it doesn't. What do I do? Here is the modified script.

Code:
 

#==============================================================================

# ** Window_PlayTime + Day & Night Settings Script

#    Window_PlayTime Add-on

#    modified by shadowball

#    further modified for Yin by second_crimson

#    further modified by Yin to use game switches and make time go slower

#

#  On the Menu scene you'll see the current in-game day and time...

#==============================================================================

 

class Window_GameStats < Window_Base

 

 def initialize

   super(0, 0, 160, 96)

   self.contents = Bitmap.new(width - 32, height - 32)

   refresh

 end

 

 def refresh

   self.contents.clear

   @total_sec = Graphics.frame_count / Graphics.frame_rate

   day = @total_sec / 60 / 24 % 7 # @total_sec / 60 / 24 % 7

   hour = @total_sec / 60 % 24 #@total_sec / 60 % 24

   minute = @total_sec % 60 / 5 #@total_sec % 60

   if hour >= 12

     meridian = " PM"

   else

     meridian = " AM"

   end

   if hour == 0 then hour = 12 end

   if hour > 12 then hour -= 12 end

   text = sprintf("%02d:%02d", hour, minute)

   text = text + meridian

   self.contents.font.color = system_color

   shb_day = 'Sunday'    if day == 0

   shb_day = 'Monday'    if day == 1

   shb_day = 'Tuesday'   if day == 2

   shb_day = 'Wednesday' if day == 3

   shb_day = 'Thursday'  if day == 4

   shb_day = 'Friday'    if day == 5

   shb_day = 'Saturday'  if day == 6

   shb_weekday = shb_day

   self.contents.draw_text(4, -10, 120, 32, shb_weekday, 0)

   self.contents.font.color = normal_color

   self.contents.draw_text(4, 4, 120, 32, text, 2)

   

   case $game_party.gold

   when 0..9999

     gold = $game_party.gold

   when 10000..99999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+","+array[2].to_s+array[3].to_s+array[4].to_s

   when 100000..999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+array[2].to_s+","+array[3].to_s+array[4].to_s+array[5].to_s

   when 1000000..9999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+","+array[1].to_s+array[2].to_s+array[3].to_s+","+array[4].to_s+array[5].to_s+array[6].to_s

   end

#Draw Gold

 self.contents.font.color = system_color

 gold_word = $data_system.words.gold.to_s

 cx = contents.text_size(gold_word).width

 cx2=contents.text_size(gold.to_s).width

 self.contents.draw_text(4, 18, 120-cx-2, 32, gold_word)

 self.contents.font.color = normal_color

 self.contents.draw_text(124-cx2+1,32, cx2, 32, gold.to_s, 2)

 self.contents.font.color = system_color

 end

 

 def update

   super

   if Graphics.frame_count / Graphics.frame_rate != @total_sec

     refresh

   end

 end

end

 

#==============================================================================

#  *  Scene_Map - Modified

#     modified by shadowball

#

#  Screen tone will change depending on the in-game play time automatically

#==============================================================================

class Scene_Map

 alias shb_map_up update

 def update

   @total_sec = Graphics.frame_count / Graphics.frame_rate 

   @shb_hour = @total_sec / 60 % 24

   if @shb_hour < 5 || @shb_hour > 18     # Night 7 p.m. - 5 a.m.

     $game_switches [11] = true

     $game_switches [12] = false

     $game_switches [13] = false

     $game_switches [14] = false

     $game_screen.start_tone_change(Tone.new(-120, -120, -120, 0), 80)

     $game_map.need_refresh = true

   elsif @shb_hour > 4 && @shb_hour < 7   # Early 5 a.m. - 7 a.m.

     $game_switches [12] = true

     $game_switches [11] = false

     $game_switches [13] = false

     $game_switches [14] = false

     $game_screen.start_tone_change(Tone.new(-40, -40, 0, 0), 80)

     $game_map.need_refresh = true

   elsif @shb_hour > 6 && @shb_hour < 16  # Morning - Afternoon 7 a.m. - 4 p.m.

     $game_switches [13] = true

     $game_switches [12] = false

     $game_switches [11] = false

     $game_switches [14] = false

     $game_screen.start_tone_change(Tone.new(0, 0, 0, 0), 80)

     $game_map.need_refresh = true

   elsif @shb_hour > 15 && @shb_hour < 19 # Late 4 p.m. - 7 p.m.

     $game_switches [14] = true

     $game_switches [12] = false

     $game_switches [13] = false

     $game_switches [11] = false

     $game_screen.start_tone_change(Tone.new(30, 10, 0, 0), 80)

     $game_map.need_refresh = true

   end

   shb_map_up

 end

end

 

#=======================================================

#  *  Game_System Add-on v 1.0

#     by shadowball

#     08.02.2008

#

#  You can set the time in minutes, hours, days

#  Syntax:  $game_system.set_time(0, 30, 2, 3)

#=======================================================

class Game_System

 def set_time(alter = 0, minute = 0, hour = 0, day = 0)

   if minute >= 0

     if minute >= 60

       minute = 59

     end

     set_min = Graphics.frame_rate * minute

   end

   if hour >= 0

     if hour >= 24

       hour = 23

     end

     set_hour = Graphics.frame_rate * 60 * hour

   end

   if day >= 0

     if day >= 31

       day = 30

     end

     set_day = Graphics.frame_rate * 60 * 24 * day

   end

   

   case alter

   when 0 # sets the time

     Graphics.frame_count = 0 + set_day + set_hour + set_min

   when 1 # adds the hours, minutes you specified to the current in-game playtime

     Graphics.frame_count = Graphics.frame_count + set_day + set_hour + set_min

   when 2 # this one does exactly the opposite...

     Graphics.frame_count = Graphics.frame_count - set_day - set_hour - set_min

   end

 end

end

 
 
The reason it does that is because the script writes the tints into the map code, meaning it will always retint to the appropriate tint for the appropriate time of day. If you like I can fix it so that this can be turned off. Would you like to be able to turn it off via game switch or via script call?
 
Alrighty. This modification is done:
Code:
 

#==============================================================================

# ** Window_PlayTime + Day & Night Settings Script

#    Window_PlayTime Add-on

#    modified by shadowball

#    further modified for Yin by second_crimson

#    further modified by Yin to use game switches and make time go slower

#

#  On the Menu scene you'll see the current in-game day and time...

#==============================================================================

 

class Window_GameStats < Window_Base

 

 def initialize

   super(0, 0, 160, 96)

   self.contents = Bitmap.new(width - 32, height - 32)

   refresh

 end

 

 def refresh

   self.contents.clear

   @total_sec = Graphics.frame_count / Graphics.frame_rate

   day = @total_sec / 60 / 24 % 7 # @total_sec / 60 / 24 % 7

   hour = @total_sec / 60 % 24 #@total_sec / 60 % 24

   minute = @total_sec % 60 / 5 #@total_sec % 60

   if hour >= 12

     meridian = " PM"

   else

     meridian = " AM"

   end

   if hour == 0 then hour = 12 end

   if hour > 12 then hour -= 12 end

   text = sprintf("%02d:%02d", hour, minute)

   text = text + meridian

   self.contents.font.color = system_color

   shb_day = 'Sunday'    if day == 0

   shb_day = 'Monday'    if day == 1

   shb_day = 'Tuesday'   if day == 2

   shb_day = 'Wednesday' if day == 3

   shb_day = 'Thursday'  if day == 4

   shb_day = 'Friday'    if day == 5

   shb_day = 'Saturday'  if day == 6

   shb_weekday = shb_day

   self.contents.draw_text(4, -10, 120, 32, shb_weekday, 0)

   self.contents.font.color = normal_color

   self.contents.draw_text(4, 4, 120, 32, text, 2)

   

   case $game_party.gold

   when 0..9999

     gold = $game_party.gold

   when 10000..99999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+","+array[2].to_s+array[3].to_s+array[4].to_s

   when 100000..999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+array[2].to_s+","+array[3].to_s+array[4].to_s+array[5].to_s

   when 1000000..9999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+","+array[1].to_s+array[2].to_s+array[3].to_s+","+array[4].to_s+array[5].to_s+array[6].to_s

   end

#Draw Gold

 self.contents.font.color = system_color

 gold_word = $data_system.words.gold.to_s

 cx = contents.text_size(gold_word).width

 cx2=contents.text_size(gold.to_s).width

 self.contents.draw_text(4, 18, 120-cx-2, 32, gold_word)

 self.contents.font.color = normal_color

 self.contents.draw_text(124-cx2+1,32, cx2, 32, gold.to_s, 2)

 self.contents.font.color = system_color

 end

 

 def update

   super

   if Graphics.frame_count / Graphics.frame_rate != @total_sec

     refresh

   end

 end

end

 

#==============================================================================

#  *  Scene_Map - Modified

#     modified by shadowball

#

#  Screen tone will change depending on the in-game play time automatically

#==============================================================================

class Scene_Map

 alias shb_map_up update

 def update

   @total_sec = Graphics.frame_count / Graphics.frame_rate 

   @shb_hour = @total_sec / 60 % 24

   if @shb_hour < 5 || @shb_hour > 18     # Night 7 p.m. - 5 a.m.

     $game_switches [11] = true

     $game_switches [12] = false

     $game_switches [13] = false

     $game_switches [14] = false

     if $game_switches[15] == false

       $game_screen.start_tone_change(Tone.new(-120, -120, -120, 0), 80)

     end

     $game_map.need_refresh = true

   elsif @shb_hour > 4 && @shb_hour < 7   # Early 5 a.m. - 7 a.m.

     $game_switches [12] = true

     $game_switches [11] = false

     $game_switches [13] = false

     $game_switches [14] = false

     if $game_switches[15] == false

       $game_screen.start_tone_change(Tone.new(-40, -40, 0, 0), 80)

     end

     $game_map.need_refresh = true

   elsif @shb_hour > 6 && @shb_hour < 16  # Morning - Afternoon 7 a.m. - 4 p.m.

     $game_switches [13] = true

     $game_switches [12] = false

     $game_switches [11] = false

     $game_switches [14] = false

     if $game_switches[15] == false

       $game_screen.start_tone_change(Tone.new(0, 0, 0, 0), 80)

     end

     $game_map.need_refresh = true

   elsif @shb_hour > 15 && @shb_hour < 19 # Late 4 p.m. - 7 p.m.

     $game_switches [14] = true

     $game_switches [12] = false

     $game_switches [13] = false

     $game_switches [11] = false

     if $game_switches[15] == false

       $game_screen.start_tone_change(Tone.new(30, 10, 0, 0), 80)

     end

     $game_map.need_refresh = true

   end

   shb_map_up

 end

end

 

#=======================================================

#  *  Game_System Add-on v 1.0

#     by shadowball

#     08.02.2008

#

#  You can set the time in minutes, hours, days

#  Syntax:  $game_system.set_time(0, 30, 2, 3)

#=======================================================

class Game_System

 def set_time(alter = 0, minute = 0, hour = 0, day = 0)

   if minute >= 0

     if minute >= 60

       minute = 59

     end

     set_min = Graphics.frame_rate * minute

   end

   if hour >= 0

     if hour >= 24

       hour = 23

     end

     set_hour = Graphics.frame_rate * 60 * hour

   end

   if day >= 0

     if day >= 31

       day = 30

     end

     set_day = Graphics.frame_rate * 60 * 24 * day

   end

   

   case alter

   when 0 # sets the time

     Graphics.frame_count = 0 + set_day + set_hour + set_min

   when 1 # adds the hours, minutes you specified to the current in-game playtime

     Graphics.frame_count = Graphics.frame_count + set_day + set_hour + set_min

   when 2 # this one does exactly the opposite...

     Graphics.frame_count = Graphics.frame_count - set_day - set_hour - set_min

   end

 end

end

Now by turning game switch 15 on, you prevent the automatic changing of the screen tint. Know that if the screen tint is dark and you turn switch 15 on, you still will have to change the screen tint manually to whatever you want it.
 

Yin

Member

Thank you so much! I'm learning so much just from seeing the modifications (I made some modifications too, by looking at what you did.) Also, it works flawlessly. Thanks again!
 

Yin

Member

Code:
 

#==============================================================================

# ** Window_PlayTime + Day & Night Settings Script

#    Window_PlayTime Add-on

#    modified by shadowball

#    further modified for Yin by second_crimson to include AM PM and a tint screen stopper through #                                                                                                        game switch

#    further modified by Yin to use game switches for indoors and to mark periods of the day and #                                                                                                     make time go slower

#

#  On the Menu scene you'll see the current in-game day and time...

#==============================================================================

 

class Window_GameStats < Window_Base

 

 def initialize

   super(0, 0, 160, 96)

   self.contents = Bitmap.new(width - 32, height - 32)

   refresh

 end

 

 def refresh

   self.contents.clear

   @total_sec = Graphics.frame_count / Graphics.frame_rate

   day = @total_sec / 60 / 24 % 7 # @total_sec / 60 / 24 % 7

   hour = @total_sec / 60 % 24 #@total_sec / 60 % 24

   minute = @total_sec % 60 / 3 #@total_sec % 60

   if hour >= 12

     meridian = " PM"

   else

     meridian = " AM"

   end

   if hour == 0 then hour = 12 end

   if hour > 12 then hour -= 12 end

   text = sprintf("%02d:%02d", hour, minute)

   text = text + meridian

   self.contents.font.color = system_color

   shb_day = 'Sunday'    if day == 0

   shb_day = 'Monday'    if day == 1

   shb_day = 'Tuesday'   if day == 2

   shb_day = 'Wednesday' if day == 3

   shb_day = 'Thursday'  if day == 4

   shb_day = 'Friday'    if day == 5

   shb_day = 'Saturday'  if day == 6

   shb_weekday = shb_day

   self.contents.draw_text(4, -10, 120, 32, shb_weekday, 0)

   self.contents.font.color = normal_color

   self.contents.draw_text(4, 4, 120, 32, text, 2)

   

   case $game_party.gold

   when 0..9999

     gold = $game_party.gold

   when 10000..99999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+","+array[2].to_s+array[3].to_s+array[4].to_s

   when 100000..999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+array[1].to_s+array[2].to_s+","+array[3].to_s+array[4].to_s+array[5].to_s

   when 1000000..9999999

     gold = $game_party.gold.to_s

     array = gold.split(//)

     gold = array[0].to_s+","+array[1].to_s+array[2].to_s+array[3].to_s+","+array[4].to_s+array[5].to_s+array[6].to_s

   end

#Draw Gold

 self.contents.font.color = system_color

 gold_word = $data_system.words.gold.to_s

 cx = contents.text_size(gold_word).width

 cx2=contents.text_size(gold.to_s).width

 self.contents.draw_text(4, 18, 120-cx-2, 32, gold_word)

 self.contents.font.color = normal_color

 self.contents.draw_text(124-cx2+1,32, cx2, 32, gold.to_s, 2)

 self.contents.font.color = system_color

 end

 

 def update

   super

   if Graphics.frame_count / Graphics.frame_rate != @total_sec

     refresh

   end

 end

end

 

#==============================================================================

#  *  Scene_Map - Modified

#     modified by shadowball

#

#  Screen tone will change depending on the in-game play time automatically

#==============================================================================

class Scene_Map

 alias shb_map_up update

 def update

   @total_sec = Graphics.frame_count / Graphics.frame_rate 

   @shb_hour = @total_sec / 60 % 24

   if @shb_hour < 5 || @shb_hour > 18     # Night 7 p.m. - 5 a.m.

     $game_switches [11] = true

     $game_switches [12] = false

     $game_switches [13] = false

     $game_switches [14] = false

     if $game_switches[16] == false #If false, screen tints If true, screen does not. Control with game switches

     $game_screen.start_tone_change(Tone.new(-180, -150, -100, 0), 80)

   end

     $game_map.need_refresh = true

     

   elsif @shb_hour > 4 && @shb_hour < 7   # Early 5 a.m. - 7 a.m.

     $game_switches [12] = true

     $game_switches [11] = false

     $game_switches [13] = false

     $game_switches [14] = false

     if $game_switches[16] == false #If false, screen tints If true, screen does not. Control with game switches

     $game_screen.start_tone_change(Tone.new(-55, -100, -51, 68), 80)

   end

     $game_map.need_refresh = true

     

   elsif @shb_hour > 6 && @shb_hour < 16  # Morning - Afternoon 7 a.m. - 4 p.m.

     $game_switches [13] = true

     $game_switches [12] = false

     $game_switches [11] = false

     $game_switches [14] = false

     if $game_switches[16] == false #If false, screen tints If true, screen does not. Control with game switches

     $game_screen.start_tone_change(Tone.new(0, 0, 0, 0), 80)

   end

   

     $game_map.need_refresh = true

   

   elsif @shb_hour > 15 && @shb_hour < 19 # Late 4 p.m. - 7 p.m.

     $game_switches [14] = true

     $game_switches [12] = false

     $game_switches [13] = false

     $game_switches [11] = false

     if $game_switches[16] == false #If false, screen tints If true, screen does not. Control with game switches

     $game_screen.start_tone_change(Tone.new(0, -51, -85, 0), 80)

   end

     $game_map.need_refresh = true

 end

 

   if $game_switches [15] == true #If true, then you are inside and the tinting will be set to 0 0 0 0 (Which is normal) even at night.

     #If you want to modify the tinting for inside manually through the events, set this switch to off and set switch 16 to true

     $game_screen.start_tone_change(Tone.new(0, 0, 0, 0), 5)

   end

   shb_map_up

 end

end

#=======================================================

#  *  Game_System Add-on v 1.0

#     by shadowball

#     08.02.2008

#

#  You can set the time in minutes, hours, days

#  Syntax:  $game_system.set_time(0, 30, 2, 3)

#=======================================================

class Game_System

 def set_time(alter = 0, minute = 0, hour = 0, day = 0)

   if minute >= 0

     if minute >= 60

       minute = 59

     end

     set_min = Graphics.frame_rate * minute

   end

   if hour >= 0

     if hour >= 24

       hour = 23

     end

     set_hour = Graphics.frame_rate * 60 * hour

   end

   if day >= 0

     if day >= 31

       day = 30

     end

     set_day = Graphics.frame_rate * 60 * 24 * day

   end

   

   case alter

   when 0 # sets the time

     Graphics.frame_count = 0 + set_day + set_hour + set_min

   when 1 # adds the hours, minutes you specified to the current in-game playtime

     Graphics.frame_count = Graphics.frame_count + set_day + set_hour + set_min

   when 2 # this one does exactly the opposite...

     Graphics.frame_count = Graphics.frame_count - set_day - set_hour - set_min

   end

 end

end

 


This is the most updated version. Maybe not much changes. I'm trying to learn how to make the refresh fade the new events in because right now, they just instantly appear. Also, I'm trying to make it so that another switch makes time stop.
So far my attempts at stopped time have been filled with errors. I just keep deleting it and starting over :haha:

EDIT: The changes you make are so simple, but to me I think I'm thinking too hard on how to do things. I understand it when I see it, but I can't think of it myself. I guess I'm weird.
 
I modified the add-on script, too...

Code:
#=======================================================

#  *  Game_System Add-on v 1.1

#     by Kyonides alias shadowball, kyonides-arkanthos

#     08.02.2008 - 04.04.2009

#

#  You can set the time in minutes, hours, days, months

#

#  Syntax:

#    $game_system.set_time(0, 30, 2, 3)

#    $game_system.set_min(-30) - Substracts 30 minutes

#    $game_system.set_day(5) - Adds 5 days

#=======================================================

class Game_System

  attr_accessor :timeout  # Pauses / Enables Frame Count

  attr_accessor :playtime # Store the Graphics.frame_count current value

 

  alias kyon_gs_init initialize

  def initialize

    @timeout, @playtime = false, 0

    kyon_gs_init

  end

 

  def set_time(alter = 0, minute = 0, hour = 0, day = 0, month = 0)

    minute = 59 if minute < 0 or minute >= 60

    hour   = 23 if hour < 0 or hour >= 24

    day    = 30 if day < 0 or day > 30

    month  = 11 if month < 0 or month > 11

    set_min   = Graphics.frame_rate * minute if minute >= 0

    set_hour  = Graphics.frame_rate * 60 * hour if hour >= 0

    set_day   = Graphics.frame_rate * 60 * 24 * day if day >= 0

    set_month = Graphics.frame_rate * 60 * 24 * 30 * month if month >= 0

    case alter

    when 0 # sets the time

      Graphics.frame_count = set_day + set_hour + set_min + set_month

    when 1 # adds the hours, minutes you specified to the current in-game playtime

      Graphics.frame_count += set_day + set_hour + set_min + set_month

    when 2 # this one does exactly the opposite...

      Graphics.frame_count -= set_day + set_hour + set_min + set_month

    end

  end

 

  def set_min(value)

    unless $game_system.timeout

      minute = value if value > -60 and value < 60

      Graphics.frame_count += Graphics.frame_rate * 60 * minute

    end

  end

 

  def set_hour(value)

    unless $game_system.timeout

      hour = value if value > -24 and value < 24

      Graphics.frame_count += Graphics.frame_rate * 60 * 60 * hour

    end

  end

 

  def set_day(value)

    unless $game_system.timeout

      day = value

      Graphics.frame_count += Graphics.frame_rate * 60 * 60 * 24 * day

    end

  end

  

  def set_month(value)

    unless $game_system.timeout

      month = value

      Graphics.frame_count += Graphics.frame_rate * 60 * 60 * 24 * 30 * month

    end

  end

 

  def stop_time

    $game_system.timeout = true

    @playtime = Graphics.frame_count

    $game_variables[1] = @playtime if $DEBUG

  end

 

  def time

    Graphics.frame_count = @playtime

    $game_system.timeout = false

    $game_variables[2] = Graphics.frame_count if $DEBUG

  end

end

 

class Window_PlayTime < Window_Base

  def refresh

    self.contents.clear

    self.contents.font.color = system_color

    self.contents.draw_text(4, 0, 120, 32, "Play Time")

    frame_count = Graphics.frame_count  if !$game_system.timeout

    frame_count = $game_system.playtime if $game_system.timeout

    @total_sec = frame_count / Graphics.frame_rate

    hour = @total_sec / 60 / 60

    min = @total_sec / 60 % 60

    sec = @total_sec % 60

    text = sprintf("%02d:%02d:%02d", hour, min, sec)

    self.contents.font.color = normal_color

    self.contents.draw_text(4, 32, 120, 32, text, 2)

  end

end

 

class Scene_Save < Scene_File

  alias kyon_ss_wsd write_save_data

  def write_save_data(file)

    Graphics.frame_count = $game_system.playtime if $game_system.timeout

    kyon_ss_wsd(file)

  end

end

The set_time method now just looks a bit better. I added the @timeout public instance variable and let the user choose between the original set_time method or any of the other 3 simple methods to set gameplay time correctly.

With this new version of the Game_System add-on script now you should be able to "stop time" ingame.

In any Window script, namely Window_PlayTime or Window_GameStats or anything else, you may need to modify some methods like I did in Window_PlayTime (see just below Game_System add-on script).

Now time should have stopped for good... (Actually it didn't, it just makes the player think gameplay time has stopped just because it's not refresh anymore.)

Of course, you may think now that it won't work if you reenable the game playtime. We'll need to do something to make it remember the specific time when playtime has stopped.

Edit...

I forgot to post a new public instance variable and the last 2 simple add-on methods for the Game_System class.

I edited the script above once again.
 
Well, I already did that, it was quite simple.
You should call Game_System this way to make it work

$game_system.stop_time
$game_system.timeout = true

Now even if Graphics.frame_count is always running (btw this is a must), people won't notice it because the respective ingame playtime window doesn't refresh the time data.

Once you think you should reenable the time flow, call the script like this

$game_system.time

And it'll reset the current Graphics.frame_count count to the previous count before we "stop time".

Edit...

Now you can copy the new version of Game_System add-on script, I already provided the things (2 public instance variables and 2 extra methods) I left out before.

Edit...

I just modified the script once again to change both variables attributes from attr_reader to attr_accessor. I also changed the set_min, set_hour and set_day methods so they won't add / substract any minutes, hours, days to the playtime if $game_system.timeout is set to true.

I can't say for sure if it won't lag for brief periods of time, but it definitely works... except for the moment when you save your game... (Window_SaveFile still shows the actual playtime.)

Edit...

Now after I modified Scene_Save's write_save_data method Window_SaveFile will let us know that time actually stopped (if $game_system.timeout flag is set to true).
 

Yin

Member

Ok, great I got it. It's pretty late... Or early, I should say (4:43AM) So, I'll check it tomorrow/today. (It's still yesterday to me if I haven't slept. :grin:
 
Well, after several edits (maybe too many of them) the Game_System add-on script is stable and I even modified Scene_Save to make sure it'd save the time when "it stopped". If you save it and load the saved game later, the script will work flawlessly AFAIK.
 

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