Skip to main content

Achievements

Overview

The GamePush functionality allows you to add achievements to the game, combine them into groups and manage them. And also monitor the progress and accomplishment of achievements by players. You will be able to unlock achievements by ID or Tag and trigger various events when unlocking achievements. This section provides information on how to:

  • Unlock achievement.
  • Open list of achievements, open - used when you need to show achievements through a ready-made interface.
  • Get a list of achievements, fetch - used when the list of achievements needs to be drawn manually.

As well as information about available achievement fields, achievement group fields, and player achievement fields.

Unlock achievement

+1 Request

To unlock player's achievement, you need to pass an ID or Tag of achievement.

// Unlock by id
gp.achievements.unlock({ id: 17541 });

// Unlock by tag
gp.achievements.unlock({ tag: 'WIN_FIRST_BATTLE' });

Unlock achievement events

// Unlock success
gp.achievements.on('unlock', (achievement) => {});

// Unlock error
gp.achievements.on('error:unlock', (error) => {});

Unlock with promises

const result = await gp.achievements.unlock({ id: 17541 });

/**
* Is achievement was success unlocked
* @type {boolean}
*/
result.success;

/**
* Achievement data
* @type {Achievement | null}
*/
result.achievement;

/**
* Error if unlock failed
* @type {
* 'player_not_found' |
* 'empty_id_or_tag' |
* 'achievement_not_found' |
* 'already_unlocked' |
* undefined
* }
*/
result.error;

Setting Progress in an Achievement

+1 Request

You can set progress in an achievement. To do this, in the control panel in the achievement, set the "Maximum Progress" field to the value you need.

Set the "Notification Step" to show notifications to the player about the progress every X progress points.

When the progress changes, the achievement is automatically unlocked if the progress is greater than the maximum.

// Set progress by ID
gp.achievements.setProgress({ id: 17541, progress: 57 });

// Set progress by tag
gp.achievements.setProgress({ tag: 'WIN_FIRST_BATTLE', progress: 57 });

Events when progress of the achievement

// Progress of achievement changed
gp.achievements.on('progress', (achievement) => {});

// Error while changing progress
gp.achievements.on('error:progress', (error) => {});

Asynchronous response processing.

const result = await gp.achievements.setProgress({ id: 17541, progress: 57 });
/**
* Whether the progress was changed successfully
* @type {boolean}
*/
result.success;

/**
* Data about the achievement
* @type {Achievement | null}
*/
result.achievement;

/**
* Error if something went wrong
* @type {
* 'player_not_found' |
* 'empty_id_or_tag' |
* 'achievement_not_found' |
* 'achievement_has_no_progress' |
* 'progress_the_same' |
* 'already_unlocked' |
* undefined
* }
*/
result.error;

Checks

FREE

Check if the player has an achievement by ID or tag:

const isUnlocked = gp.achievements.has('WIN_FIRST_BATTLE');

Check the progress of an achievement by ID or tag:

const progress = gp.achievements.getProgress('WIN_FIRST_BATTLE');

Open achievements list

FREE

In order not to implement the displaying of the achievements on your side, you can simply open it in the in-game overlay.

gp.achievements.open();

Open with promises

// wait until closed
await gp.achievements.open();

Achievements overlay events

// On open
gp.achievements.on('open', () => {});

// On close
gp.achievements.on('close', () => {});

List of Achievements

FREE

List of achievements:

gp.achievements.list;

List of player's achievements that have progress and unlocked achievements:

gp.achievements.playerAchievementsList;

List of achievement groups:

gp.achievements.groupsList;

Get achievements list

FREE Deprecated
gp.achievements.fetch();

Fetch with promises

const result = await gp.achievements.fetch();

// Response result
const {
// Achievements list
achievements,
// Achievements groups
achievementsGroups,
// Player's unlocked achievements
playerAchievements,
} = result;

Fetch achievements events

// Fetch success
gp.achievements.on('fetch', (result) => {});

// Fetch error
gp.achievements.on('error:fetch', (error) => {});

Achievement fields

/**
* Achievement ID
* @type {number}
*/
achievement.id;

/**
* Optional tag for help in selecting
* You can use it instead of ID
* @type {string}
*/
achievement.tag;

/**
* Name translated into current language
* @type {string}
*/
achievement.name;

/**
* Description translated into current language
* @type {string}
*/
achievement.description;

/**
* Icon src 256x256
* @type {string}
*/
achievement.icon;

/**
* Icon src 64x64
* @type {string}
*/
achievement.iconSmall;

/**
* Icon src of locked achievement, 256x256
* @type {string}
*/
achievement.lockedIcon;

/**
* Icon src of locked achievement, 64x64
* @type {string}
*/
achievement.lockedIconSmall;

/**
* Rarity of achievement
* @type {'COMMON' | 'UNCOMMON' | 'RARE' | 'EPIC' | 'LEGENDARY' | 'MYTHIC'}
*/
achievement.rare;

/**
* Maximum progress of the achievement
* @type {number}
*/
achievement.maxProgress;

/**
* Step for progress notification
* @type {number}
*/
achievement.progressStep;

/**
* Whether the achievement should be shown if it's not unlocked
* @type {boolean}
*/
achievement.lockedVisible;

/**
* Whether the description of the achievement should be shown if it's not unlocked
* @type {boolean}
*/
achievement.lockedDescriptionVisible;

Achievements Group fields

/**
* Achievement group ID
* @type {number}
*/
achievementsGroup.id;

/**
* Optional tag for help in selecting
* You can use it instead of ID
* @type {string}
*/
achievementsGroup.tag;

/**
* Name translated into current language
* @type {string}
*/
achievementsGroup.name;

/**
* Description translated into current language
* @type {string}
*/
achievementsGroup.description;

/**
* Array of achievement ID in group
* @type {number[]}
*/
achievementsGroup.achievements;

Player Achievement fields

/**
* Achievement ID
* @type {number}
*/
playerAchievement.achievementId;

/**
* Time when the achievement was unlocked
* @type {string}
*/
playerAchievement.createdAt;

/**
* Achievement progress
* @type {number}
*/
playerAchievement.progress;

/**
* Achievement unlocked
* @type {boolean}
*/
playerAchievement.unlocked;

Stay in Touch

Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.

GamePush Community Telegram: @gs_community.

For your suggestions e-mail: [email protected]

We Wish you Success!