[SOLVED] Event Script: show an image depending on the map ID

Hi there, at first I have to say: I am very bad at scripting and doing nearly everything in my game with the standard commands. I can more or less understand the basics of a script if I see it, but have not much JS-knowledge.

What I want:
I want to display an image depending on the MapID, or to be correct: depending on a range of this ID. Sketch:
If mapID is 10...15, then
ShowPicture(3) 'Image1.png' at location x
If mapID is 16..25, then
ShowPicture(3) 'Image2.png' at location y
...

Current setup:
1704407014335.png

With the help of some others from the community I got this script.
The center part is basically:
use 'MapX.fileformat' (X = mapID of the current map)
So if the mapID is 001, it automatically shows the image file "map1.png" at a specific location.
and if the mapID is 002, it automatically shows the image file "map2.png" at the same location.

But since I changed the way the map works, I need now not an automatic 1:1 correlation, but separate defined ranges of IDs for each image (so that I can set the image file and location individually).

But I have no Idea how to do this in detail ^^ "
You might consider writing this as a plugin since this is more complicated than what you can fit inside a script call. You can save the following text as a .js and install that as a plugin. If you try the plugin strategy I would highly recommend naming that plugin using your game name as part of the filename. If you're like me and have multiple small projects out, it really pays to mark which code is project-specific and can't be exported into a new project.

I don't know if "getPauseMenuBg" is the best name for this function since you gave no indication as to what purpose this code is supposed to serve. Feel free to rename this to something that directly describes what the function does.
Code:
Game_Screen.prototype.getPauseMenuBg = function(mapId) {
    if (mapId < 5) { //If mapId is between 0 to 4 inclusive
        return 'map1';
    } else if (mapId < 10) { //If mapId is between 5 to 9 inclusive
        return 'map2';
    }
    return 'mapDefault'; //If mapId does not match any of the above criteria
}

Then your script call would go along the lines of
Code:
$gameScreen.showPicture(3, $gameScreen.getPauseMenuBg(this._mapId), 0, 0, 0, 100, 100, 255, 0);
if (mapId > 5) { //If mapId is between 0 to 4 inclusive
Overall this is a very reasonable approach, but here you probably meant to use < instead of that >.
You might consider writing this as a plugin since this is more complicated than what you can fit inside a script call. You can save the following text as a .js and install that as a plugin. If you try the plugin strategy I would highly recommend naming that plugin using your game name as part of the filename. If you're like me and have multiple small projects out, it really pays to mark which code is project-specific and can't be exported into a new project.

I don't know if "getPauseMenuBg" is the best name for this function since you gave no indication as to what purpose this code is supposed to serve. Feel free to rename this to something that directly describes what the function does.
Code:
Game_Screen.prototype.getPauseMenuBg = function(mapId) {
    if (mapId < 5) { //If mapId is between 0 to 4 inclusive
        return 'map1';
    } else if (mapId < 10) { //If mapId is between 5 to 9 inclusive
        return 'map2';
    }
    return 'mapDefault'; //If mapId does not match any of the above criteria
}

Then your script call would go along the lines of
Code:
$gameScreen.showPicture(3, $gameScreen.getPauseMenuBg(this._mapId), 0, 0, 0, 100, 100, 255, 0);

Thanks, thats a very nice take. And easy to understand even for me xD
Only one thing left: How can I show every one of the images at its own location?
My Idea (as someone who has nearly no Idea of scripting) would be to replace the number values of the image location with another script call:
$gameScreen.showPicture(3, $gameScreen.getPauseMenuBg(this._mapId), 0, 0, 0, 100, 100, 255, 0);
$gameScreen.showPicture(3, $gameScreen.getPauseMenuBg(this._mapId),
$gameScreen.getBgXvalue(this._mapId), $gameScreen.getBgYvalue(this._mapID), 0, 100, 100, 255, 0);
And then make basically a list of if-->then-commands with the mapIDs and values in the plugin. But I don't know if it works this way xD
Okay, I found the solution:
1704414381547.png


I tried something like this already earlier, but it seems I messed something up in my first attempt.
Now it works. And this way I can set the location of each image individually, so the current area gets marked on the map.
1704416090859.png


But thanks for your ideas, you got me to the right way 🙂
This thread is being closed due to being solved. If you need it reopened, report it to let us know why. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/solved-event-script-show-an-image-depending-on-the-map-id.164468/