Energy
You can configure automatic variables that will be accrued according to the server time, which can be set with upper and lower limits.
Examples:
- Energy / Lives;
- Hourly rewards from the opening moment;
- Limit on the number of actions, for example, no more than 3 ad views for a reward in 30 minutes (similar to hourly rewards).
- Offline piggy banks.
- Player loyalty mechanics.
Configuration
The concept of energy involves setting the maximum and minimum values of a player's field, as well as the interval for automatically adding the variable value.
More about configuring player fields:
More about working with Player State API.
Energy / Lives
To implement lives, you need to create a energy
field for the player in the Players section on the project management panel as shown in the screenshot:
In this example, Energy:
- Is available within the range from 0 to 100 (Limit by range);
- Starts full upon first entry (Default value);
- Adds 1 unit of energy every 60 seconds (Automatically incremented variable);
- Can be manually set above 100.
Checking energy at level start
- JavaScript
- Unity
function onClickButtonStartLevel() {
// Not enough energy
if (gp.player.get('energy') <= 0) {
// Show modal "Not enough energy"
showNotEnoughEnergyModal();
return;
}
// Subtract 1 unit of energy
gp.player.add('energy', -1);
// Save the deduction to persist after reload
gp.player.sync();
// Start the level
startLevel();
}
public void ClickButtonStartLevel()
{
// Not enough energy
if (GP_Player.Get("energy") <= 0) {
// Show modal "Not enough energy"
ShowNotEnoughEnergyModal();
return;
}
// Subtract 1 unit of energy
GP_Player.Add("energy", -1);
// Save the deduction to persist after reload
GP_Player.Sync();
// Start the level
StartLevel();
}
Bonus energy
Add a certain amount of energy manually as a bonus, for example, when using an item, unlocking an achievement, or making a purchase. If the variable can be set above the maximum, in the following example 10 energy will be added even if the energy is full.
- JavaScript
- Unity
// Add 10 units of energy manually as a bonus
async function addMoreEnergy() {
// Add 10 units of energy
gp.player.add('energy', 10);
// Save
gp.player.sync();
}
// Add 10 units of energy manually as a bonus
public void AddMoreEnergy() {
// Add 10 units of energy
GP_Player.Add('energy', 10);
// Save
GP_Player.Sync();
}
Refill energy by watching ads
- JavaScript
- Unity
async function onClickButtonRefillEnergy() {
const success = await gp.ads.showRewardedVideo();
if (!success) {
// Failed to show / complete the ad
return;
}
// Restore all missing energy
gp.player.set('energy', gp.player.getMaxValue('energy'));
// Save
gp.player.sync();
}
public void ClickButtonRefillEnergy() {
if(GP_Ads.IsRewardedAvailable()){
// Show rewarded
GP_Ads.ShowRewarded("Refill", OnRewardedReward);
}
}
// Reward is received
private void OnRewardedReward(string value)
{
if (value == "Refill"){
// Restore all missing energy
GP_Player.Set("energy", GP_Player.GetMaxValue("energy"));
// Save
GP_Player.Sync();
}
}
Increase energy capacity
Increase the maximum energy capacity. Let's consider the example of a purchase.
- JavaScript
- Unity
async function onClickButtonIncreaseEnergy() {
// Purchase energy increase
await gp.payments.purchase({ tag: 'ENERGY_100' });
// Add 100 to the maximum energy value
gp.player.add('energy:max', 100);
// Replenish energy reserve
gp.player.set('energy', gp.player.getMaxValue('energy'));
// Save
await gp.player.sync();
// Consume the purchase
await gp.payments.consume({ tag: 'GOLD_1000' });
}
public void ClickButtonIncreaseEnergy() {
// Purchase energy increase
GP_Payments.Purchase("ENERGY_100", OnPurchaseSuccess, OnPurchaseError);
}
private void OnPurchaseSuccess(string productIdOrTag){
if(productIdOrTag == "ENERGY_100")
{
// Add 100 to the maximum energy value
GP_Player.Add("energy:max", 100);
// Replenish energy reserve
GP_Player.Set("energy", GP_Player.GetMaxValue("energy"));
// Save
GP_Player.Sync();
// Consume the purchase
GP_Payments.Consume("ENERGY_100");
}
}
Accelerated energy restoration
Energy restoration can be accelerated by either reducing the increment interval or increasing the amount of energy restored per iteration. Let's consider the example of purchasing VIP membership.
Increase the amount of energy restored per interval:
- JavaScript
- Unity
// If the player has a VIP purchase, 2 units of energy are restored per minute instead of 1
async function onGameStart() {
// Set the amount of energy restored per iteration
if (gp.payments.has('VIP')) {
gp.player.set('energy:incrementValue', 2);
} else {
gp.player.set('energy:incrementValue', 1);
}
}
// If the player has a VIP purchase, 2 units of energy are restored per minute instead of 1
private void OnGameStart() {
// Set the amount of energy restored per iteration
if (GP_Player.GetBool("VIP")) {
GP_Player.Set("energy:incrementValue", 2);
} else {
GP_Player.Set("energy:incrementValue", 1);
}
}
Decrease the energy restoration time:
- JavaScript
- Unity
// If the player has a VIP purchase, 1 unit of energy is restored every 30 seconds instead of 1 minute
async function onGameStart() {
// Set the increment interval
if (gp.payments.has('VIP')) {
gp.player.set('energy:incrementInterval', 30);
} else {
gp.player.set('energy:incrementInterval', 60);
}
}
// If the player has a VIP purchase, 1 unit of energy is restored every 30 seconds instead of 1 minute
private void OnGameStart() {
// Set the increment interval
if (GP_Player.GetBool("VIP")) {
GP_Player.Set("energy:incrementInterval", 30);
} else {
GP_Player.Set("energy:incrementInterval", 60);
}
}
Get time until restoration
To display how much time is left until the next energy restoration in the interface:
- JavaScript
- Unity
Method:
// Difference in seconds until the next energy restoration
gp.player.get('energy:secondsLeft');
Example:
// Time until the next energy restoration in a human-readable format like 05:47
function getSecondsLeftHuman() {
const secondsLeft = gp.player.get('energy:secondsLeft');
return formatTime(secondsLeft);
}
// Format into a human-readable format like 00:00
function formatTime(seconds) {
const minutes = Math.floor((seconds % 3600) / 60);
const remainingSeconds = seconds % 60;
return `${pad(minutes)}:${pad(remainingSeconds)}`;
}
// Add leading zeros
function pad(num) {
return String(num).padStart(2, '0');
}
// Time until the next energy restoration in a human-readable format like 05:47
public string GetSecondsLeftHuman()
{
int secondsLeft = GP_Player.GetInt("energy:secondsLeft");
return FormatTime(secondsLeft);
}
// Format into a human-readable format like 00:00
private string FormatTime(int seconds)
{
int minutes = Mathf.FloorToInt((seconds % 3600) / 60);
int remainingSeconds = seconds % 60;
return $"{Pad(minutes)}:{Pad(remainingSeconds)}";
}
// Add leading zeros
private string Pad(int num)
{
return num.ToString("D2");
}
Find out the time until full restoration:
- JavaScript
- Unity
Method:
// Difference in seconds until full restoration
gp.player.get('energy:secondsLeftTotal');
Example:
// Time until full restoration in a human-readable format like 05:47
function getSecondsLeftTotalHuman() {
const secondsLeftTotal = gp.player.get('energy:secondsLeftTotal');
// Return in a human-readable format
return formatTime(secondsLeftTotal);
}
// Time until full restoration in a human-readable format like 05:47
public string GetSecondsLeftTotalHuman()
{
int secondsLeftTotal = GP_Player.GetInt("energy:secondsLeftTotal");
// Return in a human-readable format
return FormatTime(secondsLeftTotal);
}
Rewards / Boxes (Time-based)
You can implement a mechanism for giving rewards / chests based on a renewable timer.
For example:
- Common box every hour from the time of opening;
- Rare box every 6 hours from the time of opening;
- Epic box every 24 hours from the time of opening;
To implement rewards every hour, you need to create a field common-boxes
for the player in the Players section in the project management panel as shown in the screenshot:
In this example, Common Boxes:
- No more than 1 box is available within a period (Limiting the range);
- Upon the first login, there are 0 boxes (Default value), the first one will be available after 1 hour;
- Every 3600 seconds (1 hour), 1 box is added (Automatically assigned variable);
- You can set manually more than 1.
Check Readiness
- JavaScript
- Unity
function refreshRewardsUI() {
// There are boxes to open
if (gp.player.get('common-boxes') > 0) {
// Enable the open button
buttonOpenCommonBox.enable();
} else {
// Disable the open button
buttonOpenCommonBox.disable();
}
}
// Common boxes button
private GameObject buttonOpenCommonBox;
public void RefreshRewardsUI() {
// There are boxes to open
if (GP_Player.GetInt("common-boxes") > 0) {
// Enable the open button
buttonOpenCommonBox.SetActive(true);
} else {
// Disable the open button
buttonOpenCommonBox.SetActive(false);
}
}
Bonus Rewards
Manually award a certain amount of rewards as a bonus, for example, upon level completion or boss defeat. If it's possible to set a value higher than the maximum, in the example below, 1 box will be added even if there is already an unopened box.
- JavaScript
- Unity
// Manually give 1 common box as a bonus
async function giveCommonBox() {
// Add 1 common box
gp.player.add('common-boxes', 1);
// Save
gp.player.sync();
}
// Manually give 1 common box as a bonus
public void GiveCommonBox() {
// Add 1 common box
GP_Player.Add("common-boxes", 1);
// Save
GP_Player.Sync();
}
Acquire boxes through purchase:
- JavaScript
- Unity
// Award boxes for purchase
async function buyCommonBoxPack() {
// Purchase a box pack
await gp.payments.purchase({ tag: 'BOXES_PACK' });
// Add 10 common boxes
gp.player.add('common-boxes', 10);
// Add 3 rare boxes
gp.player.add('rare-boxes', 3);
// Add 1 epic box
gp.player.add('epic-boxes', 1);
// Save
await gp.player.sync();
// Mark the purchase as consumed
await gp.payments.consume({ tag: 'BOXES_PACK' });
}
public void BuyCommonBoxPack() {
// Purchase a box pack
GP_Payments.Purchase("BOXES_PACK", OnPurchaseSuccess, OnPurchaseError);
}
private void OnPurchaseSuccess(string productIdOrTag){
if(productIdOrTag == "BOXES_PACK")
{
// Add 10 common boxes
GP_Player.Add("common-boxes", 10);
// Add 3 rare boxes
GP_Player.Add("rare-boxes", 3);
// Add 1 epic box
GP_Player.Add("epic-boxes", 1);
// Save
GP_Player.Sync();
// Mark the purchase as consumed
GP_Payments.Consume("BOXES_PACK");
}
}
Get Time Until Opening
To display in the interface how much time is left until the next box can be opened:
- JavaScript
- Unity
Method:
// Difference in seconds until the next opening
gp.player.get('common-boxes:secondsLeft');
Example:
// Amount of time until the next opening in human-readable format 01:37:42
function getSecondsLeftHuman() {
const secondsLeft = gp.player.get('common-boxes:secondsLeft');
return formatTime(secondsLeft);
}
// Format into human-readable format 00:00:00
function formatTime(seconds) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const remainingSeconds = seconds % 60;
return `${pad(hours)}:${pad(minutes)}:${pad(remainingSeconds)}`;
}
// Adding leading zeros
function pad(num) {
return String(num).padStart(2, '0');
}
// Amount of time until the next opening in human-readable format 01:37:42
public string GetSecondsLeftHuman()
{
int secondsLeft = GP_Player.GetInt("common-boxes:secondsLeft");
return FormatTime(secondsLeft);
}
// Format into human-readable format 00:00:00
private string FormatTime(int seconds)
{
int hours = Mathf.FloorToInt(seconds / 3600);
int minutes = Mathf.FloorToInt((seconds % 3600) / 60);
int remainingSeconds = seconds % 60;
return $"{Pad(hours)}:{Pad(minutes)}:{Pad(remainingSeconds)}";
}
// Adding leading zeros
private string Pad(int num)
{
return num.ToString("D2");
}
Speed Up Opening with Currency
Example of exchanging in-game currency for instant opening. In the example, we exchange the player's gems for speeding up the box opening. The exchange rate will depend on the remaining time until opening.
- JavaScript
- Unity
// Get the cost of instant opening
function getOpenCost() {
// Exchange rate of gems to seconds of opening
// 1 crystal = 3 minutes (180 seconds)
const gemsRate = 1 / 180;
// Remaining seconds until opening
const secondsLeft = gp.player.get('common-boxes:secondsLeft');
// Calculate the opening cost
return Math.ceil(secondsLeft * gemsRate);
}
// When "Open for gems" button is clicked
function onButtonInstantOpen() {
// Get the opening cost
const price = getOpenCost();
// Opening time has come, box is already available
if (price === 0) {
// Hide the button
hideInstantOpenButton();
return;
}
// Insufficient gems
if (gp.player.get('gems') < price) {
showModalNotEnoughGems();
return;
}
// Deduct the cost from the player's gems
gp.player.add('gems', -price);
// Add the box
gp.player.add('common-boxes', 1);
// Save the player
gp.player.sync();
}
// Get the cost of instant opening
private int GetOpenCost() {
// Exchange rate of gems to seconds of opening
// 1 crystal = 3 minutes (180 seconds)
float gemsRate = 1 / 180;
// Remaining seconds until opening
int secondsLeft = GP_Player.Get("common-boxes:secondsLeft");
// Calculate the opening cost
return Mathf.CailToInt(secondsLeft * gemsRate);
}
// When "Open for gems" button is clicked
public void ButtonInstantOpen() {
// Get the opening cost
int price = GetOpenCost();
// Opening time has come, box is already available
if (price == 0) {
// Hide the button
HideInstantOpenButton();
return;
}
// Insufficient gems
if (GP_Player.GetInt("gems") < price) {
ShowModalNotEnoughGems();
return;
}
// Deduct the cost from the player's gems
GP_Player.Add("gems", - price);
// Add the box
GP_Player.Add("common-boxes", 1);
// Save the player
GP_Player.Sync();
}
Offline Piggy Bank
You can implement a mechanism to accumulate in-game currency even while the player is offline with the possibility of expanding the piggy bank capacity.
For the offline piggy bank, you need to create a player field offline-piggy-bank
in the Players section of the project management panel as shown in the screenshot:
In this example of the Offline Piggy Bank:
- Capacity no more than 1000 gold by default (Limit the range);
- Upon first login, 0 gold (Default value);
- Every 1 second, 1 gold is added (Automatically incremented variable).
Empty the Piggy Bank
- JavaScript
- Unity
function usePiggyBank() {
// Get the amount of accumulated gold
const rewardGold = gp.player.get('offline-piggy-bank');
// Add gold to the player
gp.player.add('gold', rewardGold);
// Empty the piggy bank
gp.player.set('offline-piggy-bank', 0);
// Save
gp.player.sync();
}
public void UsePiggyBank() {
// Get the amount of accumulated gold
int rewardGold = GP_Player.GetInt("offline-piggy-bank");
// Add gold to the player
GP_Player.Add("gold", rewardGold);
// Empty the piggy bank
GP_Player.Set("offline-piggy-bank", 0);
// Save
GP_Player.Sync();
}
Minimum Time to Open
You can allow the player to empty the piggy bank, for example, no more frequently than once every 5 minutes. The example will also calculate the number of seconds left until opening.
- JavaScript
- Unity
// Check if the piggy bank can be used
function canUsePiggyBank() {
// Find out how much time is left until the piggy bank is fully filled
const secondsToRefill = gp.player.get('offline-piggy-bank:secondsLeftTotal');
// Refill period (1 second in the example)
const iterationTime = gp.player.get('offline-piggy-bank:incrementInterval');
// Income per iteration (1 gold in the example)
const incomePerIteration = gp.player.get('offline-piggy-bank:incrementValue');
// Maximum possible amount of gold in the piggy bank (1000 in the example)
const bankCapacity = gp.player.get('offline-piggy-bank:max');
// Calculate how many iterations are needed to fill the piggy bank from zero
const iterationsToRefillFromEmpty = Math.ceil(bankCapacity / incomePerIteration);
// Calculate how many seconds are needed to fill the piggy bank from zero
const secondsToRefillFromEmpty = iterationTime * iterationsToRefillFromEmpty;
// Calculate how many seconds are left until opening, requirement - at least 5 minutes have passed
const secondsLeft = secondsToRefill - (secondsToRefillFromEmpty - 5 * 60);
// Can open if no time is left (at least 5 minutes have passed)
return secondsLeft <= 0;
}
// Check if the piggy bank can be used
public bool CanUsePiggyBank() {
// Find out how much time is left until the piggy bank is fully filled
int secondsToRefill = GP_Player.Get("offline-piggy-bank:secondsLeftTotal");
// Refill period (1 second in the example)
int iterationTime = GP_Player.Get("offline-piggy-bank:incrementInterval");
// Income per iteration (1 gold in the example)
int incomePerIteration = GP_Player.Get("offline-piggy-bank:incrementValue");
// Maximum possible amount of gold in the piggy bank (1000 in the example)
int bankCapacity = GP_Player.Get("offline-piggy-bank:max");
// Calculate how many iterations are needed to fill the piggy bank from zero
int iterationsToRefillFromEmpty = Mathf.CeilToInt(bankCapacity / incomePerIteration);
// Calculate how many seconds are needed to fill the piggy bank from zero
int secondsToRefillFromEmpty = iterationTime * iterationsToRefillFromEmpty;
// Calculate how many seconds are left until opening, requirement - at least 5 minutes have passed
int secondsLeft = secondsToRefill - (secondsToRefillFromEmpty - 5 * 60);
// Can open if no time is left (at least 5 minutes have passed)
return secondsLeft <= 0;
}
Increase Piggy Bank Capacity
You can increase the maximum limit of the piggy bank. This is useful when the game has a progression system, such as upgrading the piggy bank.
- JavaScript
- Unity
// Increase piggy bank capacity
async function upgradePiggyBankCapacity() {
// Current capacity of the piggy bank
const currentCapacity = gp.player.get('offline-piggy-bank:max');
// Double the capacity of the piggy bank for each upgrade
gp.player.set('offline-piggy-bank:max', 2 * currentCapacity);
// Save
gp.player.sync();
}
// Increase piggy bank capacity
public void UpgradePiggyBankCapacity() {
// Current capacity of the piggy bank
int currentCapacity = GP_Player.Get("offline-piggy-bank:max");
// Double the capacity of the piggy bank for each upgrade
GP_Player.Set("offline-piggy-bank:max", 2 * currentCapacity);
// Save
GP_Player.Sync();
}
Increase Piggy Bank Income
You can increase the amount of gold replenished per unit of time. This is useful when the game has a progression system, such as upgrading the piggy bank.
- JavaScript
- Unity
// Increase gold earned per second
async function upgradePiggyBankIncome() {
// Increase income per iteration by 1 gold for each upgrade
gp.player.add('offline-piggy-bank:incrementValue', 1);
// Save
gp.player.sync();
}
// Increase gold earned per second
public void UpgradePiggyBankIncome() {
// Increase income per iteration by 1 gold for each upgrade
GP_Player.Add("offline-piggy-bank:incrementValue", 1);
// Save
GP_Player.Sync();
}
Loyalty Points
Loyalty Points - an indicator of player activity. It's constantly decreases and need to be maintained at a certain level to receive additional loyalty bonuses. This mechanic helps encourage players to participate in activities and complete more levels to not lose privileges.
For example, you can create a table of privileges:
Level | Loyalty Points | Bonuses |
---|---|---|
Level 1 | 1000 | +10% gold per level |
Level 2 | 5000 | +10% experience per level |
Level 3 | 10000 | +10 diamonds per level |
Level 4 | 50000 | GamePush Mug (one-time) +100% gold per level |
For loyalty points, you need to create a player field loyalty
in the Players section of the project management panel as shown in the screenshot:
In this example of Loyalty:
- Cannot drop below 0 (Limit the range);
- Upon first login, 0 loyalty points (Default value);
- Every 1 hour (3600 seconds), 100 points are deducted (Automatically decremented variable).
Granting Privileges
At any time, you can refer to loyalty points to assign bonuses.
- JavaScript
- Unity
// Gold bonus for completing a level, depends on loyalty points
function goldBonusMultiplier() {
const loyalty = gp.player.get('loyalty');
// Base multiplier of 100% gold
let multiplier = 1;
// +10% when reaching 1,000 points
if (loyalty >= 1000) {
multiplier += 0.1;
}
// +100% when reaching 50,000 points
if (loyalty >= 50000) {
multiplier += 1;
}
return multiplier;
}
// Upon completing a level
function onLevelComplete() {
// Add 500 gold to the player considering the loyalty bonus multiplier
gp.player.add('gold', 500 * goldBonusMultiplier());
// Save
gp.player.sync();
}
// Gold bonus for completing a level, depends on loyalty points
private float GoldBonusMultiplier() {
int loyalty = GP_Player.Get('loyalty');
// Base multiplier of 100% gold
float multiplier = 1;
// +10% when reaching 1,000 points
if (loyalty >= 1000) {
multiplier += 0.1;
}
// +100% when reaching 50,000 points
if (loyalty >= 50000) {
multiplier += 1;
}
return multiplier;
}
// Upon completing a level
private void OnLevelComplete() {
// Add 500 gold to the player considering the loyalty bonus multiplier
GP_Player.Add("gold", 500 * goldBonusMultiplier());
// Save
GP_Player.Sync();
}
Adding Loyalty Points
Example of rewarding a player by adding loyalty points for completing a level.
- JavaScript
- Unity
async function onLevelComplete() {
// Increase loyalty points by 100
gp.player.add('loyalty', 100);
// Save
gp.player.sync();
}
private void OnLevelComplete() {
// Increase loyalty points by 100
GP_Player.Add('loyalty', 100);
// Save
GP_Player.Sync();
}
Example of rewarding a player by adding loyalty points for any purchase.
- JavaScript
- Unity
// Purchased any item
gp.payments.on('purchase', () => {
// Increase loyalty points by 1000
gp.player.add('loyalty', 1000);
// Player save will be within the purchase handling
});
// Purchased any item
GP_Payments.Purchase('Item1', OnPurchaseSuccess);
private void OnPurchaseSuccess(string productIdOrTag){
// Increase loyalty points by 1000
GP_Player.Add("loyalty", 1000);
// Player save will be within the purchase handling
switch(productIdOrTag){
case "Item1":
// Handle purchase
}
}
Example of rewarding a player by adding loyalty points for watching an ad.
- JavaScript
- Unity
// Player watched a rewarded ad
gp.ads.on('rewarded:reward', () => {
// Increase loyalty points by 200
gp.player.add('loyalty', 200);
// Player save will be within the ad call handling
});
// Show rewarded video
public void ShowRewarded() => GP_Ads.ShowRewarded("COINS", OnRewardedReward);
// Player watched a rewarded ad
private void OnRewardedReward(string value)
{
// Increase loyalty points by 200
GP_Player.Add("loyalty", 200);
// Player save will be within the ad call handling
switch(value){
// Handle rewarded reward
}
}
Freeze Loyalty Decrease
The ability to stop losing loyalty points will be an additional incentive for the player to make a purchase. For example, you can offer a "Loyalty Pass (7 days)" which allows stopping the decrease of loyalty points for 7 days. Or offer this option as part of a "VIP" status.
Let's consider an example with a subscription to the loyalty pass.
- JavaScript
- Unity
// Buy a loyalty pass
async function buyLoyaltyPass() {
// Subscribe to the loyalty pass
await gp.payments.subscribe({ tag: 'LOYALTY_PASS' });
// Freeze the decrease of loyalty points
gp.player.set('loyalty:incrementValue', 0);
// Save
gp.player.sync();
}
// Upon game start
async function onGameStart() {
// Check if the decrease of loyalty points is frozen
const isLoyaltyFrozen = gp.player.get('loyalty');
// Check for the presence of a subscription
if (gp.payments.has('LOYALTY_PASS')) {
// Subscription exists, but loyalty is not frozen
// There may have been issues with processing the purchase
if (!isLoyaltyFrozen) {
// Freeze the decrease of loyalty points
gp.player.set('loyalty:incrementValue', 0);
// Save
await gp.player.sync();
}
} else if (isLoyaltyFrozen) {
// Subscription expired but loyalty is still frozen
// Unfreeze the decrease of loyalty points
gp.player.set('loyalty:incrementValue', -100);
// Save
await gp.player.sync();
}
}
// Buy a loyalty pass
public void BuyLoyaltyPass() {
// Subscribe to the loyalty pass
GP_Payments.Subscribe("LOYALTY_PASS", OnSubscribeSuccess);
}
// The player has subscribed
private void OnSubscribeSuccess(string idOrTag){
if(idOrTag == "LOYALTY_PASS"){
GP_Player.Set("LOYALTY_PASS", true);
// Freeze the decrease of loyalty points
GP_Player.Set("loyalty:incrementValue", 0);
GP_Player.Set("loyaltyFrozen", true);
// Save
GP_Player.Sync();
}
}
// Upon game start
async function onGameStart() {
// Check if the decrease of loyalty points is frozen
const isLoyaltyFrozen = gp.player.get('loyalty');
// Check for the presence of a subscription
if (GP_Player.Has("LOYALTY_PASS")) {
// Subscription exists, but loyalty is not frozen
// There may have been issues with processing the purchase
if (!isLoyaltyFrozen) {
// Freeze the decrease of loyalty points
GP_Player.Set("loyalty:incrementValue", 0);
// Save
GP_Player.Sync();
}
} else if (isLoyaltyFrozen) {
// Subscription expired but loyalty is still frozen
// Unfreeze the decrease of loyalty points
GP_Player.Set("loyalty:incrementValue", -100);
// Save
GP_Player.Sync();
}
}
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!