Skip to main content

API Triggers

Integration of triggers via SDK. Work methods.

Method List

Actions:

Properties:

Checks:

Events:

Types:

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 ss.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 Request

To claim a reward for a trigger, you need to pass the ID or tag of the trigger.

// By ID
ss.triggers.claim({ id: '646929f98abe970f54fb6274' });
// By Tag
ss.triggers.claim({ tag: 'LEVEL_10' });

The method returns the trigger, activation status, and reward confirmation:

const { trigger, isActivated, isClaimed } = await ss.triggers.claim({
tag: 'LEVEL_10'
});

Properties

Trigger List

FREE

You have access to the entire trigger list immediately upon launching the game. See trigger fields.

ss.triggers.list.forEach((trigger) => {
// trigger.id
// trigger.tag
// trigger.isAutoClaim
// trigger.description
// trigger.conditions
// trigger.bonuses
});

Activated Trigger List

FREE

You have access to the entire list of activated triggers when the player is ready.

ss.triggers.activatedList.forEach((triggerId) => {
// Trigger ID as a string

// Getting a trigger by ID
const { trigger, isActivated, isClaimed } =
ss.triggers.getTrigger(triggerId);
});

Get Information About Trigger

FREE

The method returns trigger and activation status:

// By ID
const { trigger, isActivated, isClaimed } = ss.triggers.getTrigger(
'646929f98abe970f54fb6274'
);
// By Tag
const { trigger, isActivated, isClaimed } = ss.triggers.getTrigger('LEVEl_10');

// The trigger may not exist, make sure it exists
if (trigger) {
console.info(trigger.id, isActivated, isClaimed);
}

Checks

Trigger Activated

ss.triggers.isActivated(idOrTag) FREE

// By ID
const isActivated = ss.triggers.isActivated('646929f98abe970f54fb6274');
// By Tag
const isActivated = ss.triggers.isActivated('LEVEl_10');

// Check
if (isActivated) {
// LEVEl_10 trigger is activated
}

Reward Claimed

ss.triggers.isClaimed(idOrTag) FREE

// By ID
const isClaimed = ss.triggers.isClaimed('646929f98abe970f54fb6274');
// By Tag
const isClaimed = ss.triggers.isClaimed('LEVEl_10');

// Check
if (isClaimed) {
// LEVEl_10 bonuses of the trigger is claimed
}

Events

Trigger Activated

Callback returns trigger:

ss.triggers.on('activate', ({ trigger }) => {
// Information about the trigger is available
});

Reward Claimed

Callback returns trigger:

ss.triggers.on('claim', ({ trigger }) => {
// Information about the trigger is available
});

Reward Claim Failed

The callback returns an error. See error codes:

ss.triggers.on('error:claim', (err) => {
// check error code
});

Types

Trigger Fields

FieldTypeDescriptionExample
idstringReward ID646929f98abe970f54fb6274
tagstringTag for selecting the trigger. You can use it instead of IDLEVEL_10
descriptionstringTrigger descriptionReach level 10
isAutoClaimbooleanThe reward is automatically claimed when the trigger is activatedtrue
conditionsCondition[][]List of trigger conditions[]
bonusesBonus[]List of bonuses[]

Condition Fields

FieldTypeDescriptionExample
typeConditionTypeType of conditionPLAYER_FIELD
keystringVariable key to comparelevel
operatorConditionOperatorType of comparison operatorEQ
valuenumber[] / 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

TypeDescription
PLAYER_FIELDCheck against player fields
PLAYER_STATCheck against player statistics
ENTITY_STATCheck against stats from external modules, such as events or schedulers

Comparison Operator Types

ConditionOperator

TypeDescription
EQEqual
NENot equal
GTGreater than
LTLess than
GTEGreater than or equal to
LTELess than or equal to

Bonus Fields

Bonus

FieldTypeDescriptionExample
typeBonusTypeType of bonusREWARD
idnumberBonus ID1122

Example of bonus structures:

const bonuses: Bonus[] = [
{
type: 'REWARD',
id: 941
},
{
type: 'PRODUCT',
id: 31
}
];

Bonus Types

BonusType

TypeDescription
REWARDReward
ACHIEVEMENTAchievement
PRODUCTProduct

Error Codes

ErrorError Description
trigger_not_foundTrigger with the provided ID or tag not found
trigger_not_activatedTrigger is not activated
trigger_already_claimedReward has already been claimed
undefinedUnexpected error (check the console for details)

Stay in Touch

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

SpellSync Community Telegram: @spellsync.

For your suggestions e-mail: [email protected]

We Wish you Success!