Advertisement
ezmash

More Page Conditions (MV)

Jan 25th, 2018
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2.  * More Page Conditions by Shaz
  3.  * Ver 1.00 2018.01.23
  4.  * Shaz_MorePageConditions.js
  5.  *
  6.  *
  7.  * @plugindesc Adds more flexible page conditions via comments.
  8.  * @author Shaz
  9.  *
  10.  * @help This plugin has no plugin commands.
  11.  *
  12.  * Add comments to the top of an event page to include them when checking if
  13.  * the current page should be activated.  The comment block should begin with
  14.  * the word cond
  15.  *
  16.  * The following shortened formats are available:
  17.  * \ss([1, 2, 'A']) - converts to $gameSelfSwitches.value([1, 2, 'A'])
  18.  * \s(15)           - converts to $gameSwitches.value(15)
  19.  * \v(8)            - converts to $gameVariables.value(8)
  20.  *
  21.  * Any other valid command can be included, including combinations with
  22.  * && and || and ().
  23.  *
  24.  * Examples:
  25.  * cond \s(15) && \s(16] && \s(17) - page will be active if all 3 switches are
  26.  *      on, and any other page conditions are met
  27.  * cond \v(8) >= 10 && \v(8) <= 15 - page will be active if the variable is
  28.  *      between 10 and 15, inclusive
  29.  *
  30.  * Note - although you can add any script call that will evaluate to true/false
  31.  * as a condition, it may not cause an immediate change of pages.  The map
  32.  * only evaluates page conditions when something has requested a refresh.  By
  33.  * default, this list only includes things shown under the Conditions section
  34.  * of the event page - a change to switches, self switches, variables, party
  35.  * members, and items (which means items, armor or weapons).  If you want to
  36.  * add a condtion based on something else (for example, amount of gold, hp of
  37.  * party leader, etc), you will need to manually add a script call at the time
  38.  * those things can change: $gameMap.requestRefresh()
  39.  * Be careful not to do this too often - definitely not in a parallel process
  40.  * event, as refreshing the page events is a CPU-hungry activity and will
  41.  * cause lag if done too frequently.
  42.  *
  43.  */
  44.  
  45. var Imported = Imported || {};
  46. Imported.Shaz_MorePageConditions = true;
  47.  
  48. var Shaz = Shaz || {};
  49. Shaz.MPC = Shaz.MPC || {};
  50. Shaz.MPC.Version = 1.00;
  51.  
  52. (function() {
  53.     var _Shaz_Game_Event_meetsConditions = Game_Event.prototype.meetsConditions;
  54.     Game_Event.prototype.meetsConditions = function(page) {
  55.         var test1 = _Shaz_Game_Event_meetsConditions.call(this, page);
  56.         var test2 = this.meetsExtraConditions(page);
  57.         return test1 && test2;
  58.     };
  59.  
  60.     Game_Event.prototype.meetsExtraConditions = function(page) {
  61.         var l = page.list.filter(function(cmd) {
  62.             return cmd.code === 108 || cmd.code === 408;
  63.         });
  64.  
  65.         var building = false;
  66.         var cond = '';
  67.         l.forEach(function(cmd) {
  68.             if (cmd.parameters[0].match(/^cond (.*)$/i)) {
  69.                 cond += ' ' + RegExp.$1;
  70.                 building = true;
  71.             } else if (cmd.code === 408 && building) {
  72.                 cond += ' ' + RegExp.$1;
  73.             } else {
  74.                 building = false;
  75.             }
  76.         }, this);
  77.  
  78.         if (cond) {
  79.             cond = cond.replace(/\\ss/gi, '$gameSelfSwitches.value');
  80.             cond = cond.replace(/\\s/gi, '$gameSwitches.value');
  81.             cond = cond.replace(/\\v/gi, '$gameVariables.value');
  82.             return eval(cond);
  83.         } else {
  84.             return true;
  85.         }
  86.     };
  87.  
  88. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement