MV Event Placement on Random Tile w/ Specific Region ID

Hi,

I'm looking for a plugin that upon map load: places a current map's event with an event notetag to a random tile with specific region ID. Should not be placed on a tile with an event already.

e.g. NPC event with <Region: 22> notetag would be randomly placed onto a tile with region 22. This could be used for random chest or enemy placement.

I've mostly seen spawn plugins which creates a new event, which isn't what I'm looking for. It's repositioning an existing event.


Thank you.
I've mostly seen spawn plugins which creates a new event, which isn't what I'm looking for. It's repositioning an existing event.
you might want to check those plugins again, because they rarely create new events.
they usually clone events from elsewhere (often from a master map), because creating an event by script is one hell of a lot of work.

and if the difference is only where said master event to be copied is placed, it should not be much of a problem to reorganise those events to the mastermap.
If you want a script call to do the heavy lifting, try a Parallel event like this:

◆Comment:Randomly teleport all events on this map : :with a <Teleport> tag in their notebox. ◆Script:var r = [1, 2, 3]; // valid teleport region IDs : :var w = $dataMap.width, h = $dataMap.height; : :var t = []; : :for (var x = 0; x < w; x++) : : for (var y = 0; y < h; y++) : : if (r.contains($gameMap.regionId(x, y))) : : t.push({ x: x, y: y }); : :$gameMap.events().forEach(function(e) { : : if (t.length && e.event().meta.Teleport) { : : var T = t.splice(Math.randomInt(t.length), 1)[0]; : : e.locate(T.x, T.y); : :}}); ◆Comment:Disable this event until the player leaves and comes back. ◆Erase Event
Spoiler: Easy-copy version of script call
JavaScript:
var r = [1, 2, 3];  // valid teleport region IDs
var w = $dataMap.width, h = $dataMap.height;
var t = [];
for (var x = 0; x < w; x++)
  for (var y = 0; y < h; y++)
    if (r.contains($gameMap.regionId(x, y)))
      t.push({ x: x, y: y });
$gameMap.events().forEach(function(e) {
  if (t.length && e.event().meta.Teleport) {
    var T = t.splice(Math.randomInt(t.length), 1)[0];
    e.locate(T.x, T.y);
}});
As-is, this'll scan the map for region IDs 1, 2, or 3 (edit the first line to change these IDs) then randomly teleport any event with a <Teleport> tag in their notebox to a random one of those tiles. It should also prevent multiple events from being placed in the same location.
@Andar: Yes, should be "clone" than "create". I'm using an event label plugin that reads comments to show labels, but won't work for randomly placed cloned events made through spawn plugins (Galv's, Orange's, Yanfly's). Only on current map originals.

@cae: Thank you, that setup would work. Is it possible to use event notetag like <Teleport: 22, 23, 24> and parse the numbers into a teleportable region ID array? I wish that different objects on the same map can teleport to certain regions only. Example: cat npcs teleport only on regions 22, 23, 24 and dog npcs teleport only on region 5.
but won't work for randomly placed cloned events made through spawn plugins. Only on current map originals.
Then that plugin most likely reads the comments on map load, at which time the cloned events not yet exist.
one solution would be to have a manual command to refresh the label data, either directly or from a compatibility patch depending on how the label plugin works.

keep that option as a second in case the other solution has problems.
@cae: Thank you, that setup would work. Is it possible to use event notetag like <Teleport: 22, 23, 24> and parse the numbers into a teleportable region ID array? I wish that different objects on the same map can teleport to certain regions only. Example: cat npcs teleport only on regions 22, 23, 24 and dog npcs teleport only on region 5.
Possible, yes. It's more complicated because you need separate tile pools for each combination.

Consider using multiple notetags, e.g. <TeleportCat>, <TeleportDog>, etc. Then you can have one Script command for each tag name:
  • Replace the region list on this line (e.g. [1, 2, 3] -> [5]):
    JavaScript:
    var r = [1, 2, 3];  // valid teleport region IDs
  • Replace the tag name (e.g. Teleport -> TeleportDog) on this line:
    JavaScript:
      if (t.length && e.event().meta.Teleport) {
If you use this approach and want to use the same region ID for more than one "type" of event then I also recommend changing this line:
JavaScript:
      t.push({ x: x, y: y });
...to something like this:
JavaScript:
      if (!$gamePlayer.isCollidedWithCharacters(x, y)) t.push({ x: x, y: y });
I.e. only add a tile to the pool if there's no collidable event there~

Also, I suggest you put the Script commands in a common event and just call that common event from the Parallel map events. 👋
@Andar: Yes, should be "clone" than "create". I'm using an event label plugin that reads comments to show labels, but won't work for randomly placed cloned events made through spawn plugins (Galv's, Orange's, Yanfly's). Only on current map originals.

@cae: Thank you, that setup would work. Is it possible to use event notetag like <Teleport: 22, 23, 24> and parse the numbers into a teleportable region ID array? I wish that different objects on the same map can teleport to certain regions only. Example: cat npcs teleport only on regions 22, 23, 24 and dog npcs teleport only on region 5.
I think I may have run into a similar issue recently between Yanfly's MiniLabel plugin and Yanfly's Event Copier plugin. I was gettin an error after calling a script to copy an event then trying to transfer to another map. I wasn't able to find a solution so I'll definitely be giving this a shot!

@caethyril Thank you!
@ cae: I thought about possibly doing that before asking about parsing. I don't mind that as there's not that many different types of events with different region pools. I will give it a thorough go. Also, thanks for the common event tip! Almost forget about that to save time!

@Andar: I believe MOG_EventIndicator that I'm using does read comments and notetags on map load, and I may have tried the wrong way to manual refresh before for a solution.

@ThreeSixNine: Good luck. I had no problem with Yanfly's MiniLabel plugin for achieving for what I want to do here with Galv's spawn plugin. Except that there's a incompatibility with one of my other plugins. Thus, I had to swap Yanfly's out for MOG's, which doesn't read Galv's spawns. Possibly Yanfly's plugin loads after Galv's spawns.


UPDATE: Tested the script, and so far works exactly as it should! caethyril did an fast and excellent job!

Original thread: https://forums.rpgmakerweb.com/threads/event-placement-on-random-tile-w-specific-region-id.138211/