npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rbxts/reward-containers

v1.0.1

Published

A generic, type-safe library for Roblox game development, written using roblox-ts, for granting rewards to players through containers.

Downloads

33

Readme

Reward Containers

Reward Containers is a package for Roblox game developers with built-in persistence (as makes sense) that can be swapped modularly to fit into any game's persistence schemes. Reward Containers provide a framework for granting your players rewards. From simple things like badges to virtual currency and even loot boxes. The point to Reward Containers is to provide a simple, modular system for rewarding players in games.

Installation

roblox-ts

Simply install to your roblox-ts project as follows:

npm i @rbxts/reward-containers

Wally

Wally users can install this package by adding the following line to their Wally.toml under [dependencies]:

RewardContainers = "bytebit/[email protected]"

Then just run wally install.

From model file

Model files are uploaded to every release as .rbxmx files. You can download the file from the Releases page and load it into your project however you see fit.

From model asset

New versions of the asset are uploaded with every release. The asset can be added to your Roblox Inventory and then inserted into your Place via Toolbox by getting it here.

Documentation

Documentation can be found here, is included in the TypeScript files directly, and was generated using TypeDoc.

Example

Let's see how to use this system to build a daily rewards system where users can come in, open their rewards, and then they lock for 24 hours. To start, we need to define our reward granters by their reward type in a map, like so:

import { VirtualCurrencyRewardGranter } from "@rbxts/reward-containers";

type CurrencyType = "coins" | "gems";

// Note we are assuming the currencyService here. In reality, this callback should be implemented to your game's specifications for virtual currency
const virtualCurrencyRewardGranter = VirtualCurrencyRewardGranter.create<CurrencyType>(
	(rewardedPlayer, currencyType, value) =>
		currencyService.awardCurrencyToPlayerAsync(rewardedPlayer, currencyType, value),
);

const rewardGrantersByType = new Map([["VirtualCurrency", virtualCurrencyRewardGranter]]);

Note that you can implement your own reward granters and use them here! VirtualCurrencyRewardGranter and BadgeRewardGranter are provided as part of the package and can serve as examples.

For this daily reward system, we'll be granting players one random reward every day they join from a list of rewards. You could list more, but for now let's just put an 80% chance at 100 coins and a 20% chance at 100 gems, like so:

import { WeightedRewardsSelector } from "@rbxts/reward-containers";

const rewardsSelector = WeightedRewardsSelector.create(
    1, // maximumNumberOfRewards
    [
        {
            reward: {
                type: "VirtualCurrency",
                currencyType: "coins",
                value: 100,
            },
            weight: 80,
        },
        {
            reward: {
                type: "VirtualCurrency",
                currencyType: "gems",
                value: 100,
            },
            weight: 20,
        },
    ],
    1, // value
)

The last thing we'll need before we're ready to create our reward container is a rewards opening coordinator. We'll use the standard one, like so:

import { StandardRewardsOpeningCoordinator } from "@rbxts/reward-containers";

const rewardsOpeningCoordinator = StandardRewardsOpeningCoordinator.create(rewardGrantersByType, rewardsSelector);

And now we're ready to set up our reward container that will have a 24-hour recurrence interval - aka our daily reward container! These need to be tied to a player, so we'll set this up in a player added handler.

import { Players } from "@rbxts/services";
import { RecurringTimeLockedRewardContainer } from "@rbxts/reward-containers";

Players.PlayerAdded.Connect((player) => {
    const rewardContainerForPlayer = RecurringTimeLockedRewardContainer.create(
        "DailyRewardContainer", // name
        24 * 60 * 60, // recurrenceIntervalInSeconds - set to 24 hours in seconds
        player, // rewardedPlayer
        rewardsOpeningCoordinator,
    );
});

Now just hook this up to your system for communicating to things to the client and providing a UI, and you're done!