I tried looking, but I'm unable to find what I'm looking for, and am struggling to figure this out.
Basically, I have a plugin, that lets me replace/swap an existing tile on the current map, with a specified tileId from the tileset currently being used at the location of X,Y,Z where Z is the layer, and this works fine.
Here is the code to replace tiles: $dataMap[[(z * $dataMap.height + y) * $dataMap.width + x]] = tileId
Currently, I store the X,Y,Z and TileId for replacement in an array.. 1 by 1. This is quite tedious.
But then I remembered, RPG Maker MZ has a nice little command: $gameMap.tileId(x, y, z) which grabs the tileId at X,Y,Z. Unfortunately it only grabs the tileId of the current map.
And that's where I thought, why don't I just grab the data of a different map, store that into an array. And then combine it to replace tiles en masse using a loop. If I were to create prefabbed buildings, structures, etc.. on a secondary map, I could just specify a start x & y, and a finish x & y in a nested loop, to grab that data, store it into an array, and then do basically the same thing in reverse to place them on the map currently being played on.
And that's where I'm now stuck. I have absolutely no idea how to pull the tiledata of a different map.
I tried: DataManager.loadMapData(mapId). This sort of worked. It did the following:
Loaded the map data, so that using $dataMap.data would give me data of the 'loaded' map, but with a caveat. Trying to use the replacement code to swap the tiles didn't work.
So, I tried, using 'loadMapData' (abbreviated for explanations sake) to first load the secondary map, grab the data, store it into an array, and then use 'loadMapData' again to reload the primary map and then try to swap the tiles. Unfortunately, this also didn't work. There were no errors, just the map visually didn't update.
But after restarting the game, and swapping the tiles with my 'now' known data and loop, it did work. So I then tried to refresh or update the map, refresh or update the scene. But again, nothing. My only guess is 'loadMapData' does something that just messes with things.
So I'm here asking for help, in hopes someone has the answers I'm looking for. I 'could' do this manually by just building the maps, loading the json file in VS-Code, copy & pasting the array into a new plugin file, and writing a function that will do this. But I feel like I'm 'close' to having this done within game, allowing me to use common events and such. Would there be a difference between doing it in game vs writing a function as a plugin? Nope. They'd both do the same thing in the end. I just want to know how to do it in the engine to learn and see why/what is going on with what I tried already.
Thank you for your time, sorry it's a long post, brain is melted and running on fumes lol.
Basically, I have a plugin, that lets me replace/swap an existing tile on the current map, with a specified tileId from the tileset currently being used at the location of X,Y,Z where Z is the layer, and this works fine.
Here is the code to replace tiles: $dataMap[[(z * $dataMap.height + y) * $dataMap.width + x]] = tileId
Currently, I store the X,Y,Z and TileId for replacement in an array.. 1 by 1. This is quite tedious.
But then I remembered, RPG Maker MZ has a nice little command: $gameMap.tileId(x, y, z) which grabs the tileId at X,Y,Z. Unfortunately it only grabs the tileId of the current map.
And that's where I thought, why don't I just grab the data of a different map, store that into an array. And then combine it to replace tiles en masse using a loop. If I were to create prefabbed buildings, structures, etc.. on a secondary map, I could just specify a start x & y, and a finish x & y in a nested loop, to grab that data, store it into an array, and then do basically the same thing in reverse to place them on the map currently being played on.
And that's where I'm now stuck. I have absolutely no idea how to pull the tiledata of a different map.
I tried: DataManager.loadMapData(mapId). This sort of worked. It did the following:
Loaded the map data, so that using $dataMap.data would give me data of the 'loaded' map, but with a caveat. Trying to use the replacement code to swap the tiles didn't work.
So, I tried, using 'loadMapData' (abbreviated for explanations sake) to first load the secondary map, grab the data, store it into an array, and then use 'loadMapData' again to reload the primary map and then try to swap the tiles. Unfortunately, this also didn't work. There were no errors, just the map visually didn't update.
But after restarting the game, and swapping the tiles with my 'now' known data and loop, it did work. So I then tried to refresh or update the map, refresh or update the scene. But again, nothing. My only guess is 'loadMapData' does something that just messes with things.
So I'm here asking for help, in hopes someone has the answers I'm looking for. I 'could' do this manually by just building the maps, loading the json file in VS-Code, copy & pasting the array into a new plugin file, and writing a function that will do this. But I feel like I'm 'close' to having this done within game, allowing me to use common events and such. Would there be a difference between doing it in game vs writing a function as a plugin? Nope. They'd both do the same thing in the end. I just want to know how to do it in the engine to learn and see why/what is going on with what I tried already.
Thank you for your time, sorry it's a long post, brain is melted and running on fumes lol.