Set self switches for many NPCs on a map at once

Here's what I want to do: have monsters visible on the map that create fights when you walk into them. When you beat them they disappear. Certain factors will make all the monsters on a given map disappear or reappear, for instance if the player uses an item or spell that kills all the monsters at once, or flips a switch that revives all the monsters on that map.

It's important that this be map-specific. If the player chooses to wipe out all the monsters on floor 9 of a dungeon, I don't want floors 10-20 to be empty too. By the same token if the player revives everything on floor 9 because they want to farm up an item, I don't want every monster in the world to come back to life.

Here is how I would like to tackle the problem:

Every monster event has the same prefix on their name, like MONSTER or MNST. Every event has a page activated by a self switch (say, D) in which they are defeated and invisible. This switch could normally be flipped by walking up and killing them.

A script, when called, should grab the player's current Map ID and compile a list of events on that map which have MONSTER as their prefix. It should then iterate through the list and change their self switches individually. The script call would have to provide true or false to determine whether the script activates or deactivates all the switches.

I have a fair bit of programming experience but not a lot in Ruby or RPG Maker, so I don't know how to do a couple of things. How do I get the map ID of the map the player is currently on? How do I get a list of all the entities on that map, and then get their names?

Finally, I have considered using "erase event" instead of self switches, but as far as I know that would make it much more difficult to revive monsters without leaving the map.

Thanks for your time!
I cobbled something together referencing Prof's Trace System. I think it works but I'm not confident about it. Worried I'm going to break something terribly.

Here's what I've got. I apologise for the poor commenting.

Code:
class Game_Event < Game_Character  #----------------------------------------------------------------------------  # Name (get name)  #----------------------------------------------------------------------------  def name    return @event.name  endendclass Game_Interpreter  def set_monsters(state)     for i in $game_map.events.keys          event = $game_map.events[i]          if event.name.include?("MNSTR") and !event.erased             event.set_self_switch('D', state)          end    end  endend  #----------------------------------------------------------------------------  # Set Self Switch  #----------------------------------------------------------------------------  def set_self_switch(switch,true_false)    key = [@map_id, @id, switch]    $game_self_switches[key] = true_false    $game_map.need_refresh = true  end
Can you help me understand this a bit better?

Can you not just use self switches and regular switches, without any special scripting?

I mean, the events already "know" what page they are on.

And the events are only "active" when the player is on the same page, right?

So is the problem that you do  not want a single "revive monster" switch which will revive monsters on all maps?

And you want to have it know which map you are on to know which switch to throw for just this map?

When will you throw the switch? I guess that is the crux of it. From your items menu?
You are correct, I don't want to use a universal switch because I don't want to revive/kill all monsters in the world at once, just ones on the specific map the player is currently on.

I would like to call a script either from an event (i.e. the player can interact with an object in a dungeon), an out-of-combat skill or an out-of-combat item. I think I can accomplish this by just making a script call from the event / skill / item? If I had to pick only one, then an item.
OKay, well idk much about scripting, honestly, so I am always looking for an eventing solution, and maybe that is a good thing sometimes, and maybe sometimes it misses the point.

But if you use region ids for the map/area you are on, you can have a common event called by the item you use to set a variable to the region ID, and then have the monsters revive if that variable equals the region ID of their area.

Then after they revive, reset the variable to zero.

Or, whenever you enter a map, you could just set the variable to a number corresponding to a map with a certain group of monsters. So on the "Dungeon of Death Monsters" would be map 1. Set the variable to 1. When you want the group of those monsters to be revived, throw the REVIVE! switch and have a conditional page based on the REVIVE switch and the variable equalling 1. After they revive, reset the REVIVE! switch.

I probably forgot a step. (Hubby is being distracting!!!) But you get the idea.....

*****EDIT*****

I'd like to apologize - I did not realize this was the scripting section. Sorry to barge in. =/
Darien Shields, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


What you have should work, as long as it's called ON the current map (if you do a transfer to another map and then call it as part of the same event, it'll affect the monsters on the NEW map, not the one you're just leaving).


You don't need the $game_map.need_refresh = true line - that's already done by Game_SelfSwitches.
Thanks!

If there are two scripts that have the Game_Event // def name bit would that be problematic?
If you have two scripts that define the same method for the same class, and neither of them are aliasing the method, then the first one will be ignored and the last one will be used.


So if they're both exactly the same, it won't matter. If there's a difference between them, it will.
Only if they do different things.

Original thread: https://forums.rpgmakerweb.com/threads/set-self-switches-for-many-npcs-on-a-map-at-once.16513/