Advertisement
ICF-Soft

ICF-Soft Event Expansion 1.02 RPG Maker MV

May 19th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ICF-Soft Plugins - Event Extension
  3. // ICFSoft_EventExtension.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.ICFSoft_Events = true;
  8.  
  9. var ICF = ICF || {};
  10. ICF.Events = ICF.Events || {};
  11.  
  12. //=============================================================================
  13.  /*:
  14.  * @plugindesc v1.02 This plugin allows more conditions to events.
  15.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  16.  *
  17.  * @param Developer HaltJS
  18.  * @desc When true it throws an error if an custom event condition
  19.  * javascript doesn't work.   NO - false     YES - true
  20.  * @default false
  21.  *
  22.  * @help
  23.  * ============================================================================
  24.  * Introduction
  25.  *
  26.  * Pageevents have a limited set of conditions, there are usefull but sometimes
  27.  * aren't enough.
  28.  * Variables by default aren't versatile enough because they have "greater or
  29.  * equal" only option.
  30.  *
  31.  * With this plugin you can add extra conditions like more switches, unlimited
  32.  * selfswitches, unlimited mapswitches and versatile variables.
  33.  *
  34.  * Mapswitches are special switches that aplies to all events in a map.
  35.  *
  36.  * Variables can now be "greater or equal", "greater than", "lower than",
  37.  * "lower or equal", "equal to" or "different than" a value.
  38.  *
  39.  * ============================================================================
  40.  * Parameters
  41.  * ============================================================================
  42.  *
  43.  * Developer HaltJS: This is a development variable usefull to check if there is
  44.  * a wrong javascript event condition.
  45.  * When true will throw an error when it found a wrong javascript in lunatic
  46.  * mode.
  47.  * When false it will be ignored and game continues.
  48.  *
  49.  * ============================================================================
  50.  * How to use
  51.  * ============================================================================
  52.  *
  53.  * To add an extra condition to a page just add a comment or note, same
  54.  * format as plugin commands:
  55.  *
  56.  * switch x x x x x x
  57.  * selfswitch x x x x x
  58.  * mapswitch x x
  59.  *
  60.  *  - Add specified game, self or map switch to conditions.
  61.  *  - You can place all same-tipe switchs you need in same line.
  62.  *
  63.  * variable x value
  64.  * variablehigh x value
  65.  * variableless x value
  66.  * variablemax x value
  67.  * variableequal x value
  68.  * variabledif x value
  69.  *
  70.  *  - Add a variable condition. There are six types: min value, higher than,
  71.  *    lower than, max value, equal and not equal.
  72.  *
  73.  * ============================================================================
  74.  * Lunatic Mode
  75.  * ============================================================================
  76.  *
  77.  * You can use special conditions to a page by using javascript.
  78.  * There are inside a comment or note like others conditions and if you use more
  79.  * than one all will be merged.
  80.  *
  81.  * Actually it only works for first line. It will be solved in a later version.
  82.  *
  83.  * customreq: code
  84.  *
  85.  *  result - this is where result is stored. By default is false.
  86.  *
  87.  * ============================================================================
  88.  * Plugin commands
  89.  * ============================================================================
  90.  *
  91.  * selfswitch x true/false
  92.  * mapswitch x true/false
  93.  *
  94.  *  - Turns on/off specified selfswitch or mapswitch.
  95.  *
  96.  * remoteswitch mapid eventid x true/false
  97.  *
  98.  *  - Turns on/off specified selfswitch or mapswitch remotely.
  99.  *    Use eventid 0 for a mapswitch.
  100.  *
  101.  * ============================================================================
  102.  * Incompatibilities
  103.  * ============================================================================
  104.  *
  105.  * There's no known incompatible plugins yet.
  106.  *
  107.  * ============================================================================
  108.  * Known isues
  109.  * ============================================================================
  110.  *
  111.  * Not yet.
  112.  *
  113.  * Plugins that allow to have more than 999 maps without increasing map ids
  114.  * can cause glitches between maps that shares selfswitches and mapswitches.
  115.  *
  116.  * ============================================================================
  117.  * Changelog
  118.  * ============================================================================
  119.  *
  120.  * Version 1.02:
  121.  * - Fixed and improved lunatic mode.
  122.  * - More versatile variables.
  123.  * - Added remote switchs.
  124.  *
  125.  * Version 1.01:
  126.  * - Added lunatic mode.
  127.  *
  128.  * Version 1.00:
  129.  * - Finished plugin!
  130.  *
  131.  * ============================================================================
  132.  *
  133.  * For commercial and non-commercial games.
  134.  * Credit to ICF-Soft.
  135.  * This entire header must be included with plugin.
  136.  *
  137.  * ============================================================================
  138. */
  139. //=============================================================================
  140.  /*:es
  141.  * @plugindesc v1.02 Este complemento permite más condiciones en los
  142.  * eventos.
  143.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  144.  *
  145.  * @param Developer HaltJS
  146.  * @desc Si está activado salta cuando una función personalizada
  147.  * da error.   No - false   Si - true
  148.  * @default false
  149.  *
  150.  * @help
  151.  * ============================================================================
  152.  * Introducción
  153.  * ============================================================================
  154.  *
  155.  * Las páginas de los eventos tienen un número limitado de condiciones, son
  156.  * útiles pero a veces no son suficientes.
  157.  * Las variables por defecto no son muy versátiles pues sólo tienen la opción
  158.  * de "igual o mayor".
  159.  *
  160.  * Con este complemento puedes añadir condiciones extra tales como más
  161.  * interruptores, autointerruptores ilimitados, interruptores de mapa ilimitados
  162.  * y variables más versátiles.
  163.  *
  164.  * Los nuevos interruptores de mapa son unos interruptores especiales similares
  165.  * a los automáticos, que afectan a todos los eventos del mapa.
  166.  *
  167.  * Las variables ahora permiten las opciones "igual o mayor", "mayor que",
  168.  * "menor que", "menor o igual", "igual que" o "distinto a".
  169.  *
  170.  * ============================================================================
  171.  * Parámetros
  172.  * ============================================================================
  173.  *
  174.  * Developer HaltJS: Esta es una variable de uso durante el desarrollo del juego
  175.  * útil cuando quieres comprobar si hay alguna función personalizada incorrecta.
  176.  * Cuando está activado al encontrar un error el juego se para.
  177.  * Cuando está desactivado ignora el error y el juego continúa.
  178.  *
  179.  * ============================================================================
  180.  * Uso
  181.  * ============================================================================
  182.  *
  183.  * Para añadir una condición extra en una página simplemente añadir una nota
  184.  * en el mismo formato que un comando de complemento:
  185.  *
  186.  * switch x x x x x
  187.  * selfswitch x x x
  188.  * mapswitch x
  189.  *
  190.  *  - Para añadir interruptor, autointerruptor e interruptor de mapa.
  191.  *  - Puedes usar todos los que necesites del mismo tipo en una misma linea.
  192.  *
  193.  * variable x value
  194.  * variablehigh x value
  195.  * variableless x value
  196.  * variablemax x value
  197.  * variableequal x value
  198.  * variabledif x value
  199.  *
  200.  *  - Para añadir condición de variable. Tipos: mínimo, mayor, menos,
  201.  *    máximo, igual y distinto.
  202.  *
  203.  * ============================================================================
  204.  * Lunatic Mode
  205.  * ============================================================================
  206.  *
  207.  * Puedes usar condiciones especiales en una página mediante javascript.
  208.  * Se pone el código en una nota del mismo modo que las demás condiciones.
  209.  * Si usas más de una se juntarán todas.
  210.  *
  211.  * Actualmente Sólo funciona con la primera linea. Se arreglará en una próxima
  212.  * versión.
  213.  *
  214.  * customreq: código
  215.  *
  216.  *  result - aquí se almacena el resultado. Por defecto está desactivado.
  217.  *
  218.  * ============================================================================
  219.  * Comandos de complemento
  220.  * ============================================================================
  221.  *
  222.  * selfswitch x true/false
  223.  * mapswitch x true/false
  224.  *
  225.  *  - Activa o desactiva el autointerruptor o interruptor de mapa.
  226.  *
  227.  * remoteswitch mapid eventid x true/false
  228.  *
  229.  *  - Activa o desactiva el autointerruptor o interruptor de mapa específico
  230.  *    de forma remota. Usar eventid 0 para interruptor de mapa.
  231.  *
  232.  * ============================================================================
  233.  * Incompatibilidades
  234.  * ============================================================================
  235.  *
  236.  * No se conocen complementos que sean incompatibles hasta la fecha.
  237.  *
  238.  * ============================================================================
  239.  * Problemas conocidos
  240.  * ============================================================================
  241.  *
  242.  * Por el momento ninguno.
  243.  *
  244.  * El uso de complementos que permiten usar más de 999 mapas que no incrementan
  245.  * las id's puede ocasionar bugs entre mapas que compartan interruptores
  246.  * especiales.
  247.  *
  248.  * ============================================================================
  249.  * Historial de versiones
  250.  * ============================================================================
  251.  *
  252.  * Version 1.02:
  253.  * - Modo lunático arreglado y mejorado.
  254.  * - Variables más versátiles.
  255.  * - Se han añadido interruptores remotos.
  256.  *
  257.  * Version 1.01:
  258.  * - Se ha añadido el modo lunático.
  259.  *
  260.  * Version 1.00:
  261.  * - Complemento terminado.
  262.  *
  263.  * ============================================================================
  264.  *
  265.  * Para juegos comerciales y no comerciales.
  266.  * Se debe incluir a ICF-Soft en los créditos.
  267.  * Esta cabecera debe incluirse íntegramente con el plugin.
  268.  *
  269.  * ============================================================================
  270. */
  271. //=============================================================================
  272.  
  273. //=============================================================================
  274. // Parameter Variables
  275. //=============================================================================
  276.  
  277. ICF.Parameters = PluginManager.parameters('ICFSoft_EventExtension');
  278. ICF.Param = ICF.Param || {};
  279.  
  280. ICF.Param.EventExHalt = ICF.Parameters['Developer HaltJS'].toLowerCase() === "true";
  281.  
  282. //=============================================================================
  283. // Event Utilities
  284. //=============================================================================
  285.  
  286. ICF.Events.Checking = false;
  287.  
  288. ICF.Events.CustomSwitch = function(mapid, evid, switchname, value) {
  289.     var _key = [mapid, evid, switchname];
  290.     var _value = (value.toLowerCase() === "true");
  291.     $gameSelfSwitches.setValue(_key, _value);
  292. }
  293.  
  294. ICF.Events.CustomCondition = function(page, content) {
  295.     var args = content.split(" ");
  296.     if (ICF.Events.Checking) {
  297.         page._customreq = page._customreq + content + '\n';
  298.     } else if (args[0] !== null && args[1] !== null) {
  299.         if (args[0].toLowerCase() == "switch") {
  300.             args.splice(0, 1);
  301.             page._switchs = page._switchs.concat(args);
  302.         } else if (args[0].toLowerCase() == "selfswitch") {
  303.             args.splice(0, 1);
  304.             page._selfswitchs = page._selfswitchs.concat(args);
  305.         } else if (args[0].toLowerCase() == "mapswitch") {
  306.             args.splice(0, 1);
  307.             page._mapswitchs = page._mapswitchs.concat(args);
  308.         } else if (((args[0].toLowerCase() == "variable")||(args[0].toLowerCase() == "variablemin")) && args[2] !== null) {
  309.             page._vars.push([3, args[1], args[2]]);
  310.         } else if (args[0].toLowerCase() == "variablehigh" && args[2] !== null) {
  311.             page._vars.push([2, args[1], args[2]]);
  312.         } else if (args[0].toLowerCase() == "variableless" && args[2] !== null) {
  313.             page._vars.push([4, args[1], args[2]]);
  314.         } else if (args[0].toLowerCase() == "variablemax" && args[2] !== null) {
  315.             page._vars.push([5, args[1], args[2]]);
  316.         } else if (args[0].toLowerCase() == "variableequal" && args[2] !== null) {
  317.             page._vars.push([0, args[1], args[2]]);
  318.         } else if (args[0].toLowerCase() == "variabledif" && args[2] !== null) {
  319.             page._vars.push([1, args[1], args[2]]);
  320.         } else if (args[0].toLowerCase() == "customreq:") {
  321.             page._customreq = page._customreq + content.substring(10) + '\n';
  322.             ICF.Events.Checking = true;
  323.         }
  324.     }
  325. }
  326.  
  327. ICF.Events.CheckVar = function(code, value1, value2) {
  328.     switch (code) {
  329.         case 0:
  330.             return (value1 == value2); break;
  331.         case 1:
  332.             return (value1 !== value2); break;
  333.         case 2:
  334.             return (value1 > value2); break;
  335.         case 3:
  336.             return (value1 >= value2); break;
  337.         case 4:
  338.             return (value1 < value2); break;
  339.         case 5:
  340.             return (value1 <= value2); break;
  341.         default:
  342.             return false;
  343.     }
  344. }
  345.  
  346. //=============================================================================
  347. // Game_Interpreter
  348. //=============================================================================
  349.  
  350. ICF.Events.pluginCommand = Game_Interpreter.prototype.pluginCommand;
  351. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  352.         ICF.Events.pluginCommand.call(this, command, args);
  353.     if (command === 'selfswitch') {
  354.         ICF.Events.CustomSwitch(this._mapId, this._eventId, args[0], args[1]);
  355.     } else if (command === 'mapswitch') {
  356.         ICF.Events.CustomSwitch(this._mapId, 0, args[0], args[1]);
  357.     } else if (command === 'remoteswitch') {
  358.         ICF.Events.CustomSwitch(args[0], args[1], args[2], args[3]);
  359.     }
  360. };
  361.  
  362. //=============================================================================
  363. // Game_Event
  364. //=============================================================================
  365.  
  366. ICF.Events.init = Game_Event.prototype.initialize;
  367. Game_Event.prototype.initialize = function(mapId, eventId) {
  368.     ICF.Events.init.call(this, mapId, eventId);
  369.     var pages = this.event().pages;
  370.     for (i = 0; i < pages.length; i += 1) {
  371.         var page = pages[i];
  372.         page._switchs = [];
  373.         page._selfswitchs = [];
  374.         page._mapswitchs = [];
  375.         page._vars = [];
  376.         page._varslow = [];
  377.         page._varseq = [];
  378.         page._customreq = "";
  379.         for (j = 0; j < page.list.length; j += 1) {
  380.             var command = page.list[j];
  381.             if (command.code === 108) {
  382.                 ICF.Events.Checking = false;
  383.                 ICF.Events.CustomCondition(page, command.parameters[0]);
  384.             } else if (command.code === 408) {
  385.                 ICF.Events.CustomCondition(page, command.parameters[0]);
  386.             }
  387.         }
  388.     }
  389.     this.refresh();
  390. };
  391.  
  392. ICF.Events.meetsConditions = Game_Event.prototype.meetsConditions;
  393. Game_Event.prototype.meetsConditions = function(page) {
  394.     if (!ICF.Events.meetsConditions.call(this, page)) {return false;}
  395.     if (page._switchs == null) {return true;}
  396.     for (i = 0; i < page._switchs.length; i += 1) {
  397.         if (!$gameSwitches.value(page._switchs[i])) {
  398.             return false;
  399.         }
  400.     }
  401.     for (i = 0; i < page._selfswitchs.length; i += 1) {
  402.         var key = [this._mapId, this._eventId, page._selfswitchs[i]];
  403.         if ($gameSelfSwitches.value(key) !== true) {
  404.             return false;
  405.         }
  406.     }
  407.     for (i = 0; i < page._mapswitchs.length; i += 1) {
  408.         var key = [this._mapId, 0, page._mapswitchs[i]];
  409.         if ($gameSelfSwitches.value(key) !== true) {
  410.             return false;
  411.         }
  412.     }
  413.     for (i = 0; i < page._vars.length; i += 1) {
  414.         if (!ICF.Events.CheckVar(page._vars[i][0], $gameVariables.value(page._vars[i][1]), page._vars[i][2])) {
  415.             return false;
  416.         }
  417.     }
  418.  
  419.     if (page._customreq.length != "") {
  420.         var result = false;
  421.         try {eval(page._customreq);}
  422.         catch (e) {if(ICF.Param.EventExHalt){throw new Error('Error in custom page condition for event');}}
  423.         return result;
  424.     }
  425.  
  426.     return true;
  427. };
  428.  
  429. //=============================================================================
  430. // End of File
  431. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement