Door that opens after all enemies of a type are defeated

Started by Hibiro, May 02, 2018, 04:43:15 AM

Previous topic - Next topic
I can understand how the miniboss method works, but I can't figure out, nor find an example, of how to make it so a door will only open after you defeat all enemies of a particular name group.

The perfect example would be in Maku Path in Oracle of Ages. In the room where you have to defeat the 3 gels to open the doors again.

I may just be looking for it in the wrong places, or not understanding something, but any help here would be greatly appreciated.

For reference, I'm using the majority of what's in the main Solarus DX project, learning from the scripts as I go through. (This is due to the fact I don't absorb information well if I just go off of reading. It retains better when I learn it as I need to use it.)

So, I've seen that there is a "Door Manager" script in a few of the Solarus Team's projects, which seems to help with this instance as well as a few other things you might want to do with doors- I've tried it and it works great once you figure out what you're supposed to do to use it! However, I don't 100% understand everything in that code, so I don't like using it. Maybe once I'm smart enough to re-code it myself to understand it I will, but until then I'm stubbornly doing things poorly so I can learn.

So, one way I've achieved this effect is by having an event for every enemy that, when they're killed, checking if there aren't any other enemies left and if so, opening the door (or whatever). I know for a fact that this is not very good code, and it's repetitive and hard-codes the number of enemies, but it might be a good starting point for you to try to understand some of the code that you'll need.

Code (lua) Select

function mushroom_golem_1:on_dead()
  if map:get_entities_count("mushroom_golem") == 0 then --)this line counts the number of entities that are named starting with "mushroom_golem...")

function mushroom_golem_2:on_dead()
  if map:get_entities_count("mushroom_golem") == 0 then

--and so on, with function mushroom_golem_3:on_dead(), mushroom_golem_4, etc...

Well, that certainly works for now, thanks!
I never noticed this Door Manager script, though. Which projects did they have it in?

There is a similar question and even a solution in this topic: "A chest created when all the enemies are killed"
It is for chests, but it should be not too difficult to adapt for doors.

Thanks so much for that, Froggy! It does work perfectly after I convert it to work with doors! Less lines of code than the other method, too.


Do you mind posting your final script? I'm just having trouble combining the door reference with the chest mechanic?