Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // RestoreLocation.js
- //=============================================================================
- /*:
- * @plugindesc Allows you to specify where the player loads
- * @author NoTaku
- *
- * @help
- *
- * Plugin Command:
- * RestoreLocation restore # teleport the player to the stored location
- * RestoreLocation storeLoc mapid x y dir # store the specified location
- * RestoreLocation storeMap mapid # change the stored map
- * RestoreLocation storePos x y # change the stored x, y coordinate
- * RestoreLocation storeDir dir # change the stored direction
- * RestoreLocation storePlayerLoc # store the player's current location
- * RestoreLocation storeRelativeLoc evid x_off y_off dir # store a location as an offset from the event with specified id
- * RestoreLocation storeVariableMap idvar # store a location from a map
- * RestoreLocation storeVariableLoc idvar xvar yvar dirvar # store a location from four variables
- * RestoreLocation storeVariablePos xvar yvar # store an x, y coordinate from two variables
- * RestoreLocation storeVariableDir dirvar # store a direction from variable
- * RestoreLocation clear # clear the stored location
- *
- */
- (function() {
- var parameters = PluginManager.parameters('RestoreLocation');
- var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
- var _registry = {};
- _registry.restore = function() {
- if($gamePlayer._savedMapId!==0) {
- $gamePlayer.reserveTransfer($gamePlayer._savedMapId,$gamePlayer._savedX||$gamePlayer.x,$gamePlayer._savedY||$gamePlayer.y,$gamePlayer._savedDirection||$gamePlayer._direction);
- return 1;
- }
- return 0;
- };
- _registry.storeLoc = function(mapid,x,y,dir) {
- $gamePlayer._savedMapId = mapid||$gameMap._mapId;
- $gamePlayer._savedX = x;
- $gamePlayer._savedY = y;
- $gamePlayer._savedDirection = dir;
- };
- _registry.storeMap = function(mapid) {
- $gamePlayer._savedMapId = mapid||$gameMap._mapId;
- };
- _registry.storePos = function(x,y) {
- $gamePlayer._savedX = x;
- $gamePlayer._savedY = y;
- };
- _registry.storeDir = function(dir) {
- $gamePlayer._savedDirection = dir;
- };
- _registry.storePlayerLoc = function() {
- $gamePlayer._savedMapId = $gameMap._mapId;
- $gamePlayer._savedX = $gamePlayer.x;
- $gamePlayer._savedY = $gamePlayer.y;
- $gamePlayer._savedDirection = $gamePlayer._direction;
- };
- _registry.storeRelativeLoc = function(evid,x_off,y_off,dir) {
- var rel = $gameMap.event(evid||this._eventId);
- if(rel) {
- $gamePlayer._savedMap = $gameMap._mapId;
- $gamePlayer._savedX = rel.x+x_off;
- $gamePlayer._savedY = rel.y+y_off;
- $gamePlayer.savedDirection = dir||rel._direction;
- }
- };
- _registry.storeVariableLoc = function(idvar,xvar,yvar,dirvar) {
- var vars = $gameSystem.variables;
- _registry.storeLoc(vars.value(idvar),vars.value(xvar),vars.value(yvar),vars.value(dirvar));
- };
- _registry.storeVariableMap = function(idvar) {
- _registry.storeMap($gameSystem.variables.value(idvar));
- };
- _registry.storeVariablePos = function(xvar,yvar) {
- var vars = $gameSystem.variables;
- _registry.storePos(vars.value(xvar),vars.value(yvar));
- };
- _registry.storeVariableDir = function(dirvar) {
- _registry.storeDir($gameSystem.variables.value(dirvar))
- };
- _registry.clear = function() {
- $gamePlayer._savedMapId = 0;
- $gamePlayer._savedX = 0;
- $gamePlayer._savedY = 0;
- $gamePlayer._savedDirection = 0;
- };
- Game_Interpreter.prototype.pluginCommand = function(command, args) {
- _Game_Interpreter_pluginCommand.call(this, command, args);
- if(command === 'RestoreLocation') {
- var func = _registry[args.shift()];
- if(typeof func !== 'undefined') {
- func.apply(this,args);
- }
- }
- };
- var _Game_Player_initMembers = Game_Player.prototype.initMembers;
- Game_Player.prototype.initMembers = function() {
- _Game_Player_initMembers.call(this);
- this._savedMapId = 0;
- this._savedX = 0;
- this._savedY = 0;
- this._savedDirection = 0;
- };
- Scene_Load.prototype.onLoadSuccess = function() {
- SoundManager.playLoad();
- this.fadeOutAll();
- if(!_registry.restore()) {
- this.reloadMapIfUpdated();
- }
- SceneManager.goto(Scene_Map);
- this._loadSuccess = true;
- };
- })();
RAW Paste Data