Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. =begin
  2.  
  3.   Script Name:   Day Night System
  4.   Author:        Tajiin
  5.   Release Date:  12/04/2013 | mm/dd/yyyy
  6.  
  7.   Version: 2.0
  8.   Versions Date: 05.26.2015
  9.  
  10.   Description:
  11.     This Script is a Day/Night system. It changes the color tone of the
  12.     screen when a specific time is over.
  13.    
  14.    
  15.   Script-Command:
  16.     $game_system.daynightsystem.set_tone(t)
  17.    
  18.       - With this Command you can change the color tone.
  19.       - t: is the index of the color tone (0-7)
  20.      
  21.  
  22.   What can i change in the EDIT-Area:
  23.     Switch_ID: It's the Id of the switch which can start/stop the script
  24.                (True = Started; False = Stopped)
  25.                When you set it to "0" it wont be used
  26.                
  27.     Tag_Nacht_Time: This is the time from 0 o'clock to 12 o'clock a.m.
  28.                     (in minutes)
  29.    
  30.     Change_Time: This is the time the screen needs to change his color tone
  31.                  (in Sekunden)
  32.  
  33.     Farbton: Here you can change the single color tones
  34.  
  35.     Time_Variable_ID1: In this variable the time will be saved (in frames)
  36.                        When you set it to "0" it wont be used
  37.                      
  38.     Time_Variable_ID2: In this variable the time will be saved (in hours)
  39.                        When you set it to "0" it wont be used
  40.                        
  41.     Time_Variable_ID3: In this variable the time will be saved (in minutes)
  42.                        When you set it to "0" it wont be used
  43.                        
  44.     DayCount_Variable: In this variable the days will count
  45.                        When you set it to "0" it wont be used
  46.    
  47.   Viel Spaß
  48.  
  49. =end
  50.  
  51. module TagNachtSystem
  52.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  53.   #  EDIT-Area
  54.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  55.  
  56.   Switch_ID = 10
  57.  
  58.   Tag_Nacht_Time = 0.2
  59.  
  60.   Change_Time = 5
  61.  
  62.   Farbton = [
  63.               [-128, -128, -64, 128], #Midnight           Index: 0
  64.               [-34, -34, 0, 68], #Midnight > Morning      Index: 1
  65.               [-16, -64, -64, 32], #Morning               Index: 2
  66.               [0, 0, 0, 0], #Morning > Midday             Index: 3
  67.               [34, 34, 0, 0], #Midday                     Index: 4
  68.               [68, -34, -34, 0], #Midday > Afternoon      Index: 5
  69.               [-68, -68, -68, 0], #Afternoon              Index: 6
  70.               [-68, -68, 0, 68]  #Afternoon > Midnight    Index: 7
  71.             ]
  72.  
  73.   Time_Variable_ID1 = 10
  74.  
  75.   Time_Variable_ID2 = 11
  76.  
  77.   Time_Variable_ID3 = 12
  78.  
  79.   Time_Variable_ID4 = 13
  80.  
  81.   DayCount_Variable = 14
  82.  
  83.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  84.   #  END
  85.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  86. end
  87. #==============================================================================
  88. # ** DataManager
  89. #------------------------------------------------------------------------------
  90. #  This module manages the database and game objects. Almost all of the
  91. # global variables used by the game are initialized by this module.
  92. #==============================================================================
  93. module DataManager
  94.   class << self
  95.     alias taj_datamanager_creategameobjects_uzgv21   create_game_objects
  96.     #--------------------------------------------------------------------------
  97.     # * Create Game Objects
  98.     #--------------------------------------------------------------------------
  99.     def create_game_objects
  100.       taj_datamanager_creategameobjects_uzgv21
  101.       $game_system.daynightsystem    = Day_Night.new
  102.     end
  103.   end
  104. end
  105. #==============================================================================
  106. # ** Game_System
  107. #------------------------------------------------------------------------------
  108. #  This class handles system data. It saves the disable state of saving and
  109. # menus. Instances of this class are referenced by $game_system.
  110. #==============================================================================
  111.  
  112. class Game_System
  113.   #--------------------------------------------------------------------------
  114.   # * Public Instance Variables
  115.   #--------------------------------------------------------------------------
  116.   attr_accessor     :daynightsystem
  117. end
  118. #==============================================================================
  119. # ** Game_Map
  120. #------------------------------------------------------------------------------
  121. #  This class handles maps. It includes scrolling and passage determination
  122. # functions. The instance of this class is referenced by $game_map.
  123. #==============================================================================
  124.  
  125. class Game_Map
  126.   alias taj_gamemap_update_jkbdsf9   update
  127.   #--------------------------------------------------------------------------
  128.   # * Frame Update
  129.   #--------------------------------------------------------------------------
  130.   def update(main = false)
  131.     taj_gamemap_update_jkbdsf9(main)
  132.     $game_system.daynightsystem.update if $game_switches[TagNachtSystem::Switch_ID]
  133.   end
  134. end
  135. class Day_Night
  136.   #--------------------------------------------------------------------------
  137.   # * Object Initialization
  138.   #--------------------------------------------------------------------------
  139.   def initialize
  140.     t = Tone.new(TagNachtSystem::Farbton[0][0],TagNachtSystem::Farbton[0][1],TagNachtSystem::Farbton[0][2],TagNachtSystem::Farbton[0][3])
  141.     $game_map.screen.start_tone_change(t, 0)
  142.     t = nil
  143.     @timer_in_value = 0
  144.     @timer_in_hours = 0
  145.     @timer_in_minutes = 0
  146.     @timer_in_hours_temp = 0
  147.     @daycount = 0
  148.     a = TagNachtSystem::Tag_Nacht_Time*3600
  149.     b = TagNachtSystem::Tag_Nacht_Time*3600*0.25
  150.     c = TagNachtSystem::Tag_Nacht_Time*3600*0.5
  151.     @timersettings = [
  152.                       0, (b - a*0.02).round, c.round, (b + c + a*0.02).round,
  153.                       a.round, (a + b - a*0.02).round, (a + c).round,
  154.                       (a + b + c + a*0.02).round, (a * 2).round
  155.                       ]
  156.     p @timersettings
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # * Frame Update
  160.   #--------------------------------------------------------------------------
  161.   def update
  162.     testfortime()
  163.     @timer_in_value += 1
  164.     set_variables()
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # * Sets the Variables
  168.   #--------------------------------------------------------------------------
  169.   def set_variables()
  170.     $game_variables[TagNachtSystem::Time_Variable_ID1] = @timer_in_value if TagNachtSystem::Time_Variable_ID1 != 0
  171.     if TagNachtSystem::Time_Variable_ID2 != 0
  172.       max = (TagNachtSystem::Tag_Nacht_Time*3600*2).to_f
  173.       mom = @timer_in_value.to_f
  174.       x = (max/mom).to_f if mom != 0
  175.       @timer_in_hours_temp = 24/x
  176.       @timer_in_hours = (24/x).to_i if x != 0
  177.       $game_variables[TagNachtSystem::Time_Variable_ID2] = "%02d" % @timer_in_hours
  178.       x = 0
  179.     end
  180.     if TagNachtSystem::Time_Variable_ID3 != 0
  181.       h = @timer_in_hours_temp - @timer_in_hours_temp.to_i
  182.       h2 = (@timer_in_hours_temp+1).to_i - @timer_in_hours_temp.to_i
  183.       x = (60*h/h2).to_i
  184.       @timer_in_minutes = x
  185.       $game_variables[TagNachtSystem::Time_Variable_ID3] = "%02d" % @timer_in_minutes
  186.       x = 0
  187.     end
  188.     $game_variables[TagNachtSystem::Time_Variable_ID4] = get_time() if TagNachtSystem::Time_Variable_ID4 != 0
  189.   end
  190.   #--------------------------------------------------------------------------
  191.   # * Test for Time
  192.   #--------------------------------------------------------------------------
  193.   def testfortime()
  194.     case @timer_in_value
  195.       when @timersettings[0] then set_color(0)
  196.       when @timersettings[1] then set_color(1)
  197.       when @timersettings[2] then set_color(2)
  198.       when @timersettings[3] then set_color(3)
  199.       when @timersettings[4] then set_color(4)
  200.       when @timersettings[5] then set_color(5)
  201.       when @timersettings[6] then set_color(6)
  202.       when @timersettings[7] then set_color(7)
  203.     end
  204.     if @timer_in_value == @timersettings[8] #mitternacht
  205.       set_color(0)
  206.       @timer_in_value = 0
  207.       @daycount += 1
  208.       $game_varibales[TagNachtSystem::DayCount_Variable] = @daycount if TagNachtSystem::DayCount_Variable != 0
  209.     end
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # * Set Color
  213.   #--------------------------------------------------------------------------
  214.   def set_color(n)
  215.     t = Tone.new(TagNachtSystem::Farbton[n][0],TagNachtSystem::Farbton[n][1],TagNachtSystem::Farbton[n][2],TagNachtSystem::Farbton[n][3])
  216.     $game_map.screen.start_tone_change(t, TagNachtSystem::Change_Time*60)
  217.   end
  218.   #--------------------------------------------------------------------------
  219.   # * Set Tone
  220.   #--------------------------------------------------------------------------
  221.   def set_tone(t)
  222.     case t
  223.       when 0 then @timer_in_value = @timersettings[0]
  224.       when 1 then @timer_in_value = @timersettings[1]
  225.       when 2 then @timer_in_value = @timersettings[2]
  226.       when 3 then @timer_in_value = @timersettings[3]
  227.       when 4 then @timer_in_value = @timersettings[4]
  228.       when 5 then @timer_in_value = @timersettings[5]
  229.       when 6 then @timer_in_value = @timersettings[6]
  230.       when 7 then @timer_in_value = @timersettings[7]
  231.     end
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # * get Time
  235.   #--------------------------------------------------------------------------
  236.   def get_time()
  237.     @t = false
  238.     @timersettings.each_with_index do |x, i|
  239.       if @timer_in_value >= @timersettings[i]
  240.         @t = true
  241.       else
  242.         return i
  243.       end
  244.     end
  245.   end
  246. end