Achievements #

Read more about the Achievements system in Hiro here.

Functions #

ClaimAchievements #

Claim one or more achievements by their IDs whose progress has been completed.

1
2
3
4
5
6
7
8
userId := "userId"
achievementIds := []string{"<achievementId1>", "<achievementId2>"}
claimTotal := true

achievements, repeatAchievements, err := systems.GetAchievementsSystem().ClaimAchievements(ctx, logger, nk, userId, achievementIds, claimTotal)
if err != nil {
  return err
}

GetAchievements #

Get all achievements available to the user, and their progress on them.

1
2
3
4
5
6
userId := "userId"

achievements, repeatAchievements, err := systems.GetAchievementsSystem().GetAchievements(ctx, logger, nk, userId)
if err != nil {
  return err
}

UpdateAchievements #

Update progress on one or more achievements by their IDs.

1
2
3
4
5
6
7
userId := "userId"
achievementUpdates := map[string]int64{"<achievementId1>": 5, "<achievementId2>": 10}

achievements, repeatAchievements, err := systems.GetAchievementsSystem().UpdateAchievements(ctx, logger, nk, userId, achievementUpdates)
if err != nil {
  return err
}

Hooks #

SetOnAchievementReward #

Set a custom reward function which will run after an achievement’s reward is rolled.

1
2
3
4
5
6
systems.GetAchievementsSystem().SetOnAchievementReward(OnAchievementReward)

func OnAchievementReward(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, sourceID string, source *hiro.AchievementsConfigAchievement, rewardConfig *hiro.EconomyConfigReward, reward *hiro.Reward) (*hiro.Reward, error) {
	// Modify reward or take additional actions.
	return reward, nil
}

SetOnSubAchievementReward #

Set a custom reward function which will run after a sub-achievement’s reward is rolled.

1
2
3
4
5
6
systems.GetAchievementsSystem().SetOnSubAchievementReward(OnSubAchievementReward)

func OnSubAchievementReward(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, sourceID string, source *hiro.AchievementsConfigSubAchievement, rewardConfig *hiro.EconomyConfigReward, reward *hiro.Reward) (*hiro.Reward, error) {
	// Modify reward or take additional actions.
	return reward, nil
}

SetOnAchievementTotalReward #

Set a custom reward function which will run after an achievement’s total reward is rolled.

1
2
3
4
5
6
systems.GetAchievementsSystem().SetOnAchievementTotalReward(OnAchievementTotalReward)

func OnAchievementTotalReward(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, sourceID string, source *hiro.AchievementsConfigAchievement, rewardConfig *hiro.EconomyConfigReward, reward *hiro.Reward) (*hiro.Reward, error) {
	// Modify reward or take additional actions.
	return reward, nil
}