In my game enemies are encountered as events on the overworld, and when they're defeated a self-switch triggers to a blank event so that they disappear.
I'm trying to make a common event that works like a Bonfire from Dark Souls, in that it will heal the player and then "respawn" all the defeated enemies. Ideally, it would reset all defeated enemy events regardless of which map they are on.
I've been trying several different things involving common events, switches, and making multiple event pages on the enemy events, but I haven't been able to figure out a solution that works how I would like it to.
I'd like to know if anyone has come up with a similar system and how they got it to work because I'm at a dead end working on it right now. Thank you and much appreciated.
if a player leaves the map, do the enemies have to remain defeated if they return without having rested?
I was thinking an easy way to do it would be using the delete event command instead of a self switch and then having your bonfires transfer the player elsewhere and back to refresh the enemies, but doing that would cause them to respawn on any transfer.
If the main event would have a switch as a condition, turning it off and on should theoreticly do the trick. The switch can be the same for all enemies, or different ones for specific areas, depending on your preference.
If it will not work, try to use script that remotly unplugs self-switches.
I think it's
$gameSelfSwitches.setValue([map, event, selfswitch], value)
But if not people will correct me. Don't use first two 00 in map id, it should start with non-zero number.
Value is true or false
So you basically want to toggle a whole load of self switches at once? The script call for self switches looks like this:
// Turn off self-switch A for event 5 on map 1:
$gameSelfSwitches.setValue([1, 5, 'A'], false);
So, you could have your bonfire event trigger a common event which toggles all the self switches you want it to. Of course, this would get pretty unwieldy once you have a lot of enemies. You can make it a little neater by looping through only the events you want to turn off.
If this is the only place you're using self switches in your game, you can use
$gameSelfSwitches.clear();
to turn off all self switches at once.
To set up a loop, the best way is probably to store the enemy map and id in a variable, then read that variable to know which ones to turn on again. So, have a variable that's a list/array, and when your enemy dies it should add its map and id onto it.
Something like this; at the start of your game, set a variable to an empty string.
Control Variables : #0020 EnemyList = []
When your enemy dies, have it add its event and map id on the end before turning on its self switch to vanish:
Script: $gameVariables.value(20).push([$gameMap.mapId(),this.eventId()])
Then have your bonfire run some script to loop over every array that was added to your list variable, and then clear it out:
Script:
for (var enemy of $gameVariables.value(20)) {
$gameSelfSwitches.setValue([enemy[0], enemy[1], 'A'], false);
};
$gameVariables.setValue(20, []);
So if I'm understanding what you are saying correctly, I can have enemies add their map/event id into a variable when they die, plug that variable into the loop, and have the script unplug the self-switch for all those enemies in the loop?
If so I think that's probably the solution I'm looking for, since I'd like to have a lot of enemies, and to be able to use self-switches for other things.
EDIT: Thank you for those scripts, they worked like a charm. I spent too much time struggling to get it to work until I realized I had the event that set the list variable to an empty array on parallel which kept resetting the array and making the whole thing nonfunctional >.<
Once I got over that dumb mistake it worked perfect like you said, with the feature of working across all maps like I was hoping for. Additionally, I realized that this could be used for all sorts of things besides enemies, so that's great. Looking forward to using this 😀