Randomize Event Placement based on Region

Made for a request here.

This script simply randomize the events position in the map with a name tag based on region.

Features:

Randomize Event Position(Placement)

How to Use:

[1] Paste the script below Material and above Main

[2] Set up the region number you wish to use in the setting area in the script

[3] Put <randomize> in the event's name you wish to randomly positioned

Compatibility:

This script is using alias method, if you find it not working, simply place it below other custom script you have

Terms of Use:

Free for both Commercial and Non-Commercial

Script:

Spoiler
Code:
#==============================================================================# ■ Meow Face Randomize Events Placement by Region ID#------------------------------------------------------------------------------# Randomize events in map and place them on region X#==============================================================================# How to Use:# [1] Put this script below Material and above Main# [2] Put <randomize> in event's name you wish to randomize# [3] Set up Region number in the settings area#==============================================================================module MEOWREVENT #Do Not Remove!#==============================================================================# Settings Area#==============================================================================  REGION = 2 #Region number you wish to use#==============================================================================# End of Settings Area# Edit anything past this line at your own risk!#==============================================================================endclass Game_Event < Game_Character  alias meowreinitialize initialize  def initialize(map_id, event)    meowreinitialize(map_id, event)    if @event.name.include?('<randomize>')      position = []      x_pos = 0      y_pos = 0      $game_map.width.times do        x_pos = 0        y_pos += 1        $game_map.height.times do          x_pos += 1          position << [x_pos, y_pos] if $game_map.region_id(x_pos, y_pos) == MEOWREVENT::REGION        end      end      unless position.empty?        loop do          pos = position[rand(position.size)]          if $game_map.events_xy(pos[0], pos[1]).empty?            moveto(pos[0], pos[1])            break          end        end      end    end  endend
Fixed script format, credit Meow Face.

For some reason, it randomizes event- not where region X is. I don't get why
Edit: Thanks Roninator2 for explanation, script corrected

Code:
#==============================================================================
# ■ Meow Face Randomize Events Placement by Region ID
#------------------------------------------------------------------------------
# Randomize events in map and place them on region X
#==============================================================================
# How to Use:
# [1] Put this script below Material and above Main
# [2] Put <randomize> in event's name you wish to randomize
# [3] Set up Region number in the settings area
#==============================================================================
module MEOWREVENT #Do Not Remove!
#==============================================================================
# Settings Area
#==============================================================================
  REGION = 2 #Region number you wish to use
#==============================================================================
# End of Settings Area
# Edit anything past this line at your own risk!
#==============================================================================
end
class Game_Event < Game_Character
alias meowreinitialize initialize
def initialize(map_id, event)
meowreinitialize(map_id, event)
if @event.name.include?('<randomize>')
position = []
  x_pos = 0
  y_pos = 0
$game_map.width.times do
  x_pos = 0
  y_pos += 1
$game_map.height.times do
  x_pos += 1
  position << [x_pos, y_pos] if $game_map.region_id(x_pos, y_pos) == MEOWREVENT:: REGION
end
end
unless position.empty?
  loop do
  pos = position[rand(position.size)]
  if $game_map.events_xy(pos[0], pos[1]).empty?
  moveto(pos[0], pos[1])
break
end
end
end
end
end
end
not where region X is. I don't get why
You put the if statement on a new line and added an extra end. at the bottom
position << [x_pos, y_pos] if $game_map.region_id(x_pos, y_pos) == MEOWREVENT:: REGION
@Roninator2 Thank you for the explanation!

Original thread: https://forums.rpgmakerweb.com/threads/randomize-event-placement-based-on-region.49983/