Status
Not open for further replies.

JLowther

Veteran
Veteran
Joined
Feb 20, 2016
Messages
327
Reaction score
40
First Language
English
Primarily Uses
Wondering if anyone has heard of an easy method of making a certain terrain tag assign the tile a specified region ID as well.

For example, I'd always like terrain tag 3 to assign region #24 to that tile.

This can be done manually, or even automatically with the right scripting, but doing it that way creates a whole slew of issues with "load" times.

Thanks in advance!
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,789
Reaction score
15,915
First Language
English
Primarily Uses
RMMV
Why would you want to do that? Why not just use the terrain tag?

Given there are 4 layers for mapping, which could have 4 tiles, which could all have different terrain tags, what happens if one is 3 and the others are all something else?

What if you already have a different region id on that tile?

It can be done with scripting, and I don't think it would have much impact at all on load times. If you're comfortable with js, you could check out my plugin to change/copy tiles, and see how it grabs the map data as soon as it's loaded - that's where the code would need to be inserted so it could be updated before the map is drawn. Then for terrain tags and regions, I think you'd need to do a bit of bit manipulation to first check the terrain tags on the 4 layers, clear the current region id, then set the new region id. Then it would be made more or less difficult depending on how flexible you wanted it (if you wanted terrain tag 3 to convert to region 24 on every single map, it would be easy, but if you wanted to allow multiple conversions for a single map, or different conversions on different maps - 3 becomes 24 on some, but becomes 18 on others - it would add a bit of complexity in that you'd need to use notes).

The alternative is, whatever plugin you are using that checks for regions, make a similar one that checks for terrain tags, or modify the region one to also check for terrain tags.

The first option would probably be better though, as it only runs when a map is loaded, while the second would run every time the player took a step, so more checks, more frequently = greater load on processor.
 
Last edited:

JLowther

Veteran
Veteran
Joined
Feb 20, 2016
Messages
327
Reaction score
40
First Language
English
Primarily Uses
Why would you want to do that? Why not just use the terrain tag?

Hey, Shaz. Long time. :)

I want to do it because of this: https://forums.rpgmakerweb.com/inde...-v4-2-ultra-now-with-real-time-shadows.77679/
...And the fact that it goes by region ID to determine height.

Normally, this wouldn't be an issue, but I'm creating a game with pseudo random level generation that takes place mostly in the dark. Each level will actually have ~50 randomly generated mazes to select from. The game will choose one at random, and then a "level generator" will run that goes tile by tile and places events on walls for the player to interact with, including the entrance and exit.

The issue is that I either go through all 50 mazes and paint the region onto all of the necessary tiles to block light, or I figure out some way to do it via terrain tag (or change region ID based upon terrain tag).

I've begun learning JS but I'm still mostly a novice, using it for utility websites and nothing approaching a JS plugin yet, otherwise I'd delve in and try to alter the plugin to do what I need.

Just wasn't sure if there was a plugin in existence that already did this. There IS one that can change region IDs, but that creates the aforementioned "loading times".
 

Harosata

Dramatic Lightning's BFF
Veteran
Joined
Aug 20, 2015
Messages
250
Reaction score
84
First Language
English
Primarily Uses
RMMV
If this was Ace, I'd probably do a snippet like

Code:
class Game_Character < Game_CharacterBase
 def region_id
  c = $game_map.region(@x,@y)
  c = 24 if terrain_tag == 3
  return c
 end
end

Please note this is Ruby and won't work in MV, but pretty much the idea is that you get a region id of 24 when you're on a certain terrain, and a regular region id anywhere else. The other method would be to make changes to the plugin, though that may take a bit more work depending on how many times that region id is used.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,789
Reaction score
15,915
First Language
English
Primarily Uses
RMMV
The easiest scripting solution would be something like the above, or to change the lighting plugin to look for region 24 OR terrain 3. However, to check the terrain tag, the engine has to do one test for each of 4 layers, and is probably not a good idea considering Khas says the plugin is already performance intensive.

Give this a go ...

Code:
//=============================================================================
// Shaz_ConvertTerrainToRegion.js
//=============================================================================

/*:
* @plugindesc Convert region on tiles with a specific terrain tag
* @author Shaz
*
* @param Terrain ID
* @desc The terrain ID to be converted to a region ID
* @default 0
*
* @param Region ID
* @desc The region ID to convert to
* @default 0
*
* @help This plugin does not provide plugin commands.
*
* Note - if you already have a region ID on a tile, it will be overwritten!
*
*/

(function() {
    var parameters = PluginManager.parameters('Shaz_ConvertTerrainToRegion');
    var terrainID = Number(parameters['Terrain ID'] || 0);
    var regionID = Number(parameters['Region ID'] || 0);


    var _Shaz_TC_DataManager_onLoad = DataManager.onLoad;
    DataManager.onLoad = function(object) {
        _Shaz_TC_DataManager_onLoad.call(this, object);
        if (object === $dataMap && (terrainID !== 0 || regionID !== 0)) {
            var tileset = $dataTilesets[$dataMap.tilesetId];
            var h = $dataMap.height;
            var w = $dataMap.width;
            for (var y = 0; y < h; y++) {
                for (var x = 0; x < w; x++) {
                    var foundTerrain = false;
                    for (var z = 0; z < 4; z++) {
                        if (tileset.flags[$dataMap.data[(z * h + y) * w + x]] >> 12 === terrainID) {
                            foundTerrain = true;
                        }
                    }
                    if (foundTerrain) {
                            $dataMap.data[(5 * h + y) * w + x] = regionID;
                        }
                }
            }
        }
    };

})();

Shaz_ConvertTerrainToRegion.js

You didn't answer my questions about what happens if all 4 layers have different terrain tags and only one of them happens to be 3, or what if there's already a region id specified on that tile, so I've gone with the defaults of ANY of the 4 can be terrain 3, and an existing region id on a tile will be overwritten. That could cause some issues, so just be aware of it.

I'd be interested to know what plugin you found that lets you change region ids, but causes loading issues. I probably should have asked for that before I spent the time coming up with the above.
 
Last edited:

JLowther

Veteran
Veteran
Joined
Feb 20, 2016
Messages
327
Reaction score
40
First Language
English
Primarily Uses
Shaz_ConvertTerrainToRegion.js
Shaz.... Please tell me you didn't just write me a plugin or heavily modify an existing one. D:

It works like a charm, and apologies for not answering the other questions but I was posting in the moments before bed/work. I was using Hikitsune-Red's "Set Region ID" plugin which can't batch alter region IDs like your plugin does.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,789
Reaction score
15,915
First Language
English
Primarily Uses
RMMV
lol - sure I did, because it was a small and fairly easy one, and I already had some experience with the various components.

Glad it works, and hope it's nice and fast and doesn't cause any loading delays.

If this is solved, just report your first post and ask for the mods to close the thread :)
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
9,832
Reaction score
6,253
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

Spend $5,000 on a new gaming PC. Didn't expect it to be like 1 foot wide, 2 feet tall, and weigh like 100+ pounds. The heck did I get myself into?
If you are a fan of TRPGs like Fire Emblem, take a moment to help me by filling out this:

Camping inside a hidden cave.
LzSHByh.jpg
I don’t believe in astrology. I’m a Sagittarius and we’re skeptical.

Forum statistics

Threads
124,377
Messages
1,163,203
Members
163,176
Latest member
HiKKIkMori
Top