Mark All Tiles Impassible in a Tileset

professorbeej

Villager
Member
Joined
Feb 27, 2019
Messages
29
Reaction score
10
First Language
English
Primarily Uses
RMMV
Hey, folks!

I want to get into plugin development, so I figured I'd start out by trying to alleviate an issue I have that I can't find a plugin for. Personally, I hate individually marking tiles with 0, X, * because I have far more X tiles than anything else. So I want a plugin that can either mark the entire tileset X with a script or command, or (more likely) do that on import by changing the default passage from O to X.

I have found the documentation for the flags here: https://kinoar.github.io/rmmv-doc-web/interfaces/rpg.tileset.html

The array info is pretty straightforward: 0x0001: Impassable downward 0x0002: Impassable leftward 0x0004: Impassable rightward 0x0008: Impassable upward 0x0010

Or so I thought.

When looking at the Tilesets.json, I can find no indication of these flags or how they're used. I see them (I think) in various MapXXXX.json, but again, don't know how to quite get that info into a plugin script. Both because I am crazy new to RMMV scripting and because these arrays are ginormous.

I put this in the Learning JavaScript forum instead of the Plugin Request because I'm not so much interested in the solution to the problem as I am the fundamental how and why of the scripting behind solving it. If that makes sense.

Thanks, y'all!
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,627
Reaction score
1,060
First Language
English
Primarily Uses
RMMV
Get ready to get your hands dirty. Do you know what 0x10 is? That's hexadecimal notation for the hex number 10, which is equivalent to 16 in decimal and 0001 0000 in binary.

If you have a Windows computer I'd recommend opening up the Calculator app and switch to Programmer mode.

If you open up the code you'll see stuff like this:
Code:
Game_Map.prototype.checkPassage = function(x, y, bit) {
    var flags = this.tilesetFlags();
    var tiles = this.allTiles(x, y);
    for (var i = 0; i < tiles.length; i++) {
        var flag = flags[tiles[i]];
        if ((flag & 0x10) !== 0)  // [*] No effect on passage
            continue;
        if ((flag & bit) === 0)   // [o] Passable
            return true;
        if ((flag & bit) === bit) // [x] Impassable
            return false;
    }
    return false;
};
The single "&" is a bitwise AND operation to check the passability of the tile based on the flag. You could drop a breakpoint into that function and check the values in debug to get a better sense of what it is doing.

Edit:
Check this function too, it uses a bitwise shift operator
Code:
Game_Map.prototype.isPassable = function(x, y, d) {
     return this.checkPassage(x, y, (1 << (d / 2 - 1)) & 0x0f);
};
 
Last edited:

professorbeej

Villager
Member
Joined
Feb 27, 2019
Messages
29
Reaction score
10
First Language
English
Primarily Uses
RMMV
You guys are fantastic. Thank you.

As soon as I can get back to my computer, I’m gonna start getting in over my head since I’ve never worked with hex.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

-_- Now we have punishments for skipping meals, specially breakfast. At least let me sleep on Fridays -_-
colorize an old sketch
Welp... with numerous plugins and a bit of Javascript help, I've simulated an AP system in battle. Proud of myself honestly.
Why most of games like to give a horrible control to an aircraft vehicle? can I get a simplified control that does not require me to roll first just to change my direction?
Homie, this so amazing! Old but Gold :)

Forum statistics

Threads
93,430
Messages
912,285
Members
122,938
Latest member
pafell2
Top