Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- //LudoMapConnect.js
- //=============================================================================
- /*:
- * @plugindesc Allows you to forgo the use of events for transfering players from one map to another, especially usefull in the case that the maps have a line that "connects" them.
- * @author Alessio De Santis
- *
- * @param Default Region
- * @desc The region the plugin will check for when deciding to transfer the player.
- * @default 60
- *
- * @help
- * Use Region number 60 to indicate the transfer line, only one column of region 60 tiles will be saved in data.
- * Use <targetId:id> tag in the Map Properties to indicate what map the player will transfer to.
- */
- //-----------------------------------------------------------------------------
- $tileInfo = [
- ];
- $deReg = Number(PluginManager.parameters("LudoMapConnect")["Default Region"]) || 60;
- Scene_Map.prototype.isReady = function() {
- if (!this._mapLoaded && DataManager.isMapLoaded()) {
- this.onMapLoaded();
- this._mapLoaded = true;
- this.storage();
- }
- return this._mapLoaded && Scene_Base.prototype.isReady.call(this);
- };
- Game_Player.prototype.checkRegionTransfer = function(){
- x = this.x;
- y = this.y;
- id = this.regionId();
- dir = this._direction;
- id = Number($dataMap.meta.targetId);
- transfer = false;
- $tileInfo.forEach(
- function(tile){
- if(tile.x == x && tile.y == y && dir == (6 || 4) && id){
- transfer = true;
- }
- }
- )
- if(transfer){
- this.reserveTransfer(id, x, y, dir, 0);
- }
- };
- Game_Player.prototype.performTransfer = function() {
- if (this.isTransferring()) {
- this.setDirection(this._newDirection);
- if (this._newMapId !== $gameMap.mapId() || this._needsMapReload) {
- $gameMap.setup(this._newMapId);
- this.searchCorresponding(this.x, this.y);
- this._needsMapReload = false;
- }
- this.locate(this._newX, this._newY);
- this.refresh();
- this.clearTransferInfo();
- }
- };
- Game_Player.prototype.searchCorresponding = function(x, y) {
- var temp = $tileInfo;
- var newX = this._newX;
- Scene_Map.prototype.storage();
- temp.some(function(elements){
- ele = $tileInfo[elements.iD];
- if(ele){
- if(y == ele.y && x == ele.x){
- newX = ele.x;
- return true;
- }
- }
- });
- this._newX = newX;
- };
- Scene_Map.prototype.storage = function() {
- $tileInfo = [];
- var i, j, k;
- for(i = 0 ; i < $gameMap.width(); i++){
- for(j = 0 ; j < $gameMap.height(); j++){
- if($gameMap.regionId(i, j) == $deReg){
- for(k = j; k < $gameMap.height(); k++){
- if($gameMap.regionId(i, k) == $deReg){
- $tileInfo.push({
- iD : (k - j),
- x : i,
- y : k
- });
- } else {
- i = $gameMap.width();
- j = $gameMap.height();
- k = j;
- };
- }
- }
- }
- }
- console.log($tileInfo);
- };
- Game_Player.prototype.moveByInput = function() {
- if (!this.isMoving() && this.canMove()) {
- var direction = this.getInputDirection();
- if (direction > 0) {
- $gameTemp.clearDestination();
- } else if ($gameTemp.isDestinationValid()){
- var x = $gameTemp.destinationX();
- var y = $gameTemp.destinationY();
- direction = this.findDirectionTo(x, y);
- }
- if (direction > 0) {
- this.executeMove(direction);
- this.checkRegionTransfer();
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement