Advertisement
ICF-Soft

ICF-Soft Time Utility RPG Maker MV

Jan 18th, 2016
109
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.00 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.  * @help
  48.  * ============================================================================
  49.  * Introduction
  50.  * ============================================================================
  51.  *
  52.  * There are games where special things happen on specific day of the week,
  53.  * specific hour, specific day, and so on.
  54.  * There are games where time continues even when off.
  55.  *
  56.  * With this plugin you can do both.
  57.  *
  58.  * Time is stored in game variables and can be used inside events. Automatically
  59.  * updates on map changes, but can also be updated manually.
  60.  *
  61.  * Also you can store time and check how many real time has passed.
  62.  * Time is stored as minutes.
  63.  *
  64.  * ============================================================================
  65.  * Parameters
  66.  * ============================================================================
  67.  *
  68.  * There are six basic params to store current year, day, hour, etc.
  69.  * These params indicate what variables will be used to store that info.
  70.  * To skip a param put 0.
  71.  *
  72.  * Month and day comes in a special format because events can use only one
  73.  * variable per page. So it needs a combined one. Is Month*100 + Day.
  74.  * Some Month-Day Examples:
  75.  *   -  101: January 1st
  76.  *   -  102: January 2nd
  77.  *   -  201: February 1st
  78.  *   -  211: February 11th
  79.  *   - 1001: October 1st
  80.  *   - 1010: October 10th
  81.  *
  82.  * ============================================================================
  83.  * Plugin commands
  84.  * ============================================================================
  85.  *
  86.  * GetTime x
  87.  *
  88.  *  - To store a time into variable number 'x'.
  89.  *
  90.  * GetTimeSince x y
  91.  * GetHoursSince x y
  92.  * GetDaysSince x y
  93.  *
  94.  *  - To compare how much time passed since 'x' in minutes, hours or days
  95.  *    and store result in variable 'y'.
  96.  *
  97.  * UpdateTime
  98.  *
  99.  *  - To update time variables manually.
  100.  *
  101.  * ============================================================================
  102.  * Incompatibilities
  103.  * ============================================================================
  104.  *
  105.  * There's no known incompatible plugins yet.
  106.  *
  107.  * ============================================================================
  108.  * Known isues
  109.  * ============================================================================
  110.  *
  111.  * There's no known isues yet.
  112.  *
  113.  * ============================================================================
  114.  *
  115.  * Commercial use avaiable.
  116.  * Credit to ICF-Soft.
  117.  * This entire header must be included with plugin.
  118.  *
  119.  * ============================================================================
  120. */
  121. //=============================================================================
  122.  /*:es
  123.  * @plugindesc v1.00 This plugin stores date and time in game variables
  124.  * for diverse pourposes.
  125.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  126.  *
  127.  * @param Year Var
  128.  * @desc La variable donde almacenas el año.
  129.  * @default 0
  130.  *
  131.  * @param Month Var
  132.  * @desc La variable donde almacenas el mes (de 1 a 12).
  133.  * @default 0
  134.  *
  135.  * @param Day Var
  136.  * @desc La variable donde almacenas el día (de 1 a 31).
  137.  * @default 0
  138.  *
  139.  * @param Hour Var
  140.  * @desc La variable donde almacenas la hora.
  141.  * @default 0
  142.  *
  143.  * @param Minute Var
  144.  * @desc La variable donde almacenas los minutos.
  145.  * @default 0
  146.  *
  147.  * @param Week Var
  148.  * @desc La variable donde almacenas el día de la semana.
  149.  * La semana empieza con el domingo como 0.
  150.  * @default 0
  151.  *
  152.  * @param Month and day
  153.  * @desc Una variable especial donde se almacena una combinación de mes y día.
  154.  * @default 0
  155.  *
  156.  * @help
  157.  * ============================================================================
  158.  * Introducción
  159.  * ============================================================================
  160.  *
  161.  * Hay juegos en donde ciertos eventos solo pasan en un día, día de la semana,
  162.  * hora o incluso minuto específico.
  163.  * También los hay en los que el tiempo pasa aunque no estés jugando.
  164.  *
  165.  * Con este complemento puedes hacer ambas cosas.
  166.  *
  167.  * El tiempo se almacena en variables a las que se puede acceder en los eventos.
  168.  * Se actualiza en cada cambio de mapa, pero también con comando.
  169.  *
  170.  * Además puedes guardar una fecha y comparar cuanto tiempo real ha pasado.
  171.  * El tiempo se almacena en minutos.
  172.  *
  173.  * ============================================================================
  174.  * Parámetros
  175.  * ============================================================================
  176.  *
  177.  * Hay seis parámetros básicos donde almacenar el año, mes, día, hora, etc.
  178.  * Indican qué variables se van a utilizar para almacenar esa info.
  179.  * Para saltar un parámetro dejar en 0.
  180.  *
  181.  * Month and day comes usa un formato especial porque los eventos solo pueden
  182.  * usar una variable por página. Así que necesita una combinada.
  183.  * Viene en Mes*100 + Día.
  184.  * Algunos ejemplos:
  185.  *   -  101: 1  de Enero
  186.  *   -  102: 2  de Enero
  187.  *   -  201: 1  de Febrero
  188.  *   -  211: 11 de Febrero
  189.  *   - 1001: 1  de Octubre
  190.  *   - 1010: 10 de Octubre
  191.  *
  192.  * ============================================================================
  193.  * Comandos de complemento
  194.  * ============================================================================
  195.  *
  196.  * GetTime x
  197.  *
  198.  *  - Para almacenar el tiempo en la variable número 'x'.
  199.  *
  200.  * GetTimeSince x y
  201.  * GetHoursSince x y
  202.  * GetDaysSince x y
  203.  *
  204.  *  - Para comparar cuanto tiempo ha pasado desde 'x' en minutos, horas or días
  205.  *    y almacenar el resultado en la variable 'y'.
  206.  *
  207.  * UpdateTime
  208.  *
  209.  *  - Para actualizar manualmente las variables.
  210.  *
  211.  * ============================================================================
  212.  * Incompatibilidades
  213.  * ============================================================================
  214.  *
  215.  * No se conocen complementos que sean incompatibles hasta la fecha.
  216.  *
  217.  * ============================================================================
  218.  * Problemas conocidos
  219.  * ============================================================================
  220.  *
  221.  * No hay problemas hasta la fecha.
  222.  *
  223.  * ============================================================================
  224.  *
  225.  * Se permite el uso comercial.
  226.  * Se debe incluir a ICF-Soft en los créditos.
  227.  * Esta cabecera debe incluirse íntegramente con el plugin.
  228.  *
  229.  * ============================================================================
  230. */
  231. //=============================================================================
  232.  
  233. //=============================================================================
  234. // Parameter Variables
  235. //=============================================================================
  236.  
  237. ICF.Parameters = PluginManager.parameters('ICFSoft_TimeUtil');
  238. ICF.Param = ICF.Param || {};
  239.  
  240. ICF.Param.TimeVars = [];
  241. ICF.Param.TimeVars[0] = Number(ICF.Parameters['Year Var']);
  242. ICF.Param.TimeVars[1] = Number(ICF.Parameters['Month Var']);
  243. ICF.Param.TimeVars[2] = Number(ICF.Parameters['Day Var']);
  244. ICF.Param.TimeVars[3] = Number(ICF.Parameters['Hour Var']);
  245. ICF.Param.TimeVars[4] = Number(ICF.Parameters['Minute Var']);
  246. ICF.Param.TimeVars[5] = Number(ICF.Parameters['Week Var']);
  247. ICF.Param.TimeVars[6] = Number(ICF.Parameters['Month and day']);
  248.  
  249. //=============================================================================
  250. // Time Utilities
  251. //=============================================================================
  252.  
  253. ICF.TimeUtil.GetTime = function(varid) {
  254.     var Today = new Date();
  255.     $gameVariables.setValue(varid, parseInt(Today.getTime()/60000));
  256. }
  257.  
  258. ICF.TimeUtil.GetTimeSince = function(varid, resid = 0) {
  259.     var Today = new Date();
  260.     if (resid == 0) {return (parseInt(Today.getTime()/60000) - $gameVariables.value(varid));}
  261.     $gameVariables.setValue(resid, parseInt(Today.getTime()/60000) - $gameVariables.value(varid));
  262. }
  263.  
  264. ICF.TimeUtil.GetHoursSince = function(varid, resid = 0) {
  265.     if (resid == 0) {return (ICF.TimeUtil.GetTimeSince(varid)/60)};
  266.     var Today = new Date();
  267.     $gameVariables.setValue(resid, parseInt((Today.getTime()/60000) - $gameVariables.value(varid))/60);
  268. }
  269.  
  270. ICF.TimeUtil.GetDaysSince = function(varid, resid = 0) {
  271.     if (resid == 0) {return (ICF.TimeUtil.GetTimeSince(varid)/1440)};
  272.     var Today = new Date();
  273.     $gameVariables.setValue(resid, parseInt((Today.getTime()/60000) - $gameVariables.value(varid))/1440);
  274. }
  275.  
  276. ICF.TimeUtil.GetDate = function() {
  277.     var Today = new Date();
  278.     if (ICF.Param.TimeVars[0] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[0], Today.getFullYear());}
  279.     if (ICF.Param.TimeVars[1] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[1], Today.getMonth() + 1);}
  280.     if (ICF.Param.TimeVars[2] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[2], Today.getDate());}
  281.     if (ICF.Param.TimeVars[3] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[3], Today.getHours());}
  282.     if (ICF.Param.TimeVars[4] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[4], Today.getMinutes());}
  283.     if (ICF.Param.TimeVars[5] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[5], Today.getDay());}
  284.     if (ICF.Param.TimeVars[6] > 0) {
  285.         $gameVariables.setValue(ICF.Param.TimeVars[6], Today.getMonth() * 100 + Today.getDate() + 100);
  286.     }
  287.  
  288. }
  289.  
  290. //=============================================================================
  291. // Game_Interpreter
  292. //=============================================================================
  293.  
  294. ICF.TimeUtil.pluginCommand = Game_Interpreter.prototype.pluginCommand;
  295. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  296.         ICF.TimeUtil.pluginCommand.call(this, command, args);
  297.     if (command === 'GetTime') {
  298.         ICF.TimeUtil.GetTime(args[0]);
  299.     } else if (command === 'GetTimeSince') {
  300.         ICF.TimeUtil.GetTimeSince(args[0], args[1]);
  301.     } else if (command === 'GetHoursSince') {
  302.         ICF.TimeUtil.GetHoursSince(args[0], args[1]);
  303.     } else if (command === 'GetDaysSince') {
  304.         ICF.TimeUtil.GetDaysSince(args[0], args[1]);
  305.         } else if (command === 'UpdateTime') {
  306.         ICF.TimeUtil.GetDate();
  307.         }
  308. };
  309.  
  310. //=============================================================================
  311. // Game_Map
  312. //=============================================================================
  313.  
  314. ICF.TimeUtil.mapsetup = Game_Map.prototype.setup;
  315. Game_Map.prototype.setup = function(mapId) {
  316.     ICF.TimeUtil.GetDate();
  317.     ICF.TimeUtil.mapsetup.call(this, mapId);
  318. };
  319.  
  320. //=============================================================================
  321. // End of File
  322. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement