Guest User

RestoreLocation.js (RMMV plugin)

a guest
Nov 9th, 2015
184
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // RestoreLocation.js
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @plugindesc Allows you to specify where the player loads
  7.  * @author NoTaku
  8.  *
  9.  * @help
  10.  *
  11.  * Plugin Command:
  12.  *   RestoreLocation restore                                 # teleport the player to the stored location
  13.  *   RestoreLocation storeLoc mapid x y dir                  # store the specified location
  14.  *   RestoreLocation storeMap mapid                          # change the stored map
  15.  *   RestoreLocation storePos x y                            # change the stored x, y coordinate
  16.  *   RestoreLocation storeDir dir                            # change the stored direction
  17.  *   RestoreLocation storePlayerLoc                          # store the player's current location
  18.  *   RestoreLocation storeRelativeLoc evid x_off y_off dir   # store a location as an offset from the event with specified id
  19.  *   RestoreLocation storeVariableMap idvar                  # store a location from a map
  20.  *   RestoreLocation storeVariableLoc idvar xvar yvar dirvar # store a location from four variables
  21.  *   RestoreLocation storeVariablePos xvar yvar              # store an x, y coordinate from two variables
  22.  *   RestoreLocation storeVariableDir dirvar                 # store a direction from variable
  23.  *   RestoreLocation clear                                   # clear the stored location
  24.  *
  25.  */
  26.  
  27. (function() {
  28.     var parameters = PluginManager.parameters('RestoreLocation');
  29.  
  30.     var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  31.  
  32.     var _registry = {};
  33.  
  34.     _registry.restore = function() {
  35.         if($gamePlayer._savedMapId!==0) {
  36.             $gamePlayer.reserveTransfer($gamePlayer._savedMapId,$gamePlayer._savedX||$gamePlayer.x,$gamePlayer._savedY||$gamePlayer.y,$gamePlayer._savedDirection||$gamePlayer._direction);
  37.             return 1;
  38.         }
  39.         return 0;
  40.     };
  41.  
  42.     _registry.storeLoc = function(mapid,x,y,dir) {
  43.         $gamePlayer._savedMapId = mapid||$gameMap._mapId;
  44.         $gamePlayer._savedX = x;
  45.         $gamePlayer._savedY = y;
  46.         $gamePlayer._savedDirection = dir;
  47.     };
  48.  
  49.     _registry.storeMap = function(mapid) {
  50.         $gamePlayer._savedMapId = mapid||$gameMap._mapId;
  51.     };
  52.  
  53.     _registry.storePos = function(x,y) {
  54.         $gamePlayer._savedX = x;
  55.         $gamePlayer._savedY = y;
  56.     };
  57.  
  58.     _registry.storeDir = function(dir) {
  59.         $gamePlayer._savedDirection = dir;
  60.     };
  61.  
  62.     _registry.storePlayerLoc = function() {
  63.         $gamePlayer._savedMapId = $gameMap._mapId;
  64.         $gamePlayer._savedX = $gamePlayer.x;
  65.         $gamePlayer._savedY = $gamePlayer.y;
  66.         $gamePlayer._savedDirection = $gamePlayer._direction;
  67.     };
  68.  
  69.     _registry.storeRelativeLoc = function(evid,x_off,y_off,dir) {
  70.         var rel = $gameMap.event(evid||this._eventId);
  71.         if(rel) {
  72.             $gamePlayer._savedMap = $gameMap._mapId;
  73.             $gamePlayer._savedX = rel.x+x_off;
  74.             $gamePlayer._savedY = rel.y+y_off;
  75.             $gamePlayer.savedDirection = dir||rel._direction;
  76.         }
  77.     };
  78.  
  79.     _registry.storeVariableLoc = function(idvar,xvar,yvar,dirvar) {
  80.         var vars = $gameSystem.variables;
  81.         _registry.storeLoc(vars.value(idvar),vars.value(xvar),vars.value(yvar),vars.value(dirvar));
  82.     };
  83.  
  84.     _registry.storeVariableMap = function(idvar) {
  85.         _registry.storeMap($gameSystem.variables.value(idvar));
  86.     };
  87.  
  88.     _registry.storeVariablePos = function(xvar,yvar) {
  89.         var vars = $gameSystem.variables;
  90.         _registry.storePos(vars.value(xvar),vars.value(yvar));
  91.     };
  92.  
  93.     _registry.storeVariableDir = function(dirvar) {
  94.         _registry.storeDir($gameSystem.variables.value(dirvar))
  95.     };
  96.  
  97.     _registry.clear = function() {
  98.         $gamePlayer._savedMapId = 0;
  99.         $gamePlayer._savedX = 0;
  100.         $gamePlayer._savedY = 0;
  101.         $gamePlayer._savedDirection = 0;
  102.     };
  103.  
  104.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  105.         _Game_Interpreter_pluginCommand.call(this, command, args);
  106.         if(command === 'RestoreLocation') {
  107.             var func = _registry[args.shift()];
  108.             if(typeof func !== 'undefined') {
  109.                 func.apply(this,args);
  110.             }
  111.         }
  112.     };
  113.  
  114.     var _Game_Player_initMembers = Game_Player.prototype.initMembers;
  115.  
  116.     Game_Player.prototype.initMembers = function() {
  117.         _Game_Player_initMembers.call(this);
  118.         this._savedMapId = 0;
  119.         this._savedX = 0;
  120.         this._savedY = 0;
  121.         this._savedDirection = 0;
  122.     };
  123.  
  124.     Scene_Load.prototype.onLoadSuccess = function() {
  125.         SoundManager.playLoad();
  126.         this.fadeOutAll();
  127.         if(!_registry.restore()) {
  128.             this.reloadMapIfUpdated();
  129.         }
  130.         SceneManager.goto(Scene_Map);
  131.         this._loadSuccess = true;
  132.     };
  133. })();
RAW Paste Data