Coupon Plugin

Coupons are a mechanic often used during active development or for community building. A player enters a coupon (e.g. SUMMER2025) and they are rewarded with something such as special items or a temporary boost.

The Coupon plugin handles the checking of coupons and awards the player with your existing Output. Coupons are hashed so that snoops cannot infer them from your source code.

Demo

You have 0 money!
GAIN10MONEY Available
GAIN100MONEY Available
Hash: 0

Usage

import { CouponPlugin } from '@123ishatest/ludiek';

const coupon = new CouponPlugin();

// Define your coupons
coupon.loadContent([
  {
    id: '/coupon/gain-10-money',
    hash: '282868016',
    output: { type: '/output/gain-currency', id: '/currency/money', amount: 10 },
  },
  {
    id: '/coupon/super-secret',
    hash: '1821260852',
    output: { type: '/output/earn-achievement', id: '/achievement/super-secret' },
  },
]);

// Check if a code is supported
coupon.supportsCode('/coupon/gain-10-money'); // True

// Enter a code
coupon.enterCode('SUMMER2025'); // True

// Check whether we have redeemed it
coupon.hasRedeemedCode('/coupon/gain-10-money'); // True

Hook into the “code redeemed earned” event for UI/popups.

coupon.onCouponRedeemed.subscribe((coupon) => {
  console.log(`You have redeemed '${coupon.id}'!`)
});

Links