Advertisement
ICF-Soft

ICF-Soft Time Utility for RPG Maker

Sep 26th, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.67 KB | None | 0 0
  1. #===============================================================================
  2. # ICF-Soft Time Utility Version 1.0
  3. # For XP to Ace versions.
  4. #-------------------------------------------------------------------------------
  5. # It uses game variables to store and count time.
  6. # Time is stored as minutes.
  7. # Also stores date on variables and update when map changes.
  8. #-------------------------------------------------------------------------------
  9. # Scripted by ICF-Soft [http://icfsoft.blogspot.com.es/]
  10. # Commercial use avaiable.
  11. # Credit to ICF-Soft.
  12. #===============================================================================
  13. # This header must be included with script, in english or spanish.
  14. #===============================================================================
  15. # Usage:
  16. # -To store a time into a variable use ICFUTIL::GetTime(varid)
  17. # -To check how much time has passed use ICFUTIL::GetTimeSince(varid,resid)
  18. # -To check how much hours has passed use ICFUTIL::GetHoursSince(varid,resid)
  19. # -To check how much days has passed use ICFUTIL::GetDaysSince(varid,resid)
  20. #
  21. # Params:
  22. # -varid: the variable where store and check the time.
  23. # -resid: the variable where store the result of time passed. If omited returns
  24. #       the value directly (for scripting purposes).
  25. #===============================================================================
  26. module ICFUTIL
  27. #===============================================================================
  28.  
  29.   # Do not touch this
  30.   Scripts = {} unless defined? (Scripts)
  31.   Scripts["time"] = 1.0
  32.  
  33.   # Configuration
  34.  
  35.   # Aditional variables where store full date. Usefull for map events.
  36.   # Format is [Year,Month,Day,Hour,Minute,Weekday,Month-Day].
  37.   # To skip a param put 0.
  38.  
  39.   DateVars = [6,0,0,3,2,4,5]
  40.  
  41.   # Weekday starts with sunday as 0, monday as 1 ... and saturday as 6
  42.   # Month-Day is a special format because events can use only one variable
  43.   #  per page. So it needs a combined one. Is Month*100 + Day
  44.   # Some Month-Day Examples:
  45.   #  -  101: January 1st
  46.   #  -  102: January 2nd
  47.   #  -  201: February 1st
  48.   #  -  211: February 11th
  49.   #  - 1001: October 1st
  50.   #  - 1010: October 10th
  51.  
  52. #-------------------------------------------------------------------------------
  53.   def self.GetTime(varid)
  54.     $game_variables[varid] = Time.now.to_i / 60
  55.   end
  56.  
  57.   def self.GetTimeSince(varid, resid=0)
  58.     return Time.now.to_i / 60 - $game_variables[varid] if resid == 0
  59.     $game_variables[resid] = Time.now.to_i / 60 - $game_variables[varid]
  60.   end
  61.  
  62.   def self.GetHoursSince(varid, resid=0)
  63.     return GetTimeSince(varid)/60 if resid == 0
  64.     $game_variables[resid] = (Time.now.to_i / 60 - $game_variables[varid])/60
  65.   end
  66.  
  67.   def self.GetDaysSince(varid, resid=0)
  68.     return GetTimeSince(varid)/1440 if resid == 0
  69.     $game_variables[resid] = (Time.now.to_i / 60 - $game_variables[varid])/1440
  70.   end
  71.  
  72.   def self.GetDate
  73.     $game_variables[DateVars[4]] = Time.now.min if DateVars[4] > 0
  74.     $game_variables[DateVars[3]] = Time.now.hour if DateVars[3] > 0
  75.     $game_variables[DateVars[2]] = Time.now.day if DateVars[2] > 0
  76.     $game_variables[DateVars[1]] = Time.now.month if DateVars[1] > 0
  77.     $game_variables[DateVars[0]] = Time.now.year if DateVars[0] > 0
  78.     $game_variables[DateVars[5]] = Time.now.wday if DateVars[5] > 0
  79.     $game_variables[DateVars[6]] = (Time.now.month*100 + Time.now.day) if DateVars[6] > 0
  80.   end
  81.  
  82. end
  83. #===============================================================================
  84. #===============================================================================
  85. class Game_Map
  86.   alias pre_time_setup setup
  87.   def setup(map_id)
  88.     pre_time_setup(map_id)
  89.     ICFUTIL::GetDate()
  90.   end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement