Greetings, I tried to make a system where it will show a picture based on the current mapID and also don't show the picture if the there's no picture file based on a said mapID exist. Here's the code.
My biggest struggle is with how to actually detect the said image files. I've been scouring through the forum and so far, there's no good and consistent solution for RPG Maker MZ.
Thanks in advance!
JavaScript:
var MapDisplay = MapDisplay || {};
MapDisplay.showMap = function() {
// Retrieve the current map's ID.
const mapId = $gameMap.mapId();
// Retrieve map images path
const imgPath = "Maps/";
//Combine the path and name file
const fullPath = imgPath + mapId;
const MapID_pngformat = mapId+".png";
// Set up the parameters for displaying the picture
const pictureId = 10;
const origin = 1;
const x = 512;
const y = 256;
const scaleX = 100;
const scaleY = 100;
const opacity = 255;
const blendMode = 0;
pictureExists = function(MapID_pngformat) {
const fs = require ("fs");
return fs.existsSync("./img/pictures/Maps" + MapID_pngformat);
};
if(pictureExists){
//If the image file exist then show it.
$gameScreen.showPicture(pictureId, fullPath, origin, x, y, scaleX, scaleY, opacity, blendMode);
}else{
//Otherwise call a common event
$gameTemp.reserveCommonEvent(159);
}
};
My biggest struggle is with how to actually detect the said image files. I've been scouring through the forum and so far, there's no good and consistent solution for RPG Maker MZ.
Thanks in advance!