Advertisement
ICF-Soft

ICF-Soft Event Extension 1.03 RPG Maker MV

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