累计送礼: 0 个 累计收礼: 1 个 TA的每日心情 开心 2026-7-12 04:10
签到天数: 209 天
连续签到: 2 天
[LV.7]常住居民III
管理员
VIP
7
卡币
58751
OK点
16
推广点
0
同能卷
50
积分 68660
Shaz_TileChangerMZ.js
by Shaz (original plugin) and SeaPhoenix (edits for MZ)
Prologue
@Shaz has a great plugin to copy tiles and change tiles for MV, and I got their approval to port this plugin to MZ. The main edits are for compatibility, especially in terms of the plugin commands, and simplified map notes.
The text describing the plugin is mostly reproduced from the original thread:
https://forums.rpgmakerweb.com/index.php?threads/tile-changer-copy-tiles-and-change-tiles.90437/
Introduction
This plugin allows you to copy a block of tiles from another map to the current map, copy a block of tiles from one spot on the current map to another, or to change individual tiles to a specific tile Id.
How to use
Add to your plugin folder (call it Shaz_TileChangerMZ.js) and enable in the plugin manager.
Set up the notes on the current map
only if you want to copy tiles from other maps.
Use the plugin commands to copy or change tiles.
Map notes must be in the following format (note: this is slightly different from the original plugin):
Example 1: If you want to copy tiles from Map 5
JavaScript:
Example 2: If you want to copy tiles from Maps 5, 10 and 12
JavaScript:
Plugin Commands
Copy Tiles: Copy tiles from a different map, or from the same map. You can copy either a single tile or a rectangular block (you specify the source's upper left x and y, and the lower right x and y). You can copy all layers (including shadow and region), or choose which layers you want to copy.
Change Tile: Change one tile at a specific location and layer. No auto-formatting of autotiles happens.
When using the plugin commands, you can enter either a number or a script call for the coordinates, z-layer, and mapId.
For example, if you want to change a tile where the coordinates are determined by variables 10 and 11, set the x-coordinate to $gameVariables.value(10) and the y-coordinate to $gameVariables.value(11).
Note: To find the Tile Id, see this very helpful thread by
@Llareian :
https://forums.rpgmakerweb.com/index.php?threads/how-to-determine-your-tileid.91129/
Credit
Shaz and SeaPhoenix
Terms
Free for use in non-commercial and commercial games.
Do not post elsewhere - link back to this page.
Notes
This plugin changes/copies the tile Id, not the image. So your other maps should use the same tileset, or at least have the the tiles that you want to copy in the same position on both tilesets. Otherwise you could be trying to copy a vase with flowers from one map, and have it turn into a teddy bear on the other.
This plugin saves the tile changes. If you leave the map (to another map, the battle screen or a menu) and return, or save the game and reload, the tile changes will still be there.
Download
Copy and paste the following into a text editor and save as Shaz_TileChangerMZ.js.
Spoiler: Plugin
JavaScript: //============================================================================= // Tile Changer (Shaz_TileChangerMZ.js) // by Shaz, edited by SeaPhoenix for compatibility with MZ // Last Updated: 2023.10.16 v1.20 //============================================================================= /*: * @target MZ * @plugindesc Change tiles on map or copy tiles from another map * @author Shaz (edited by SeaPhoenix to work on MZ, with some minor changes) * * @help * This plugin allows you to copy a block of tiles from another map to the * current map, or from one place on the current map to another, or to * change an individual tile to a specific tile id. * * To Use: * ------- * * To copy tiles from other maps, you must set up references to the map id * in the current map's note box. This consists of the mapId, for * each map you want to copy tiles from. The format should be as follows: * * If you want to copy tiles from just one map, e.g., map 5: * <load:[5]> * * If you want to copy tiles from two or more maps, e.g., maps 5, 10, and 12: * <load:[5, 10, 12]> * * This will then allow you to run the Copy Tiles plugin command, and refer to * the maps by their map ids. * * If you only wish to copy tile areas from the current map to another place * on the current map, you do not need to set up the map notes. This is only * required if you want to copy from other maps. * * The current map and the maps being copied must use the same tileset, or at * least have the same or similar tiles in the same location on the tileset. * This plugin does not copy the tile image, just the tile id, so if the source * map has a vase of flowers, and the current map has a teddy bear in the same * location on the tileset, a teddy bear is what will appear when you copy the * tiles. * * If you only wish to use the Change Tile plugin command, you do not need to * set up the map notes. * * To find the tile id, see this very helpful thread by Llareian: * https://forums.rpgmakerweb.com/index.php?threads/how-to-determine-your-tileid.91129/ * * Plugin Commands: * ---------------- * * Copy Tiles: Copy tiles from a different map, or from the same map. You can copy * either a single tile or a rectangular block (you specify the source's upper left * x and y, and the lower right x and y). You can copy all layers (including * shadow and region), or choose which layers you want to copy. * * Change Tile: Change one tile at a specific location and layer. * * When using the plugin commands, you can enter either a number or a script call * for the coordinates, z-layer, and mapId. * * For example, if you want to change a tile where the coordinates are determined * by variables 10 and 11, set the x-coordinate to $gameVariables.value(10) and * the y-coordinate to $gameVariables.value(11). * * Change Log: * ----------- * 2023.10.16 1.20 Modified by SeaPhoenix for MZ * 2018.03.24 1.10 Save tile changes (fixes issue with returning to map * after menu or battle, and loading games) - no longer any * need for an event to re-do tile changes when map is * reloaded. * * @command copyTiles * @text Copy tiles * @desc Select tiles to copy to a destination from a source. * * @arg destX * @type string * @text Destination x * @desc x-coordinate of the top left destination area * * @arg destY * @type string * @text Destination y * @desc y-coordinate of the top left destination area * * @arg source * @type string * @text Source map id * @desc Source (mapId), 0 for current map * @min 0 * @default 0 * * @arg sourceX1 * @type string * @text Source x1 * @desc x-coordinate of the top left source area * * @arg sourceY1 * @type string * @text Source y1 * @desc y-coordinate of the top left destination area * * @arg sourceX2 * @type string * @text Source x2 * @desc x-coordinate of the bottom right source area * * @arg sourceY2 * @type string * @text Source y2 * @desc y-coordinate of the bottom right destination area * * @arg copyAll * @type boolean * @text Copy all layers? * @desc Set to ON if all layers should be copied. Otherwise, set this to OFF, and list layers in the next field. * @on On * @off Off * @default true * * @arg layers * @type string[] * @text Copy which layers? * @desc If not all layers, copy which layers (0: lower ground, 1: upper ground, 2: lower, 3: upper, 4: shadow, 5: region) * * @command changeTile * @text Change tile * @desc Changes the tile at the specified coordinates/layer to the tile id. No auto-formatting of autotiles happens. * * @arg coordX * @type string * @text x-coordinate * @desc x-coordinate of the tile to be changed * * @arg coordY * @type string * @text y-coordinate * @desc y-coordinate of the tile to be changed * * @arg layerZ * @type string * @text Z-layer * @desc Ground (0), ground (1), lower (2), upper (3), shadow (4), region (5) * * @arg tileId * @type string * @text Tile ID * @desc Change to this tile id (from the same tileset) * */ var Imported = Imported || {}; Imported.Shaz_TileChangerMZ = true; var Shaz = Shaz || {}; Shaz.TC = Shaz.TC || {}; Shaz.TC.Version = 1.20; (function() { const pluginName = 'Shaz_TileChangerMZ'; PluginManager.registerCommand(pluginName, 'copyTiles', args => { // SPX modified for MZ $gameMap.copyTiles(args); }); PluginManager.registerCommand(pluginName, 'changeTile', args => { // SPX modified for MZ $gameMap.changeTile(args); }); var _Shaz_TC_DataManager_onLoad = DataManager.onLoad; DataManager.onLoad = function(object) { _Shaz_TC_DataManager_onLoad.call(this, object); if (object === $dataMap) { $dataMap.extraMaps = {}; $dataMap.extraMapCount = 0; if ($dataMap.meta.load) { $dataMap.meta.load = JSON.parse($dataMap.meta.load); for (var i = 0; i < $dataMap.meta.load.length; i++) { var mapId = parseInt($dataMap.meta.load[i]); // SPX modified map references: only mapIds are used var name = 'map' + mapId; var filename = 'Map%1.json'.format(mapId.padZero(3)); this.loadExtraMap(name, filename); } } } }; DataManager.loadExtraMap = function(name, src) { var xhr = new XMLHttpRequest(); var url = 'data/' + src; xhr.open('GET', url); xhr.overrideMimeType('application/json'); xhr.onload = function() { if (xhr.status < 400) { var data = JSON.parse(xhr.responseText); $dataMap.extraMaps[name] = {}; $dataMap.extraMaps[name].width = data.width; $dataMap.extraMaps[name].height = data.height; $dataMap.extraMaps[name].data = data.data; $dataMap.extraMapCount -= 1; } else { this.onXhrError(name, src, url); // SPX added based on MZ's code } } xhr.onerror = () => this.onXhrError(name, src, url); // SPX modified based on MZ's code $dataMap.extraMaps[name] = null; $dataMap.extraMapCount += 1; xhr.send(); }; var _Shaz_TC_DataManager_isMapLoaded = DataManager.isMapLoaded; DataManager.isMapLoaded = function() { return _Shaz_TC_DataManager_isMapLoaded.call(this) && $dataMap.extraMapCount === 0; // SPX note: do we need to add isEventTest }; var _Shaz_TC_Spriteset_Map_updateTilemap = Spriteset_Map.prototype.updateTilemap; Spriteset_Map.prototype.updateTilemap = function() { _Shaz_TC_Spriteset_Map_updateTilemap.call(this); if ($gameTemp.needMapDataRefresh()) { this._tilemap.setData($gameMap.width(), $gameMap.height(), $gameMap.data()); this._tilemap.refresh(); $gameTemp.setMapDataRefresh(false); } }; var _Shaz_TC_Game_Temp_initialize = Game_Temp.prototype.initialize; Game_Temp.prototype.initialize = function() { _Shaz_TC_Game_Temp_initialize.call(this); this._needMapDataRefresh = false; }; Game_Temp.prototype.needMapDataRefresh = function() { return this._needMapDataRefresh; }; Game_Temp.prototype.setMapDataRefresh = function(refresh) { this._needMapDataRefresh = refresh; }; var _Shaz_TC_Game_System_initialize = Game_System.prototype.initialize; Game_System.prototype.initialize = function() { _Shaz_TC_Game_System_initialize.call(this); this._mapTiles = []; }; Game_System.prototype.saveMapTile = function(location, tileId) { var mapId = $gameMap.mapId(); if (!this._mapTiles[mapId]) { this._mapTiles[mapId] = {}; } this._mapTiles[mapId][location] = tileId; }; Game_System.prototype.restoreMapTiles = function(mapId) { var tiles = this._mapTiles[mapId] || {}; Object.keys(tiles).forEach(function(location) { $dataMap.data[location] = tiles[location]; }.bind(this)); $gameTemp.setMapDataRefresh(true); }; Game_Map.prototype.copyTiles = function(args) { // SPX modified function slightly for MZ var dtlx = eval(args.destX); var dtly = eval(args.destY); var src = eval(args.source); var stlx = eval(args.sourceX1); var stly = eval(args.sourceY1); var sbrx = eval(args.sourceX2); var sbry = eval(args.sourceY2); var copyAll = args.copyAll === 'true'; let zarray; if (copyAll) { zarray = [0, 1, 2, 3, 4, 5]; } else { const layers = JSON.parse(args.layers).map(x => eval(x)); zarray = []; for (var i = 0; i < layers.length; i++) { zarray.push(layers[i]); } } if (src === 0) { var source = $dataMap; } else { var source = $dataMap.extraMaps['map' + src]; } var sw = sbrx - stlx + 1; var sh = sbry - stly + 1; for (var z1 = 0; z1 < zarray.length; z1++) { for (var y = 0; y < sh; y++) { for (var x = 0; x < sw; x++) { var sx = stlx + x; var sy = stly + y; var dx = dtlx + x; var dy = dtly + y; var z = zarray[z1]; var dIndex = this.calcIndex($dataMap, dx, dy, z); var sIndex = this.calcIndex(source, sx, sy, z); var tileId = source.data[sIndex]; $dataMap.data[dIndex] = tileId; $gameSystem.saveMapTile(dIndex, tileId); } } } $gameTemp.setMapDataRefresh(true); }; Game_Map.prototype.changeTile = function(args) { var x = eval(args.coordX); var y = eval(args.coordY); var z = eval(args.layerZ); var tileId = eval(args.tileId); var mapLoc = this.calcIndex($dataMap, x, y, z); $dataMap.data[mapLoc] = tileId; $gameSystem.saveMapTile(mapLoc, tileId); $gameTemp.setMapDataRefresh(true); }; Game_Map.prototype.calcIndex = function(dataMap, x, y, z) { var w = dataMap.width; var h = dataMap.height; return (z * w * h) + (y * w) + x; }; var _Shaz_TC_Scene_Map_onMapLoaded = Scene_Map.prototype.onMapLoaded; Scene_Map.prototype.onMapLoaded = function() { $gameSystem.restoreMapTiles(this._transfer ? $gamePlayer.newMapId() : $gameMap.mapId()); _Shaz_TC_Scene_Map_onMapLoaded.call(this); }; })(); 复制代码
Examples (with screenshots):
Spoiler: Copying tiles from the same map
Original map:
Using the plugin command (the source map id is 0, to indicate that it's the same map):
Result:
Spoiler: Copying tiles from the same map, layers 0 and 3 only
Original map is the same as in the previous example.
Using the plugin command:
Result:
Spoiler: Copying tiles from different map, using variables
Original map is the same as in the first example.
Map notes (we're currently on map 3, and we may copy from maps 2 and 4):
Set the variables first, then use the plugin command:
Source (map 4, with the rectangular block that's being copied outlined in red):
Result:
Spoiler: Changing 1 tile
Original map is the same as in the first screenshot.
The first plugin command shown below on the left is a tile change at x = 12, y = 2 to the tile id 1 on layer 3.
The second plugin command (with the details on the right), shows a tile change at x = 14, y = 2 to the tile id 80*2 = 160 on layer 2, using script calls.
Result:
本贴来自国际rpgmaker官方论坛作者:SeaPhoenix处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/tile-changer-shazs-plugin-for-mv-ported-to-mz.162070/
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x