Guest User

RGSS3 Day/Night Cycle

a guest
Nov 2nd, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | None | 0 0
  1. #Basic Game Time + Night/Day v1.6.2
  2. #----------#
  3. #Features: Provides a series of functions to set and recall current game time
  4. # as well customizable tints based on current game time to give the
  5. # appearance of night and day.
  6. #
  7. #Usage: Script calls:
  8. # GameTime::minute? - returns the current minute
  9. # GameTime::hour? - returns the current hour
  10. # GameTime::set(time) - sets the game time to time, in frames (max:1440)
  11. # GameTime::change(time) - increments the game time! (can be negative)
  12. # GameTime::pause_time(set) - stops time for events and stuff, true or false
  13. # GameTime::pause_tint(set) - time runs, but tints do not update
  14. # GameTime::clock(set) - sets whether clock is visible or not
  15. #
  16. #Customization: Set below, in comments.
  17. #
  18. #Examples: GameTime::set(360)
  19. #
  20. #----------#
  21. #-- Script by: V.M of D.T
  22. #
  23. #- Questions or comments can be:
  24. # given by email: [email protected]
  25. # provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  26. # All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  27. #
  28. #--- Free to use in any project, commercial or non-commercial, with credit given
  29. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  30.  
  31. #---Game Clock---#
  32. #USE_CLOCK to true to display game time clock
  33. #CLOCK_POSITION for position of clock
  34. # 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
  35. #CLOCK_TOGGLE is any input button available, see the INPUT help file for options
  36. #------#
  37. USE_CLOCK = false
  38. CLOCK_POSITION = 2
  39. CLOCK_TOGGLE = :SHIFT
  40.  
  41. module GameTime
  42. #---Game Time Details---#
  43. #Number of frames in a game minute, 60 frames = 1 second
  44. TIME_COUNT = 60
  45. #Sets whether to tint screen based on game time
  46. USE_TINT = true
  47.  
  48. #Switch to denote day or night time
  49. USE_SWITCH = false
  50. NIGHT_DAY_SWITCH = 1
  51. DAY_TIME_START = 6
  52. NIGHT_TIME_START = 18
  53.  
  54. #True to pause time while not in map or while during a message
  55. PAUSE_IN_COMBAT = false
  56. PAUSE_NOT_IN_MAP = true
  57. PAUSE_IN_MESSAGE = true
  58.  
  59. #Sets time frames of tints by minute count, one day is 1440 seconds
  60. # 0 = 12am, 360 = 6am, 720 = 12pm, 1080 = 6pm etc...
  61. PRESUNRISE_TIME = 240
  62. SUNRISE_TIME = 360
  63. NOONSTART_TIME = 660
  64. NOONEND_TIME = 900
  65. PRESUNSET_TIME = 1080
  66. SUNSET_TIME = 1260
  67. MIDNIGHT_TIME = 60 #Must be greater than 0
  68.  
  69. #Sets custome tints
  70. PRESUNRISE_TONE = Tone.new(-75,-75,0,50)
  71. SUNRISE_TONE = Tone.new(0,0,0,0)
  72. NOONSTART_TONE = Tone.new(45,45,0,-25)
  73. NOONEND_TONE = Tone.new(0,0,0,0)
  74. PRESUNSET_TONE = Tone.new(-50,-50,0,25)
  75. SUNSET_TONE = Tone.new(-75,-100,0,75)
  76. MIDNIGHT_TONE = Tone.new(-125,-125,0,125)
  77.  
  78. #Include the ids of any maps not to be tinted based on time
  79. # Usually reserved for indoor maps
  80. NOTINTMAPS = [2,3,4,14,15,16,17,18,19,20,21]
  81.  
  82. #Store current time in a variable?
  83. USE_VARIABLE = false
  84. TIME_VARIABLE = 1
  85.  
  86. #---END---#
  87.  
  88. def self.init
  89. $game_time = 0
  90. $game_time_pause_time = false
  91. $game_time_pause_tint = false
  92. end
  93. def self.update
  94. if $game_time_pause_time then return else end
  95. case SceneManager::scene_is?(Scene_Map)
  96. when true
  97. if $game_message.visible == true && PAUSE_IN_MESSAGE then else
  98. $game_time += 1 if Graphics.frame_count % TIME_COUNT == 0 end
  99. when false
  100.  
  101. if !PAUSE_NOT_IN_MAP and !SceneManager::scene_is?(Scene_Battle)
  102. $game_time += 1 if Graphics.frame_count % TIME_COUNT == 0 end
  103. if SceneManager::scene_is?(Scene_Battle) && PAUSE_IN_COMBAT != true
  104. $game_time += 1 if Graphics.frame_count % TIME_COUNT == 0 end
  105. end
  106. if $game_time == 1440 then $game_time = 0 end
  107. $game_variables[TIME_VARIABLE] = $game_time if USE_VARIABLE
  108. update_night_switch if USE_SWITCH
  109. GameTime::tint if $game_time_pause_tint != true
  110. end
  111. def self.update_night_switch
  112. if hour? > DAY_TIME_START and hour? < NIGHT_TIME_START
  113. $game_switches[NIGHT_DAY_SWITCH] = true unless $game_switches[NIGHT_DAY_SWITCH] == true
  114. else
  115. $game_switches[NIGHT_DAY_SWITCH] = false unless $game_switches[NIGHT_DAY_SWITCH] == false
  116. end
  117. end
  118. def self.hour?
  119. return $game_time / 60
  120. end
  121. def self.minute?
  122. return $game_time % 60
  123. end
  124. def self.time?
  125. meri = "AM"
  126. hour = GameTime::hour?
  127. minute = GameTime::minute?
  128. if hour > 11 then meri = "PM" end
  129. if hour == 0 then hour = 12; meri = "AM" end
  130. if hour > 12 then hour -= 12 end
  131. if hour < 10 then hour = " " + hour.to_s else hour.to_s end
  132. if minute < 10 then minute = "0" + minute.to_s else minute.to_s end
  133. return hour.to_s + ":" + minute.to_s + " " + meri
  134. end
  135. def self.set(number)
  136. $game_time = number if number < 1440
  137. GameTime::tint(0) if $game_time_pause_tint != true
  138. end
  139. def self.change(number)
  140. $game_time += number
  141. $game_time -= 1440 if $game_time > 1440
  142. $game_time += 1440 if $game_time < 0
  143. GameTime::tint(0) if $game_time_pause_tint != true
  144. end
  145. def self.tint(tint = 60)
  146. if USE_TINT != true then return end
  147. for i in NOTINTMAPS
  148. if $game_map.map_id == i
  149. $game_map.screen.start_tone_change(Tone.new(0,0,0,0),0)
  150. return
  151. end
  152. end
  153. if SceneManager::scene_is?(Scene_Map) then else return end
  154. case $game_time
  155. when PRESUNRISE_TIME .. SUNRISE_TIME
  156. $game_map.screen.start_tone_change(PRESUNRISE_TONE, tint)
  157. when SUNRISE_TIME .. NOONSTART_TIME
  158. $game_map.screen.start_tone_change(SUNRISE_TONE, tint)
  159. when NOONSTART_TIME .. NOONEND_TIME
  160. $game_map.screen.start_tone_change(NOONSTART_TONE, tint)
  161. when NOONEND_TIME .. PRESUNSET_TIME
  162. $game_map.screen.start_tone_change(NOONEND_TONE, tint)
  163. when PRESUNSET_TIME .. SUNSET_TIME
  164. $game_map.screen.start_tone_change(PRESUNSET_TONE, tint)
  165. when SUNSET_TIME .. 1440
  166. $game_map.screen.start_tone_change(SUNSET_TONE, tint)
  167. when 0 .. MIDNIGHT_TIME
  168. $game_map.screen.start_tone_change(SUNSET_TONE, tint)
  169. when MIDNIGHT_TIME .. PRESUNRISE_TIME
  170. $game_map.screen.start_tone_change(MIDNIGHT_TONE, tint)
  171. end
  172. end
  173. def self.pause_time(set)
  174. $game_time_pause_time = set
  175. end
  176. def self.pause_tint(set)
  177. $game_time_pause_tint = set
  178. end
  179. def self.clock(set)
  180. return unless SceneManager.scene.is_a?(Scene_Map)
  181. SceneManager.scene.clock_visible?(set)
  182. end
  183.  
  184. class Window_Clock < Window_Base
  185. def initialize
  186. case CLOCK_POSITION
  187. when 1
  188. super(0,0,115,56)
  189. when 2
  190. super(429,0,115,56)
  191. when 3
  192. super(0,360,115,56)
  193. when 4
  194. super(429,360,115,56)
  195. end
  196. self.visible = $game_time_clock_visibility unless $game_time_clock_visibility.nil?
  197. end
  198. def update
  199. self.contents.clear
  200. self.contents.draw_text(0,0,100,24,GameTime::time?)
  201. $game_time_clock_visibility = self.visible
  202. end
  203. end
  204.  
  205. end
  206.  
  207. GameTime::init
  208.  
  209. module DataManager
  210. class << self
  211. alias gametime_msc make_save_contents
  212. alias gametime_esc extract_save_contents
  213. end
  214. def self.make_save_contents
  215. contents = gametime_msc
  216. contents[:gametime] = $game_time
  217. contents
  218. end
  219. def self.extract_save_contents(contents)
  220. gametime_esc(contents)
  221. $game_time = contents[:gametime]
  222. end
  223. end
  224.  
  225.  
  226. class Scene_Map < Scene_Base
  227. alias gametime_post_transfer post_transfer
  228. alias gametime_create_all_windows create_all_windows
  229. alias gametime_update_map update
  230. def post_transfer
  231. GameTime::tint(0) if $game_time_pause_tint != true
  232. gametime_post_transfer
  233. end
  234. def create_all_windows
  235. gametime_create_all_windows
  236. @gametimeclock = GameTime::Window_Clock.new if USE_CLOCK
  237. end
  238. def update
  239. gametime_update_map
  240. @gametimeclock.update if @gametimeclock.nil? == false
  241. if Input.trigger?(CLOCK_TOGGLE) and @gametimeclock.nil? == false
  242. @gametimeclock.visible ? @gametimeclock.visible = false : @gametimeclock.visible = true
  243. end
  244. end
  245. def clock_visible?(set)
  246. @gametimeclock.visible = set
  247. end
  248. end
  249.  
  250. class Scene_Base
  251. alias gametime_update update
  252. def update
  253. gametime_update
  254. GameTime::update
  255. end
  256. end
Advertisement
Add Comment
Please, Sign In to add comment