Advertisement
MkNish

[RMMV Plugin] Self Variables

Dec 4th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // μ'ki's Self Variables v1.00
  3. // MK_SelfVariables.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. var Maki = Maki || {};
  8. Maki.SV = Maki.SV || {};
  9.  
  10. //=============================================================================
  11. /*:
  12.  * @plugindesc v1.00 Self Variables
  13.  * @author μ'ki
  14.  *
  15.  * @help
  16.  * ============================================================================
  17.  * Introduction
  18.  * ============================================================================
  19.  * The RPG MV default game system has self switches data, but you may also need
  20.  * 'self variables' that belong to each event object like self switches do.
  21.  * That was inspired by RPG VX script "Rei Self Variable", which can be found
  22.  * at RPGMakerID forum, so that I developed this RPG MV plugin for it.
  23.  *
  24.  * Contact me for support/bug report:
  25.  * listra92[at]gmail.com
  26.  *
  27.  * ============================================================================
  28.  * Features and Usages
  29.  * ============================================================================
  30.  *  - Allows self variables data to be stored in the game save data.
  31.  *  - Provides easier access to self variables and switches:
  32.  *    $gameSelfVariables.valueOf(eventId, 'name')
  33.  *    $gameSelfVariables.setValueOf = function(eventId, 'name', value);
  34.  *    $gameSelfSwitches.valueOf(eventId, 'name')
  35.  *    $gameSelfSwitches.setValueOf = function(eventId, 'name', value);
  36.  *
  37.  *    Note: The self switch names by default are 'A', 'B', 'C' and 'D', but
  38.  *          here you can define the names by yourself.
  39.  *
  40.  */
  41. //=============================================================================
  42.  
  43. //=============================================================================
  44. // Parameter Variables
  45. //=============================================================================
  46.  
  47. Maki.SV.Parameters = PluginManager.parameters('MK_SelfVariables');
  48.  
  49. //-----------------------------------------------------------------------------
  50. // Game_SelfVariables
  51. //-----------------------------------------------------------------------------
  52.  
  53. function Game_SelfVariables() {
  54.     this.initialize.apply(this, arguments);
  55. }
  56.  
  57. Game_SelfVariables.prototype.initialize = function() {
  58.     this.clear();
  59. };
  60.  
  61. Game_SelfVariables.prototype.clear = function() {
  62.     this._data = {};
  63. };
  64.  
  65. Game_SelfVariables.prototype.value = function(key) {
  66.     return this._data[key] || 0;
  67. };
  68.  
  69. Game_SelfVariables.prototype.setValue = function(key, value) {
  70.     this._data[key] = value;
  71.     this.onChange();
  72. };
  73.  
  74. Game_SelfVariables.prototype.valueOf = function(eventId, name) {
  75.     var key = [$gameMap._mapId, eventId, name];
  76.     return this.value(key);
  77. };
  78.  
  79. Game_SelfVariables.prototype.setValueOf = function(eventId, name, value) {
  80.     var key = [$gameMap._mapId, eventId, name];
  81.     this.setValue(key, value);
  82. };
  83.  
  84. Game_SelfVariables.prototype.onChange = function() {
  85.     $gameMap.requestRefresh();
  86. };
  87.  
  88. //-----------------------------------------------------------------------------
  89. // Game_SelfSwitches
  90. //-----------------------------------------------------------------------------
  91.  
  92. Game_SelfSwitches.prototype.valueOf = function(eventId, name) {
  93.     var key = [$gameMap._mapId, eventId, name];
  94.     return this.value(key);
  95. };
  96.  
  97. Game_SelfSwitches.prototype.setValueOf = function(eventId, name, value) {
  98.     var key = [$gameMap._mapId, eventId, name];
  99.     this.setValue(key, value);
  100. };
  101.  
  102. //-----------------------------------------------------------------------------
  103. // DataManager
  104. //-----------------------------------------------------------------------------
  105.  
  106. var $gameSelfVariables = null;
  107.  
  108. Maki.SV.DataManagerCreateGameObjects = DataManager.createGameObjects;
  109. DataManager.createGameObjects = function() {
  110.     Maki.SV.DataManagerCreateGameObjects.call(this);
  111.     $gameSelfVariables = new Game_SelfVariables();
  112. };
  113.  
  114. Maki.SV.DataManagerMakeSaveContents = DataManager.makeSaveContents;
  115. DataManager.makeSaveContents = function() {
  116.     // A save data does not contain $gameTemp, $gameMessage, and $gameTroop.
  117.     var contents = Maki.SV.DataManagerMakeSaveContents.call(this);
  118.     contents.selfVariables= $gameSelfVariables;
  119.     return contents;
  120. };
  121.  
  122. Maki.SV.DataManagerExtractSaveContents = DataManager.extractSaveContents;
  123. DataManager.extractSaveContents = function(contents) {
  124.     Maki.SV.DataManagerExtractSaveContents.call(this, contents);
  125.     $gameSelfVariables = contents.selfVariables;
  126. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement