Enemy Spawner in Overworld

So, i wanted to try out making the enemies spawn in the overworld during exploration in the dungeon, similar to the persona games, where you explore the dungeon, and the Shadows (In this case, the enemies) Randomly spawn in certain places of the dungeon
Is there a way for me to do that? Since i know how to make the npcs to use as the event, but not the spawner itself
Depends on what exactly you want to achieve.

It can be done with events alone (you'll need one master event that activates or deactivates placeholder events and do the randomizing), but for anything more complicated you're better off using a clone event script to give you the required functions.
Basically what i want to do, is spawn enemies in random places in the dungeon floors, but with a fixed encounter, just if the player wants to grind for exp
If you'd like to go the eventing way, you could have several events on the map which only appear when a variable is of a certain value, either in a set order (increasing the value after each battle), or if you want real randomization, with the master event Andar mentioned that will assign a value randomly. That's what I would do, because my maps are rather small, but if you have big ones, a script is probably better. I haven't used the clone event one mentioned above, but I used this one before, and it sounds like it could work for you.
I think im just stupid, but i don't know what a Master Event exactly is, i know only a Common event, lol

But like, what i wanted to do, is that some of the enemies are respawned after a fight in the floor
This will only work if you don't use self switches for anything but this.

Make an event with 3 pages. Page one will be an autorun event. In the event make a variable mobChance and set it to a random 1-3 (or whatever you want. The bigger the second number, the lower chance that this enemy will spawn. So 1-3 will be a 1 in 3 chance, 1-10 will be a 1 in 10 chance). Then make a conditional branch that will be if mobChance = 1 then turn on self switch A, Else turn on self switch B.

On the 2nd page of the event set the condition of the event to self switch B - leave the page blank.

On the 3rd page of the event set the condition of the event to self switch A. In here you will add all the stuff for your encounter including the graphic.

Now just copy and paste this event anywhere in your dungeon you want to have a chance to have a monster spawn


Now, enemies won't respawn until you run a script that has
$gameSelfSwitches.clear();

So if you want the enemies to respawn after leaving a map, just have that script in there. Or if for example, you want a dungeon with multiple maps, and only want the monsters to reset after you leave the entire dungeon, then don't run that script until you leave the entire dungeon.


A version of this same concept you can use if you do use self switches for other things.

Just have an event autorun when you enter that rolls the mobChance variable. Then in the events of the mobs themselves you make some have the condition mobChance = 1, another with mobChance = 2, etc. Does the same thing, but is more tedious and is reset when you leave a map.
This will only work if you don't use self switches for anything but this.

Make an event with 3 pages. Page one will be an autorun event. In the event make a variable mobChance and set it to a random 1-3 (or whatever you want. The bigger the second number, the lower chance that this enemy will spawn. So 1-3 will be a 1 in 3 chance, 1-10 will be a 1 in 10 chance). Then make a conditional branch that will be if mobChance = 1 then turn on self switch A, Else turn on self switch B.

On the 2nd page of the event set the condition of the event to self switch B - leave the page blank.

On the 3rd page of the event set the condition of the event to self switch A. In here you will add all the stuff for your encounter including the graphic.

Now just copy and paste this event anywhere in your dungeon you want to have a chance to have a monster spawn


Now, enemies won't respawn until you run a script that has
$gameSelfSwitches.clear();

So if you want the enemies to respawn after leaving a map, just have that script in there. Or if for example, you want a dungeon with multiple maps, and only want the monsters to reset after you leave the entire dungeon, then don't run that script until you leave the entire dungeon.


A version of this same concept you can use if you do use self switches for other things.

Just have an event autorun when you enter that rolls the mobChance variable. Then in the events of the mobs themselves you make some have the condition mobChance = 1, another with mobChance = 2, etc. Does the same thing, but is more tedious and is reset when you leave a map.
For the enemies respawning after a battle, could i just make that after the battle, the self switches are turned off? Cause the Random Spawning part works, but im bad as using scripts, so idk how to use the Script that u had in the response

Also, when u said that it will only work if i use no self switches, do u mean in the map, or in the game in general? Cause i used Self Switches for Autorun Cutscene events
Perhaps this experimental script could help you make the enemies spawn automatically.

Ruby:
# * Event Spawner ACE - Experimental
#   Scripter : Kyonides Arkanthes
#   2023-04-21

# * Script Calls for Event Commands * #

# Instead of setting the event's self switch manually, use this call:

# event_respawn(Frames, "SelfSwitch")
# event_respawn(Frames, "SelfSwitch", EventID)

class Game_Event
  alias :kyon_event_spawner_gm_evnt_up :update
  def update_respawn_page
    @respawn = nil
    key = [$game_map.map_id, @id, @respawn_self_switch]
    $game_self_switches.delete(key)
    refresh
  end

  def update
    if @respawn
      @respawn_counter -= 1
      update_respawn_page if @respawn_counter == 0
    end
    kyon_event_spawner_gm_evnt_up
  end

  def setup_respawn(char, frames)
    @respawn = true
    @respawn_self_switch = char
    @respawn_counter = frames
  end
  attr_accessor :respawn
end

class Game_Interpreter
  def event_respawn(frames, self_switch, rsp_event_id=0)
    rsp_event_id = @event_id if rsp_event_id == 0
    event = $game_map.events[rsp_event_id]
    event.setup_respawn(self_switch, frames)
    key = [$game_map.map_id, rsp_event_id, char]
    $game_self_switches[key] = true
  end
end
Perhaps this experimental script could help you make the enemies spawn automatically.

Ruby:
# * Event Spawner ACE - Experimental
#   Scripter : Kyonides Arkanthes
#   2023-04-21

# * Script Calls for Event Commands * #

# Instead of setting the event's self switch manually, use this call:

# event_respawn(Frames, "SelfSwitch")
# event_respawn(Frames, "SelfSwitch", EventID)

class Game_Event
  alias :kyon_event_spawner_gm_evnt_up :update
  def update_respawn_page
    @respawn = nil
    key = [$game_map.map_id, @id, @respawn_self_switch]
    $game_self_switches.delete(key)
    refresh
  end

  def update
    if @respawn
      @respawn_counter -= 1
      update_respawn_page if @respawn_counter == 0
    end
    kyon_event_spawner_gm_evnt_up
  end

  def setup_respawn(char, frames)
    @respawn = true
    @respawn_self_switch = char
    @respawn_counter = frames
  end
  attr_accessor :respawn
end

class Game_Interpreter
  def event_respawn(frames, self_switch, rsp_event_id=0)
    rsp_event_id = @event_id if rsp_event_id == 0
    event = $game_map.events[rsp_event_id]
    event.setup_respawn(self_switch, frames)
    key = [$game_map.map_id, rsp_event_id, char]
    $game_self_switches[key] = true
  end
end
I'm sorry, but i still don't know how to properly use scripts..
For the enemies respawning after a battle, could i just make that after the battle, the self switches are turned off? Cause the Random Spawning part works, but im bad as using scripts, so idk how to use the Script that u had in the response

Also, when u said that it will only work if i use no self switches, do u mean in the map, or in the game in general? Cause i used Self Switches for Autorun Cutscene events
Just use the 2nd way then. Takes a little longer, but will still work. You won't be able to "just turn off self switches" because that will reset the event.

So you'll want to have 1 event autorun when you enter that rolls the mobChance variable (this is your master monster roll chance) for this example, have it roll 1-5. This has to be specific to the area for this to work, so rename it for each area. For example if your map is called Den of evil, name it mobChanceDOE1 then for the next map in the same dungeon have it called mobChanceDOE2 or something like that.

Then in the events of the mobs themselves you will make 2 pages. Page 1 will be a blank page with nothing on it. The second page will be an autorun event that will have the condition to run be mobChanceDOE1 (or whatever map you are on that your master monster roll chance happened in). In this case we rolled 1-5. So have 1/5th of the events have the condition mobChanceDOE1 = 1, another 1/5th with mobChanceDOE1 = 2, etc. This will make it so that when the master spawner rolls, each event will have a 1 in 5 chance of running. In this 2nd page you will have all the events for your monster, just make sure that when the battle is over you use the erase event command.

Now for this, each time you enter the map the mobs would reset. So using no scripting the only way to keep them defeated would be to make 4 pages and way more switches. Have the 1st page the same, then on the 2nd page you will instead keep the mobChanceDOE1 = X condition, but in the events you will make it turn on a switch for just that event. So for this event name the switch DOE1_mob1 or something. Then on the 3rd page you will have all your events for your monster itself, with the condition to be DOE1_mob1 is true. Then on the events make a new switch only for when the mob is defeated called DOE1_mob1Dead and make the 4th page blank with that switch as the condition.

Now the enemies you defeat won't respawn when you leave. If you want them to respawn you'll have an event that just sets all the mobDead switches to false and they will respawn. So say you leave the dungeon, on the exit event just have all the switches turn off. There are probably some problems with this whole thing, but in my head it worked out, the basics should work, just go off the idea.

That's the only way I can think of getting it to work with events only, scripting makes this kind of thing much easier. It's doable, but lots of switches and variables in events is time consuming lol.
I'm sorry, but i still don't know how to properly use scripts..
Read through the tutorial from the link in my signature block on how to use scripts
here
↓

Original thread: https://forums.rpgmakerweb.com/threads/enemy-spawner-in-overworld.156735/