Page 1 of 1

Lock a Level Behind Achievements

Posted: Sun Jan 22, 2023 8:43 pm
by MarioChallengerX2
Is it possible to lock a level behind achievements?

And I don't mean like collecting all the achievements in an episode, I mean like specific achievements.

For example: Like, find all secret exits in the game achievement, unlocks a secret level or set of levels.

Re: Lock a Level Behind Achievements

Posted: Mon Jan 23, 2023 2:59 am
by Emral
Achievements aren't contained to a single save file, so keep that in mind.

The answer is yes, but it does require some lua. I'm assuming you have a "collect all secret exits" achievement set up and working. It may be called "AllSecretExits" and be bound to SaveData.secretExitsCollected >= 100 being true in one of the save files.

Using this information you'll need a way to lock off the level. This would be easiest to do by having a "gate" level file, which presents the player a simple impassable wall with an exit on the other side. If the achievement is obtained, the wall disappears and the player can collect the exit, opening a new path on the world map or bringing their star counter to a value required for opening a door in a hub.
Then in the onStart of the luna.lua, you can do this:

if SaveData.secretExitsCollected > 100 then
triggerEvent("hideTheBarrier")
end

This will trigger an event called hideTheBarrier, which you can use to get rid of the wall for those who have managed to get the achievement.
You can optionally replace the if-condition with "if Achievements.get("AllSecretExits").collected then", to make it save file independent.

There are other ways to make this work without a gate level, but they are more complicated in the code that is inside the if statement. The part of binding it to the achievement won't change to the lines above though.
Since the variable names are assumptions for the sake of example, make sure to think of them with your own variable names.