Lock a Level Behind Achievements

Need help with any SMBX game-related issues? Ask your questions here.

Moderator: Userbase Moderators

MarioChallengerX2
Dolphin
Dolphin
Posts: 88
Joined: Sat Dec 31, 2022 4:34 pm
Pronouns: he/him

Lock a Level Behind Achievements

Postby MarioChallengerX2 » Sun Jan 22, 2023 8:43 pm

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.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9860
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Lock a Level Behind Achievements

Postby Emral » Mon Jan 23, 2023 2:59 am

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.


Return to “Help and Support”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari