API Triggers
Integration of triggers via SDK. Work methods.
Method List
Actions:
gp.triggers.claim()
- claim reward. +Lazy Sync Request
Properties:
gp.triggers.list
- trigger list. FREEgp.triggers.activatedList
- activated trigger list. FREEgp.triggers.getTrigger()
- get information about a trigger by ID or tag. FREE
Checks:
gp.triggers.isActivated()
- check if trigger is activated. FREEgp.triggers.isClaimed()
- check if trigger bonuses are claimed. FREE
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
+Lazy Sync RequestTo claim a reward for a trigger, you need to pass the ID or tag of the trigger.
- JavaScript
- Unity
// By ID
gp.triggers.claim({ id: '646929f98abe970f54fb6274' });
// By Tag
gp.triggers.claim({ tag: 'LEVEL_10' });
// By ID
GP_Triggers.Claim('646929f98abe970f54fb6274');
// By Tag
GP_Triggers.Claim('LEVEL_10');
The method returns the trigger, activation status, and reward confirmation:
- JavaScript
- Unity
const { trigger, isActivated, isClaimed } = await gp.triggers.claim({ tag: 'LEVEL_10' });
Not implemented, use GP_Trigger.GetTrigger() to get this data
Properties
Trigger List
FREEYou have access to the entire trigger list immediately upon launching the game. See trigger fields.
- JavaScript
- Unity
gp.triggers.list.forEach((trigger) => {
// trigger.id
// trigger.tag
// trigger.isAutoClaim
// trigger.description
// trigger.conditions
// trigger.bonuses
});
//Get list of triggers
TriggerData[] triggers = GP_Triggers.List();
//Show each trigger data
foreach(TriggerData trigger in triggers)
{
Debug.Log("ID: " + trigger.id);
Debug.Log("Tag: " + trigger.tag);
Debug.Log("AutoClaim: " + trigger.isAutoClaim);
Debug.Log("Descroption: " + trigger.description);
foreach (TriggerCondition condition in trigger.conditions)
{
Debug.Log("Condition: " + JsonUtility.ToJson(condition));
}
foreach (TriggerBonus bonus in trigger.bonuses)
{
Debug.Log("Bonus: " + JsonUtility.ToJson(bonus));
}
}
Activated Trigger List
FREEYou have access to the entire list of activated triggers when the player is ready.
- JavaScript
- Unity
gp.triggers.activatedList.forEach((triggerId) => {
// Trigger ID as a string
// Getting a trigger by ID
const { trigger, isActivated, isClaimed } = gp.triggers.getTrigger(triggerId);
});
//Get activated triggers list
TriggerActive[] triggers = GP_Triggers.ActivatedList();
//Show each activated trigger data
foreach (TriggerActive trigger in triggers)
{
Debug.Log("ID: " + trigger.triggerId);
Debug.Log("Claimed: " + trigger.claimed);
}
Get Information About Trigger
FREEThe method returns trigger and activation status:
- JavaScript
- Unity
// 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);
}
// By ID
TriggerAllData data = GP_Triggers.GetTrigger('646929f98abe970f54fb6274');
// By Tag
TriggerAllData data = GP_Triggers.GetTrigger('LEVEl_10');
Debug.Log(data.trigger);
Debug.Log(data.isActivated);
Debug.Log(data.isClaimed);
Checks
Trigger Activated
gp.triggers.isActivated(idOrTag)
FREE
- JavaScript
- Unity
// 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
}
// By ID
bool isActivated = GP_Triggers.IsActivated('646929f98abe970f54fb6274');
// By Tag
bool isActivated = GP_Triggers.IsActivated('LEVEl_10');
// Check
if (isActivated) {
// LEVEl_10 trigger is activated
}
Reward Claimed
gp.triggers.isClaimed(idOrTag)
FREE
- JavaScript
- Unity
// 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
}
// By ID
bool isClaimed = GP_Triggers.IsClaimed('646929f98abe970f54fb6274');
// By Tag
bool isClaimed = GP_Triggers.IsClaimed('LEVEl_10');
// Check
if (isClaimed) {
// LEVEl_10 bonuses of the trigger is claimed
}
Events
Trigger Activated
Callback returns trigger:
- JavaScript
- Unity
gp.triggers.on('activate', ({ trigger }) => {
// Information about the trigger is available
});
//Subscribe to event
private void OnEnable()
{
GP_Triggers.OnTriggerActivate += OnActivate;
}
//Unsubscribe from event
private void OnDisable()
{
GP_Triggers.OnTriggerActivate -= OnActivate;
}
//Process the event
public void OnActivate(TriggerData trigger)
{
Debug.Log(trigger.ToString());
}
Reward Claimed
Callback returns trigger:
- JavaScript
- Unity
gp.triggers.on('claim', ({ trigger }) => {
// Information about the trigger is available
});
//Subscribe to event
private void OnEnable()
{
GP_Triggers.OnTriggerClaim += OnClaim;
}
//Unsubscribe from event
private void OnDisable()
{
GP_Triggers.OnTriggerClaim -= OnClaim;
}
//Process the event
public void OnClaim(TriggerData trigger)
{
Debug.Log(trigger.ToString());
}
Reward Claim Failed
The callback returns an error. See error codes:
- JavaScript
- Unity
gp.triggers.on('error:claim', (err) => {
// check error code
});
//Subscribe to event
private void OnEnable()
{
GP_Triggers.OnTriggerClaimError += OnClaimError;
}
//Unsubscribe from event
private void OnDisable()
{
GP_Triggers.OnTriggerClaimError -= OnClaimError;
}
//Process the event
public void OnClaimError(string error)
{
Debug.LogError(error);
}
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!