API Triggers
Integration of triggers via SDK. Work methods.
Method List
Actions:
gp.triggers.claim()
- claim reward.
Properties:
gp.triggers.list
- trigger list.gp.triggers.activatedList
- activated trigger list.gp.triggers.getTrigger()
- get information about a trigger by ID or tag.
Checks:
gp.triggers.isActivated()
- check if trigger is activated.gp.triggers.isClaimed()
- check if trigger bonuses are claimed.
Events:
gp.triggers.on('activate')
- subscribe to the moment of trigger activation.gp.triggers.on('claim')
- subscribe to the moment of trigger bonuses claim.gp.triggers.on('error:claim')
- subscribe to an error when claim a trigger bonuses.
Types:
Trigger
- trigger fields.
Rules for Working with Triggers
How trigger activation occurs:
- The player enters the game or saves the game.
- On the server, the fulfillment of conditions is checked.
- The SDK receives a response from the server and notifies the developer.
- A notification of trigger activation is sent.
- When reward is claimed:
- A notification of trigger reward claimed is sent.
- A notification of reward receipt is sent.
- A notification of achievement receipt is sent.
- A notification of purchase accrual is sent.
How trigger rewards are claimed:
- If automatic reward claiming is enabled, rewards, purchases or achievements are recieved to the player when conditions are met.
- If manual claiming is selected, the
gp.triggers.claim()
method must be called at any time in order to obtain all of the trigger rewards. - When rewards are manually claimed, a request is made to save the player and all rewards are credited to the server and player variables are modified.
Since data consistency and bonus issuance are provided by us, there is no need to participate in the process at the code level.
It is enough for you to only subscribe to events of awarding rewards and wait for the trigger to activate.
Actions
Claim Reward
To claim a reward for a trigger, you need to pass the ID or tag of the trigger.
// By ID
gp.triggers.claim({ id: '646929f98abe970f54fb6274' });
// By Tag
gp.triggers.claim({ tag: 'LEVEL_10' });
The method returns the trigger, activation status, and reward confirmation:
const { trigger, isActivated, isClaimed } = await gp.triggers.claim({ tag: 'LEVEL_10' });
Properties
Trigger List
You have access to the entire trigger list immediately upon launching the game. See trigger fields.
gp.triggers.list.forEach((trigger) => {
// trigger.id
// trigger.tag
// trigger.isAutoClaim
// trigger.description
// trigger.conditions
// trigger.bonuses
});
Activated Trigger List
You have access to the entire list of activated triggers when the player is ready.
gp.triggers.activatedList.forEach((triggerId) => {
// Trigger ID as a string
// Getting a trigger by ID
const { trigger, isActivated, isClaimed } = gp.triggers.getTrigger(triggerId);
});
Get Information About Trigger
The method returns trigger and activation status:
// By ID
const { trigger, isActivated, isClaimed } = gp.triggers.getTrigger('646929f98abe970f54fb6274');
// By Tag
const { trigger, isActivated, isClaimed } = gp.triggers.getTrigger('LEVEl_10');
// The trigger may not exist, make sure it exists
if (trigger) {
console.info(trigger.id, isActivated, isClaimed);
}
Checks
Trigger Activated
gp.triggers.isActivated(idOrTag)
// By ID
const isActivated = gp.triggers.isActivated('646929f98abe970f54fb6274');
// By Tag
const isActivated = gp.triggers.isActivated('LEVEl_10');
// Check
if (isActivated) {
// LEVEl_10 trigger is activated
}
Reward Claimed
gp.triggers.isClaimed(idOrTag)
// By ID
const isClaimed = gp.triggers.isClaimed('646929f98abe970f54fb6274');
// By Tag
const isClaimed = gp.triggers.isClaimed('LEVEl_10');
// Check
if (isClaimed) {
// LEVEl_10 bonuses of the trigger is claimed
}
Events
Trigger Activated
Callback returns trigger:
gp.triggers.on('activate', ({ trigger }) => {
// Information about the trigger is available
});
Reward Claimed
Callback returns trigger:
gp.triggers.on('claim', ({ trigger }) => {
// Information about the trigger is available
});
Reward Claim Failed
The callback returns an error. See error codes:
gp.triggers.on('error:claim', (err) => {
// check error code
});
Types
Trigger Fields
Field | Type | Description | Example |
---|---|---|---|
id | string | Reward ID | 646929f98abe970f54fb6274 |
tag | string | Tag for selecting the trigger. You can use it instead of ID | LEVEL_10 |
description | string | Trigger description | Reach level 10 |
isAutoClaim | boolean | The reward is automatically claimed when the trigger is activated | true |
conditions | Condition[][] | List of trigger conditions | [] |
bonuses | Bonus[] | List of bonuses | [] |
Condition Fields
Field | Type | Description | Example |
---|---|---|---|
type | ConditionType | Type of condition | PLAYER_FIELD |
key | string | Variable key to compare | level |
operator | ConditionOperator | Type of comparison operator | EQ |
value | number[] / string[] / boolean[] | Values to be checked, combined with OR | [10,20] |
Full example of condition structure:
// Conditions AND on player fields
// player.level >= 10
const playerLevelGte10: Condition = {
type: 'PLAYER_FIELD',
key: 'level',
operator: 'GTE',
value: [10],
};
// player.class === 'rouge' || player.class === 'mage'
const playerRogueOrMage: Condition = {
type: 'PLAYER_FIELD',
key: 'class',
operator: 'EQ',
value: ['rogue', 'mage'],
};
// player.level >= 10 && (player.class === 'rouge' || player.class === 'mage')
const playerANDConditions: Condition[] = [playerLevelGte10, playerRogueOrMage];
// Conditions AND on player statistics
// playerStats.activeDays >= 5
const activeDaysGTE5: Condition = {
type: 'PLAYER_STAT',
key: 'activeDays',
operator: 'GTE',
value: [5],
};
// playerStats.playtimeAll >= 36000
const playtimeAllGTE360000: Condition = {
type: 'PLAYER_STAT',
key: 'playtimeAll',
operator: 'GTE',
value: [36000],
};
// playerStats.activeDays >= 5 && playerStats.playtimeAll >= 36000
const playerStatsANDConditions: Condition[] = [activeDaysGTE5, playtimeAllGTE360000];
// Conditions OR
// Trigger activates if either conditions are met for player fields or player stats
const triggerORConditions: Condition[][] = [playerANDConditions, playerStatsANDConditions];
Condition Types
ConditionType
Type | Description |
---|---|
PLAYER_FIELD | Check against player fields |
PLAYER_STAT | Check against player statistics |
ENTITY_STAT | Check against stats from external modules, such as events or schedulers |
Comparison Operator Types
ConditionOperator
Type | Description |
---|---|
EQ | Equal |
NE | Not equal |
GT | Greater than |
LT | Less than |
GTE | Greater than or equal to |
LTE | Less than or equal to |
Bonus Fields
Bonus
Field | Type | Description | Example |
---|---|---|---|
type | BonusType | Type of bonus | REWARD |
id | number | Bonus ID | 1122 |
Example of bonus structures:
const bonuses: Bonus[] = [
{
type: 'REWARD',
id: 941,
},
{
type: 'PRODUCT',
id: 31,
},
];
Bonus Types
BonusType
Type | Description |
---|---|
REWARD | Reward |
ACHIEVEMENT | Achievement |
PRODUCT | Product |
Error Codes
Error | Error Description |
---|---|
trigger_not_found | Trigger with the provided ID or tag not found |
trigger_not_activated | Trigger is not activated |
trigger_already_claimed | Reward has already been claimed |
undefined | Unexpected error (check the console for details) |
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!