Advertisement
ICF-Soft

ICF-Soft Time Utility 1.01 RPG Maker MV

Feb 19th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ICF-Soft Plugins - Time Utility
  3. // ICFSoft_TimeUtil.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.ICFSoft_TimeUtil = true;
  8.  
  9. var ICF = ICF || {};
  10. ICF.TimeUtil = ICF.TimeUtil || {};
  11.  
  12. //=============================================================================
  13.  /*:
  14.  * @plugindesc v1.01 This plugin stores date and time in game variables
  15.  * for diverse pourposes.
  16.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  17.  *
  18.  * @param Year Var
  19.  * @desc A variable where store year.
  20.  * @default 0
  21.  *
  22.  * @param Month Var
  23.  * @desc A variable where store month from 1 to 12.
  24.  * @default 0
  25.  *
  26.  * @param Day Var
  27.  * @desc A variable where store day from 1 to 31.
  28.  * @default 0
  29.  *
  30.  * @param Hour Var
  31.  * @desc A variable where store hour.
  32.  * @default 0
  33.  *
  34.  * @param Minute Var
  35.  * @desc A variable where store minute.
  36.  * @default 0
  37.  *
  38.  * @param Week Var
  39.  * @desc A variable where store the day of the week.
  40.  * Week starts with Sunday as 0.
  41.  * @default 0
  42.  *
  43.  * @param Month and day
  44.  * @desc A variable where store a month and day combination.
  45.  * @default 0
  46.  *
  47.  * @param Time travel
  48.  * @desc A variable where store a time offset.
  49.  * @default 0
  50.  *
  51.  * @help
  52.  * ============================================================================
  53.  * Introduction
  54.  * ============================================================================
  55.  *
  56.  * There are games where special things happen on specific day of the week,
  57.  * specific hour, specific day, and so on.
  58.  * There are games where time continues even when off.
  59.  *
  60.  * With this plugin you can do both.
  61.  *
  62.  * Time is stored in game variables and can be used inside events. Automatically
  63.  * updates on map changes, but can also be updated manually.
  64.  *
  65.  * Also you can store time and check how many real time has passed.
  66.  * Time is stored as minutes.
  67.  *
  68.  * ============================================================================
  69.  * Parameters
  70.  * ============================================================================
  71.  *
  72.  * There are six basic params to store current year, day, hour, etc.
  73.  * These params indicate what variables will be used to store that info.
  74.  * To skip a param put 0.
  75.  *
  76.  * Month and day comes in a special format because events can use only one
  77.  * variable per page. So it needs a combined one. Is Month*100 + Day.
  78.  * Some Month-Day Examples:
  79.  *   -  101: January 1st
  80.  *   -  102: January 2nd
  81.  *   -  201: February 1st
  82.  *   -  211: February 11th
  83.  *   - 1001: October 1st
  84.  *   - 1010: October 10th
  85.  *
  86.  * ============================================================================
  87.  * Plugin commands
  88.  * ============================================================================
  89.  *
  90.  * GetTime x
  91.  *
  92.  *  - To store a time into variable number 'x'.
  93.  *
  94.  * GetTimeSince x y
  95.  * GetHoursSince x y
  96.  * GetDaysSince x y
  97.  *
  98.  *  - To compare how much time passed since 'x' in minutes, hours or days
  99.  *    and store result in variable 'y'.
  100.  *
  101.  * UpdateTime
  102.  *
  103.  *  - To update time variables manually.
  104.  *
  105.  * GoPresent [true]
  106.  *  - To reset time. Returning to present.
  107.  *  - Optional: placing 'true' will update map automatically.
  108.  *    
  109.  * AdvanceTime x [true]
  110.  * AdvanceDays x [true]
  111.  * AdvanceYears x [true]
  112.  *  - To advance x minutes, days or years in time (can be negative).
  113.  *  - Optional: placing 'true' will update map automatically.
  114.  *
  115.  * ============================================================================
  116.  * Incompatibilities
  117.  * ============================================================================
  118.  *
  119.  * There's no known incompatible plugins yet.
  120.  *
  121.  * ============================================================================
  122.  * Known isues
  123.  * ============================================================================
  124.  *
  125.  * There's no known isues yet.
  126.  *
  127.  * ============================================================================
  128.  * Changelog
  129.  * ============================================================================
  130.  *
  131.  * Version 1.01:
  132.  * - Added time travel utility.
  133.  *
  134.  * Version 1.00:
  135.  * - Finished plugin!
  136.  *
  137.  * ============================================================================
  138.  *
  139.  * Commercial use avaiable.
  140.  * Credit to ICF-Soft.
  141.  * This entire header must be included with plugin.
  142.  *
  143.  * ============================================================================
  144. */
  145. //=============================================================================
  146.  /*:es
  147.  * @plugindesc v1.01 This plugin stores date and time in game variables
  148.  * for diverse pourposes.
  149.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  150.  *
  151.  * @param Year Var
  152.  * @desc La variable donde almacenas el año.
  153.  * @default 0
  154.  *
  155.  * @param Month Var
  156.  * @desc La variable donde almacenas el mes (de 1 a 12).
  157.  * @default 0
  158.  *
  159.  * @param Day Var
  160.  * @desc La variable donde almacenas el día (de 1 a 31).
  161.  * @default 0
  162.  *
  163.  * @param Hour Var
  164.  * @desc La variable donde almacenas la hora.
  165.  * @default 0
  166.  *
  167.  * @param Minute Var
  168.  * @desc La variable donde almacenas los minutos.
  169.  * @default 0
  170.  *
  171.  * @param Week Var
  172.  * @desc La variable donde almacenas el día de la semana.
  173.  * La semana empieza con el domingo como 0.
  174.  * @default 0
  175.  *
  176.  * @param Month and day
  177.  * @desc Una variable especial donde se almacena una combinación de mes y día.
  178.  * @default 0
  179.  *
  180.  * @param Time travel
  181.  * @desc Una variable en donde almacenar el salto en el tiempo.
  182.  * @default 0
  183.  *
  184.  * @help
  185.  * ============================================================================
  186.  * Introducción
  187.  * ============================================================================
  188.  *
  189.  * Hay juegos en donde ciertos eventos solo pasan en un día, día de la semana,
  190.  * hora o incluso minuto específico.
  191.  * También los hay en los que el tiempo pasa aunque no estés jugando.
  192.  *
  193.  * Con este complemento puedes hacer ambas cosas.
  194.  *
  195.  * El tiempo se almacena en variables a las que se puede acceder en los eventos.
  196.  * Se actualiza en cada cambio de mapa, pero también con comando.
  197.  *
  198.  * Además puedes guardar una fecha y comparar cuanto tiempo real ha pasado.
  199.  * El tiempo se almacena en minutos.
  200.  *
  201.  * ============================================================================
  202.  * Parámetros
  203.  * ============================================================================
  204.  *
  205.  * Hay seis parámetros básicos donde almacenar el año, mes, día, hora, etc.
  206.  * Indican qué variables se van a utilizar para almacenar esa info.
  207.  * Para saltar un parámetro dejar en 0.
  208.  *
  209.  * Month and day comes usa un formato especial porque los eventos solo pueden
  210.  * usar una variable por página. Así que necesita una combinada.
  211.  * Viene en Mes*100 + Día.
  212.  * Algunos ejemplos:
  213.  *   -  101: 1  de Enero
  214.  *   -  102: 2  de Enero
  215.  *   -  201: 1  de Febrero
  216.  *   -  211: 11 de Febrero
  217.  *   - 1001: 1  de Octubre
  218.  *   - 1010: 10 de Octubre
  219.  *
  220.  * ============================================================================
  221.  * Comandos de complemento
  222.  * ============================================================================
  223.  *
  224.  * GetTime x
  225.  *
  226.  *  - Para almacenar el tiempo en la variable número 'x'.
  227.  *
  228.  * GetTimeSince x y
  229.  * GetHoursSince x y
  230.  * GetDaysSince x y
  231.  *
  232.  *  - Para comparar cuanto tiempo ha pasado desde 'x' en minutos, horas or días
  233.  *    y almacenar el resultado en la variable 'y'.
  234.  *
  235.  * UpdateTime
  236.  *
  237.  *  - Para actualizar manualmente las variables.
  238.  *
  239.  * GoPresent [true]
  240.  *  - Para reiniciar el tiempo. Volver al presente.
  241.  *  - Opcional: poniendo 'true' las variables se actualizarán.
  242.  *    
  243.  * AdvanceTime x [true]
  244.  * AdvanceDays x [true]
  245.  * AdvanceYears x [true]
  246.  *  - Para avanzar x minutos, días o años en el tiempo (puede ser negativo).
  247.  *  - Opcional: poniendo 'true' las variables se actualizarán.
  248.  *
  249.  * ============================================================================
  250.  * Incompatibilidades
  251.  * ============================================================================
  252.  *
  253.  * No se conocen complementos que sean incompatibles hasta la fecha.
  254.  *
  255.  * ============================================================================
  256.  * Problemas conocidos
  257.  * ============================================================================
  258.  *
  259.  * No hay problemas hasta la fecha.
  260.  *
  261.  * ============================================================================
  262.  * Historial de versiones
  263.  * ============================================================================
  264.  *
  265.  * Version 1.01:
  266.  * - Se ha añadido la utilidad de viaje en el tiempo.
  267.  *
  268.  * Version 1.00:
  269.  * - Complemento terminado.
  270.  *
  271.  * ============================================================================
  272.  *
  273.  * Se permite el uso comercial.
  274.  * Se debe incluir a ICF-Soft en los créditos.
  275.  * Esta cabecera debe incluirse íntegramente con el plugin.
  276.  *
  277.  * ============================================================================
  278. */
  279. //=============================================================================
  280.  
  281. //=============================================================================
  282. // Parameter Variables
  283. //=============================================================================
  284.  
  285. ICF.Parameters = PluginManager.parameters('ICFSoft_TimeUtil');
  286. ICF.Param = ICF.Param || {};
  287.  
  288. ICF.Param.TimeVars = [];
  289. ICF.Param.TimeVars[0] = Number(ICF.Parameters['Year Var']);
  290. ICF.Param.TimeVars[1] = Number(ICF.Parameters['Month Var']);
  291. ICF.Param.TimeVars[2] = Number(ICF.Parameters['Day Var']);
  292. ICF.Param.TimeVars[3] = Number(ICF.Parameters['Hour Var']);
  293. ICF.Param.TimeVars[4] = Number(ICF.Parameters['Minute Var']);
  294. ICF.Param.TimeVars[5] = Number(ICF.Parameters['Week Var']);
  295. ICF.Param.TimeVars[6] = Number(ICF.Parameters['Month and day']);
  296.  
  297. ICF.Param.TimeTravel = Number(ICF.Parameters['Time travel']);
  298.  
  299. //=============================================================================
  300. // Time Utilities
  301. //=============================================================================
  302.  
  303. ICF.TimeUtil.GetTime = function(varid) {
  304.     var Today = new Date();
  305.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  306.     $gameVariables.setValue(varid, parseInt(Today.getTime()/60000));
  307. }
  308.  
  309. ICF.TimeUtil.GetTimeSince = function(varid, resid) {
  310.     var Today = new Date();
  311.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  312.     if (resid == undefined) {return (parseInt(Today.getTime()/60000) - $gameVariables.value(varid));}
  313.     $gameVariables.setValue(resid, parseInt(Today.getTime()/60000) - $gameVariables.value(varid));
  314. }
  315.  
  316. ICF.TimeUtil.GetHoursSince = function(varid, resid) {
  317.     if (resid == undefined) {return (ICF.TimeUtil.GetTimeSince(varid)/60)};
  318.     var Today = new Date();
  319.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  320.     $gameVariables.setValue(resid, parseInt((Today.getTime()/60000) - $gameVariables.value(varid))/60);
  321. }
  322.  
  323. ICF.TimeUtil.GetDaysSince = function(varid, resid) {
  324.     if (resid == undefined) {return (ICF.TimeUtil.GetTimeSince(varid)/1440)};
  325.     var Today = new Date();
  326.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  327.     $gameVariables.setValue(resid, parseInt((Today.getTime()/60000) - $gameVariables.value(varid))/1440);
  328. }
  329.  
  330. ICF.TimeUtil.GetDate = function() {
  331.     var Today = new Date();
  332.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  333.     if (ICF.Param.TimeVars[0] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[0], Today.getFullYear());}
  334.     if (ICF.Param.TimeVars[1] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[1], Today.getMonth() + 1);}
  335.     if (ICF.Param.TimeVars[2] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[2], Today.getDate());}
  336.     if (ICF.Param.TimeVars[3] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[3], Today.getHours());}
  337.     if (ICF.Param.TimeVars[4] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[4], Today.getMinutes());}
  338.     if (ICF.Param.TimeVars[5] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[5], Today.getDay());}
  339.     if (ICF.Param.TimeVars[6] > 0) {
  340.         $gameVariables.setValue(ICF.Param.TimeVars[6], Today.getMonth() * 100 + Today.getDate() + 100);
  341.     }
  342.  
  343. }
  344.  
  345. ICF.TimeUtil.GoPresent = function(updating) {
  346.     $gameVariables.setValue(ICF.Param.TimeTravel, 0);
  347.     if (updating) {ICF.TimeUtil.GetDate();}
  348. }
  349.  
  350. ICF.TimeUtil.AdvanceTime = function(minutes, updating) {
  351.     if (minutes == undefined) {minutes = 1}
  352.     $gameVariables.setValue(ICF.Param.TimeTravel, ICF.Param.TimeTravel + minutes);
  353.     if (updating) {ICF.TimeUtil.GetDate();}
  354. }
  355.  
  356. ICF.TimeUtil.AdvanceDays = function(days, updating) {
  357.     if (days == undefined) {days = 1}
  358.     $gameVariables.setValue(ICF.Param.TimeTravel, ICF.Param.TimeTravel + days * 1440);
  359.     if (updating) {ICF.TimeUtil.GetDate();}
  360. }
  361.  
  362. ICF.TimeUtil.AdvanceYears = function(years, updating) {
  363.     if (years == undefined) {years = 1}
  364.     $gameVariables.setValue(ICF.Param.TimeTravel, ICF.Param.TimeTravel + years * 525960);
  365.     if (updating) {ICF.TimeUtil.GetDate();}
  366. }
  367.  
  368. //=============================================================================
  369. // Game_Interpreter
  370. //=============================================================================
  371.  
  372. ICF.TimeUtil.pluginCommand = Game_Interpreter.prototype.pluginCommand;
  373. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  374.         ICF.TimeUtil.pluginCommand.call(this, command, args);
  375.     if (command === 'GetTime') {
  376.         ICF.TimeUtil.GetTime(args[0]);
  377.     } else if (command === 'GetTimeSince') {
  378.         ICF.TimeUtil.GetTimeSince(args[0], args[1]);
  379.     } else if (command === 'GetHoursSince') {
  380.         ICF.TimeUtil.GetHoursSince(args[0], args[1]);
  381.     } else if (command === 'GetDaysSince') {
  382.         ICF.TimeUtil.GetDaysSince(args[0], args[1]);
  383.         } else if (command === 'UpdateTime') {
  384.         ICF.TimeUtil.GetDate();
  385.         } else if (command === 'GoPresent') {
  386.         ICF.TimeUtil.GoPresent(args[0]);
  387.     } else if (command === 'AdvanceTime') {
  388.         ICF.TimeUtil.AdvanceTime(args[0], args[1]);
  389.     } else if (command === 'AdvanceDays') {
  390.         ICF.TimeUtil.AdvanceDays(args[0], args[1]);
  391.         } else if (command === 'AdvanceYears') {
  392.         ICF.TimeUtil.AdvanceYears(args[0], args[1]);
  393.         }
  394. };
  395.  
  396. //=============================================================================
  397. // Game_Map
  398. //=============================================================================
  399.  
  400. ICF.TimeUtil.mapsetup = Game_Map.prototype.setup;
  401. Game_Map.prototype.setup = function(mapId) {
  402.     ICF.TimeUtil.GetDate();
  403.     ICF.TimeUtil.mapsetup.call(this, mapId);
  404. };
  405.  
  406. //=============================================================================
  407. // End of File
  408. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement