设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 93|回复: 0

[转载发布] Tile Changer (Shaz's plugin for MV ported to MZ)

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9015

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58751
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68660

    灌水之王

    发表于 2026-7-20 10:31:23 | 显示全部楼层 |阅读模式
    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:       
    1. <load:[5]>
    复制代码


    Example 2: If you want to copy tiles from Maps 5, 10 and 12
                    JavaScript:       
    1. <load:[5, 10, 12]>
    复制代码


    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:       
    1. //=============================================================================
    2. // Tile Changer (Shaz_TileChangerMZ.js)
    3. // by Shaz, edited by SeaPhoenix for compatibility with MZ
    4. // Last Updated: 2023.10.16 v1.20
    5. //=============================================================================
    6. /*:
    7. * @target MZ
    8. * @plugindesc Change tiles on map or copy tiles from another map
    9. * @author Shaz (edited by SeaPhoenix to work on MZ, with some minor changes)
    10. *
    11. * @help
    12. * This plugin allows you to copy a block of tiles from another map to the
    13. * current map, or from one place on the current map to another, or to
    14. * change an individual tile to a specific tile id.
    15. *
    16. * To Use:
    17. * -------
    18. *
    19. * To copy tiles from other maps, you must set up references to the map id
    20. * in the current map's note box.  This consists of the mapId, for
    21. * each map you want to copy tiles from.  The format should be as follows:
    22. *
    23. * If you want to copy tiles from just one map, e.g., map 5:
    24. * <load:[5]>
    25. *
    26. * If you want to copy tiles from two or more maps, e.g., maps 5, 10, and 12:
    27. * <load:[5, 10, 12]>
    28. *
    29. * This will then allow you to run the Copy Tiles plugin command, and refer to
    30. * the maps by their map ids.
    31. *
    32. * If you only wish to copy tile areas from the current map to another place
    33. * on the current map, you do not need to set up the map notes.  This is only
    34. * required if you want to copy from other maps.
    35. *
    36. * The current map and the maps being copied must use the same tileset, or at
    37. * least have the same or similar tiles in the same location on the tileset.
    38. * This plugin does not copy the tile image, just the tile id, so if the source
    39. * map has a vase of flowers, and the current map has a teddy bear in the same
    40. * location on the tileset, a teddy bear is what will appear when you copy the
    41. * tiles.
    42. *
    43. * If you only wish to use the Change Tile plugin command, you do not need to
    44. * set up the map notes.
    45. *
    46. * To find the tile id, see this very helpful thread by Llareian:
    47. * https://forums.rpgmakerweb.com/index.php?threads/how-to-determine-your-tileid.91129/
    48. *
    49. * Plugin Commands:
    50. * ----------------
    51. *
    52. * Copy Tiles: Copy tiles from a different map, or from the same map. You can copy
    53. * either a single tile or a rectangular block (you specify the source's upper left
    54. * x and y, and the lower right x and y). You can copy all layers (including
    55. * shadow and region), or choose which layers you want to copy.
    56. *
    57. * Change Tile: Change one tile at a specific location and layer.
    58. *
    59. * When using the plugin commands, you can enter either a number or a script call
    60. * for the coordinates, z-layer, and mapId.
    61. *
    62. * For example, if you want to change a tile where the coordinates are determined
    63. * by variables 10 and 11, set the x-coordinate to $gameVariables.value(10) and
    64. * the y-coordinate to $gameVariables.value(11).
    65. *
    66. * Change Log:
    67. * -----------
    68. * 2023.10.16  1.20  Modified by SeaPhoenix for MZ
    69. * 2018.03.24  1.10  Save tile changes (fixes issue with returning to map
    70. *                   after menu or battle, and loading games) - no longer any
    71. *                   need for an event to re-do tile changes when map is
    72. *                   reloaded.
    73. *
    74. * @command copyTiles
    75. * @text Copy tiles
    76. * @desc Select tiles to copy to a destination from a source.
    77. *
    78. * @arg destX
    79. * @type string
    80. * @text Destination x
    81. * @desc x-coordinate of the top left destination area
    82. *  
    83. * @arg destY
    84. * @type string
    85. * @text Destination y
    86. * @desc y-coordinate of the top left destination area
    87. *
    88. * @arg source
    89. * @type string
    90. * @text Source map id
    91. * @desc Source (mapId), 0 for current map
    92. * @min 0
    93. * @default 0
    94. *
    95. * @arg sourceX1
    96. * @type string
    97. * @text Source x1
    98. * @desc x-coordinate of the top left source area
    99. *  
    100. * @arg sourceY1
    101. * @type string
    102. * @text Source y1
    103. * @desc y-coordinate of the top left destination area
    104. *
    105. * @arg sourceX2
    106. * @type string
    107. * @text Source x2
    108. * @desc x-coordinate of the bottom right source area
    109. *  
    110. * @arg sourceY2
    111. * @type string
    112. * @text Source y2
    113. * @desc y-coordinate of the bottom right destination area
    114. *
    115. * @arg copyAll
    116. * @type boolean
    117. * @text Copy all layers?
    118. * @desc Set to ON if all layers should be copied. Otherwise, set this to OFF, and list layers in the next field.
    119. * @on On
    120. * @off Off
    121. * @default true
    122. *
    123. * @arg layers
    124. * @type string[]
    125. * @text Copy which layers?
    126. * @desc If not all layers, copy which layers (0: lower ground, 1: upper ground, 2: lower, 3: upper, 4: shadow, 5: region)
    127. *
    128. * @command changeTile
    129. * @text Change tile
    130. * @desc Changes the tile at the specified coordinates/layer to the tile id. No auto-formatting of autotiles happens.
    131. *
    132. * @arg coordX
    133. * @type string
    134. * @text x-coordinate
    135. * @desc x-coordinate of the tile to be changed
    136. *
    137. * @arg coordY
    138. * @type string
    139. * @text y-coordinate
    140. * @desc y-coordinate of the tile to be changed
    141. *  
    142. * @arg layerZ
    143. * @type string
    144. * @text Z-layer
    145. * @desc Ground (0), ground (1), lower (2), upper (3), shadow (4), region (5)
    146. *  
    147. * @arg tileId
    148. * @type string
    149. * @text Tile ID
    150. * @desc Change to this tile id (from the same tileset)
    151. *
    152. */
    153. var Imported = Imported || {};
    154. Imported.Shaz_TileChangerMZ = true;
    155. var Shaz = Shaz || {};
    156. Shaz.TC = Shaz.TC || {};
    157. Shaz.TC.Version = 1.20;
    158. (function() {
    159.     const pluginName = 'Shaz_TileChangerMZ';
    160.    
    161.     PluginManager.registerCommand(pluginName, 'copyTiles', args => {  // SPX modified for MZ
    162.         $gameMap.copyTiles(args);
    163.     });
    164.     PluginManager.registerCommand(pluginName, 'changeTile', args => {  // SPX modified for MZ
    165.         $gameMap.changeTile(args);
    166.     });
    167.     var _Shaz_TC_DataManager_onLoad = DataManager.onLoad;
    168.     DataManager.onLoad = function(object) {
    169.         _Shaz_TC_DataManager_onLoad.call(this, object);
    170.         if (object === $dataMap) {
    171.             $dataMap.extraMaps = {};
    172.             $dataMap.extraMapCount = 0;
    173.             if ($dataMap.meta.load) {
    174.                 $dataMap.meta.load = JSON.parse($dataMap.meta.load);
    175.                 for (var i = 0; i < $dataMap.meta.load.length; i++) {
    176.                     var mapId = parseInt($dataMap.meta.load[i]); // SPX modified map references: only mapIds are used
    177.                     var name = 'map' + mapId;
    178.                     var filename = 'Map%1.json'.format(mapId.padZero(3));
    179.                     this.loadExtraMap(name, filename);
    180.                 }
    181.             }
    182.         }
    183.     };
    184.     DataManager.loadExtraMap = function(name, src) {
    185.         var xhr = new XMLHttpRequest();
    186.         var url = 'data/' + src;
    187.         xhr.open('GET', url);
    188.         xhr.overrideMimeType('application/json');
    189.         xhr.onload = function() {
    190.             if (xhr.status < 400) {
    191.                 var data = JSON.parse(xhr.responseText);
    192.                 $dataMap.extraMaps[name] = {};
    193.                 $dataMap.extraMaps[name].width = data.width;
    194.                 $dataMap.extraMaps[name].height = data.height;
    195.                 $dataMap.extraMaps[name].data = data.data;
    196.                 $dataMap.extraMapCount -= 1;
    197.             } else {
    198.                 this.onXhrError(name, src, url);  // SPX added based on MZ's code
    199.             }
    200.         }
    201.         xhr.onerror = () => this.onXhrError(name, src, url);  // SPX modified based on MZ's code
    202.         $dataMap.extraMaps[name] = null;
    203.         $dataMap.extraMapCount += 1;
    204.         xhr.send();
    205.     };
    206.     var _Shaz_TC_DataManager_isMapLoaded = DataManager.isMapLoaded;
    207.     DataManager.isMapLoaded = function() {
    208.         return _Shaz_TC_DataManager_isMapLoaded.call(this) && $dataMap.extraMapCount === 0;  // SPX note: do we need to add isEventTest
    209.     };
    210.     var _Shaz_TC_Spriteset_Map_updateTilemap = Spriteset_Map.prototype.updateTilemap;
    211.     Spriteset_Map.prototype.updateTilemap = function() {
    212.         _Shaz_TC_Spriteset_Map_updateTilemap.call(this);
    213.         if ($gameTemp.needMapDataRefresh()) {
    214.             this._tilemap.setData($gameMap.width(), $gameMap.height(), $gameMap.data());
    215.             this._tilemap.refresh();
    216.             $gameTemp.setMapDataRefresh(false);
    217.         }
    218.     };
    219.     var _Shaz_TC_Game_Temp_initialize = Game_Temp.prototype.initialize;
    220.     Game_Temp.prototype.initialize = function() {
    221.         _Shaz_TC_Game_Temp_initialize.call(this);
    222.         this._needMapDataRefresh = false;
    223.     };
    224.     Game_Temp.prototype.needMapDataRefresh = function() {
    225.         return this._needMapDataRefresh;
    226.     };
    227.     Game_Temp.prototype.setMapDataRefresh = function(refresh) {
    228.         this._needMapDataRefresh = refresh;
    229.     };
    230.     var _Shaz_TC_Game_System_initialize = Game_System.prototype.initialize;
    231.     Game_System.prototype.initialize = function() {
    232.         _Shaz_TC_Game_System_initialize.call(this);
    233.         this._mapTiles = [];
    234.     };
    235.     Game_System.prototype.saveMapTile = function(location, tileId) {
    236.         var mapId = $gameMap.mapId();
    237.         if (!this._mapTiles[mapId]) {
    238.             this._mapTiles[mapId] = {};
    239.         }
    240.         this._mapTiles[mapId][location] = tileId;
    241.     };
    242.     Game_System.prototype.restoreMapTiles = function(mapId) {
    243.         var tiles = this._mapTiles[mapId] || {};
    244.         Object.keys(tiles).forEach(function(location) {
    245.             $dataMap.data[location] = tiles[location];
    246.         }.bind(this));
    247.         $gameTemp.setMapDataRefresh(true);
    248.     };
    249.     Game_Map.prototype.copyTiles = function(args) {
    250.         // SPX modified function slightly for MZ
    251.         var dtlx = eval(args.destX);
    252.         var dtly = eval(args.destY);
    253.         var src = eval(args.source);
    254.         var stlx = eval(args.sourceX1);
    255.         var stly = eval(args.sourceY1);
    256.         var sbrx = eval(args.sourceX2);
    257.         var sbry = eval(args.sourceY2);
    258.         var copyAll = args.copyAll === 'true';
    259.         let zarray;
    260.         if (copyAll) {
    261.             zarray = [0, 1, 2, 3, 4, 5];
    262.         } else {
    263.             const layers = JSON.parse(args.layers).map(x => eval(x));
    264.             zarray = [];
    265.             for (var i = 0; i < layers.length; i++) {
    266.                 zarray.push(layers[i]);
    267.             }
    268.         }
    269.         if (src === 0) {
    270.             var source = $dataMap;
    271.         } else {
    272.             var source = $dataMap.extraMaps['map' + src];
    273.         }
    274.         var sw = sbrx - stlx + 1;
    275.         var sh = sbry - stly + 1;
    276.         for (var z1 = 0; z1 < zarray.length; z1++) {
    277.             for (var y = 0; y < sh; y++) {
    278.                 for (var x = 0; x < sw; x++) {
    279.                     var sx = stlx + x;
    280.                     var sy = stly + y;
    281.                     var dx = dtlx + x;
    282.                     var dy = dtly + y;
    283.                     var z = zarray[z1];
    284.                     var dIndex = this.calcIndex($dataMap, dx, dy, z);
    285.                     var sIndex = this.calcIndex(source, sx, sy, z);
    286.                     var tileId = source.data[sIndex];
    287.                     $dataMap.data[dIndex] = tileId;
    288.                     $gameSystem.saveMapTile(dIndex, tileId);
    289.                 }
    290.             }
    291.         }
    292.         $gameTemp.setMapDataRefresh(true);
    293.     };
    294.     Game_Map.prototype.changeTile = function(args) {
    295.         var x = eval(args.coordX);
    296.         var y = eval(args.coordY);
    297.         var z = eval(args.layerZ);
    298.         var tileId = eval(args.tileId);
    299.         var mapLoc = this.calcIndex($dataMap, x, y, z);
    300.         $dataMap.data[mapLoc] = tileId;
    301.         $gameSystem.saveMapTile(mapLoc, tileId);
    302.         $gameTemp.setMapDataRefresh(true);
    303.     };
    304.     Game_Map.prototype.calcIndex = function(dataMap, x, y, z) {
    305.         var w = dataMap.width;
    306.         var h = dataMap.height;
    307.         return (z * w * h) + (y * w) + x;
    308.     };
    309.     var _Shaz_TC_Scene_Map_onMapLoaded = Scene_Map.prototype.onMapLoaded;
    310.     Scene_Map.prototype.onMapLoaded = function() {
    311.         $gameSystem.restoreMapTiles(this._transfer ? $gamePlayer.newMapId() : $gameMap.mapId());
    312.         _Shaz_TC_Scene_Map_onMapLoaded.call(this);
    313.     };
    314. })();
    复制代码


    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
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-4 20:28 , Processed in 0.151856 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表