-
Notifications
You must be signed in to change notification settings - Fork 0
Adding an in‐game Achievement
A lot of the achievements in All You Can Mine use this hook, they are found in AllYouCanMine/content/Achievements
In your modInit in your mod_main.gd, you just have to declare a new achievement as follows :
get_node("/root/ModLoader/POModder-Dependency").data_achievements.add_achievement(id : String , stage : String)The id should be the same as in step 2 and the stage is the name of the stage your achievement should be loaded in. The different stages names are MultiplayerLoadoutModStage, Relichunt, ... If you want your achievement to appear in any LevelStage (no matter which gamemode as long as it is a LevelStage), just use stage = "LevelStage"
Create an achievement scene with a script attached to it. This scene will be instanced depending on the stage we're in (once we set it up) and added as a grand_child of the dependency's mod_main node . So don't try to use get_parent. The easyest way to go through the tree is using autoloads such as Level and StageManager (if you want to find the map, use StageManager.currentStage.MAP).
The achievement script should never be queue_freed! The achievements are all queue_freed() when the stage is over. If your achievement needs data to store (for example if you want to make an achievement to collect a total of 1.000 iron on multiple games), you'll need to make your own save system or find a way to use the vanilla one.
Your achievement should call get_parent().unlockAchievement(id : String) to unlock the achievement. The unlock of the achievement is automatically saved, you don't have to worry about it. All the loadout visibility is also automatic.
Your achievement scene file should be names exactly the same as your achievement id (step 1 and 2). Then simply override it into the right folder :
var my_achievement = preload(path)
my_achievement.take_over_path("res://mods-unpacked/POModder-Dependency/content/Achievements/myAchievementId.tscn")Your achievement is now ready.