Author Topic: Door that opens after all enemies of a type are defeated  (Read 194 times)

Hibiro

  • Newbie
  • *
  • Posts: 4
    • View Profile
Door that opens after all enemies of a type are defeated
« on: May 02, 2018, 04:43:15 am »
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.)

Max

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Door that opens after all enemies of a type are defeated
« Reply #1 on: May 02, 2018, 06:00:53 pm »
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
  1. function mushroom_golem_1:on_dead()
  2.   if map:get_entities_count("mushroom_golem") == 0 then --)this line counts the number of entities that are named starting with "mushroom_golem...")
  3.     game:start_dialog("_yarrowmouth.observations.mushroom_spot.1")
  4.     map:open_doors("gate")
  5.   end
  6. end
  7.  
  8. function mushroom_golem_2:on_dead()
  9.   if map:get_entities_count("mushroom_golem") == 0 then
  10.     game:start_dialog("_yarrowmouth.observations.mushroom_spot.1")
  11.     map:open_doors("gate")
  12.   end
  13. end
  14.  
  15. --and so on, with function mushroom_golem_3:on_dead(), mushroom_golem_4, etc...
  16.  
« Last Edit: May 02, 2018, 06:03:21 pm by Max »

Hibiro

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Door that opens after all enemies of a type are defeated
« Reply #2 on: May 02, 2018, 07:38:02 pm »
Well, that certainly works for now, thanks!
I never noticed this Door Manager script, though. Which projects did they have it in?

froggy77

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Door that opens after all enemies of a type are defeated
« Reply #3 on: May 02, 2018, 11:11:15 pm »
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.

Hibiro

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Door that opens after all enemies of a type are defeated
« Reply #4 on: May 02, 2018, 11:18:28 pm »
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.