Need help with puzzle

Hello everyone!

I have been having trouble trying to figure out how to do a puzzle for a dungeon in my game.

The player encounters a dragon guarding a door.
Spoiler: Show Image
Puzzle1.png
The dragon won't allow player to pass through door, unless the player bring 5 sacrifices to it.
Spoiler: Show Image
Puzzle6.png
Puzzle7.png
The player then has to lure the monsters in front of dragon.
Spoiler: Show Image
Puzzle3.png
One the monster is in front of dragon, the dragon will consume it.
Spoiler: Show Image
Puzzle2.png
Puzzle4.png
Once the dragon has consumed 5 monsters, the door will open.
Spoiler: Show Image
Puzzle5.png

Can someone explain to me, how I would make a puzzle like this?

Thank you 🙂
The short answer is: increase a variable each time a monster is consumed and then use a conditional branch to check that variable. If its value is 5 then move your door and increase the variable again (it is equal to 6 now). Have a second page in your door thad does not display any graphics but still transfers the player and set "your variable greater than or equal to 6" as a condition for that page.

That was the short answer. The long one depends on what the player has to do to lure an enemy there so I cannot really give you a more detailed answer.
Yeah we're gonna need more detail, because there are so many ways to pull that off, but coming up with a fun, creative and whenever possible, unique way is what matters most.

How @Heirukichi described is likely going to be part of what you do no matter what.

Tell us how you see it playing out as the Player, and it will be easier to help describe how to go about eventing it.
@Heirukichi
I was thinking of doing it like this:
Once the player gets close enough to the enemy, the enemy will start following them. The enemy will stop following if the player get too far away.
So basically you need something to calculate proximity. One possible way to do this is to have a second page on each enemy event with autonomous movement that follows the player. The trigger for that second page would be self switch A on.

Once you set up this you need something that actually turns that switch on when needed. This can be done using a parallel process event. Just have a parallel process event in either your map or your common events and put the following in it.
Code:
following_enemies = [id1, id2, id3, id4]
following_enemies.each do |id|
  ev = $game_map.events[id]
  prox = ($game_player.x - ev.x).abs + ($game_player.y - ev.y).abs
  $game_self_switches[[$game_map.map_id, id, 'A']] = ((prox < certain_distance) ? true : false)
end
Change id1, id2, id3, id4 with the id of your movable events (you can add new ones separating them with commas, add as many as you want) and change certain_distance to be the actual distance (in squares) at which one event starts following the player.

DO NOT CHANGE anything else, not even id. Just change those ids inside "following_enemies" and that certain_distance.
At the end of this event you should put a wait command so that it does not run every frame. The player will unlikely occupy a new position each frame.
@Heirukichi
Could you post a screenshot to show me what you mean? I'm a little confused on how to set it up.
Here is a screenshot that shows you all the important parts of your monster event.
Spoiler: Image here
EventID.png
As you can see my event ID is 1. Now let's assume that in my map I have event from 1 to 5 acting as those monsters. I then decide that events should start moving once the player enters a range of 2 tiles (that can be any combination of 2 tiles: horizontal, vertical, horizontal + vertical, etc). The script call to the common event would look like this:
Code:
following_enemies = [1, 2, 3, 4, 5]
following_enemies.each do |id|
  ev = $game_map.events[id]
  prox = ($game_player.x - ev.x).abs + ($game_player.y - ev.y).abs
  $game_self_switches[[$game_map.map_id, id, 'A']] = ((prox < 3) ? true : false)
end

as you can see the array contains my events ID (1, 2, 3, 4, 5) while I changed certain_distance to 3 because when it is less than 3 (which means 2) events start chasing the player.
@Heirukichi
Okay the monsters are following me now. 🙂
I know I have to use variables to keep track of how many monsters the dragon has to consume, but how do I make it so that when the monster is in front of dragon, the dragon will breath fire on it and the monster disappears?
Spoiler: Example of what I mean
index.php
index.php
index.php
You can check that in the same common event you use to let events start following the player. Check if there is an event in front of your dragon and if there is turn a self switch B on. Then set up your event so that your 3rd page (a new one) has "Self switch B is ON" as trigger condition. That 3rd page can be an autorun event or anything else. If you want to display the flame animation I'd recommend using an autorun event so that you can actually put commands there.

In the following example I am still using 1, 2, 3, 4 and 5 as event IDs and 3 as minimum distance to not trigger events. My dragon event (in the following example) is Event 6 (so its ID is 6). Change it to be your actual dragon event id.
Spoiler: How your script call would look like including the position check for sacrifices
Code:
following_enemies = [1, 2, 3, 4, 5]
dragon = $game_map.events[6] # change this
following_enemies.each do |id|
  ev = $game_map.events[id]
  prox = ($game_player.x - ev.x).abs + ($game_player.y - ev.y).abs
  $game_self_switches[[$game_map.map_id, id, 'B']] = ((dragon.x == ev.x) && ((ev.y - dragon.y) == 1))
  $game_self_switches[[$game_map.map_id, id, 'A']] = ((prox < 3) ? true : false)
end

In the example I am calculating is the event is BELOW the dragon (that means same x coordinate and a difference of 1 in y coordinate). I picked that one because in your screenshot the dragon is up while the event disappear upon walking in the square right below it. If you decide to move the relative position for the sacrifice then you have to change that accordingly.

Spoiler: Note 1: events cannot step on squares with other events.
For this reason after your event animation ends do not forget to either move your event somewhere else after triggering a blank page with the "Through" condition checked (using a self switch would be ideal) or erase it using "Erase Event". The first option means that leaving the room and entering it again will have no impact on the number of events, the second option means you reset your event to its last active page (the one used to trigger the sacrifice) upon entering the room again. Keep in mind that using erase event might lead to complications such as
  • having to reset your counter variable;
  • having to reset all your self switches.
Spoiler: Note 2: moving events are tricky
An event that is moving to a square is already considered to be on that square. This means two things: 1) if you do not time things properly the 3rd page triggers during movement, 2) if your timing is off you might start your sacrifice animation when the event is still moving.
To prevent such things just start your 3rd page autorun event (I am saying autorun because it is the best way in my opinion) with this code:
Code:
Fiber.yield while $game_map.events[@event_id].moving?
This prevents the engine from running everything that follows that command until the event stops its movement.
@Heirukichi
I apologise for the late reply. I've been busy this week.
Thank you for helping me. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-puzzle.106141/