Skip to content

Creating a Parameter-Based Effect

A Parameter Effect allows players specify the quantity of the item being sent through, or a specific parameter. For our parameter effect, we will be creating a effect that lets a viewer specify the amount of coins they want to give to the streamer.

Inside of the "CC Effects" Folder, create a class called "CCGiveCoins". Open up the class. Make sure we are using the WarpWorld.CrowdControl and CrowdControlSampleGame namespaces.

The initial class should look like this:

cs
using WarpWorld.CrowdControl;
using CrowdControlSampleGame;

public class CCGiveCoins : CCEffectParameters
{
    protected override EffectResult OnTriggerEffect(CCEffectInstanceParameters effectInstance) {
        return EffectResult.Success;
    }
    public override bool CanBeRan() {
        return true;
    }
}

This setup is similar to the basic effect, except we are now receiving an instance of CCEffectInstanceParameters. This holds information of the parameters sent through by the viewer.

There are two ways to access this information. GetParameter for an item type parameter, and GetQuantity for a quantity based. Since this effect needs the amount of coins requested, we will use GetQuantity, and pass in "Total Coins".

Calling Player.Instance.GiveCoins(amount) will return true if it's able to add coins (if the sum will be less than the max, which is 99). If it's false, the attempt will try again later.

The OnTriggerEffect class should now look look like this:

cs
using WarpWorld.CrowdControl;

namespace CrowdControlSampleGame {
    public class CCGiveCoins : CCEffectParameters {
        protected override EffectResult OnTriggerEffect(CCEffectInstanceParameters effectInstance) { 
            if (Player.Instance.GiveCoins(effectInstance.GetQuantity("Total Coins"))) 
                return EffectResult.Success;

            return EffectResult.Retry;
        }

        public override bool CanBeRan() {
            return !Player.Instance.Dead;
        }
    }
}

Now that we have completed our class:

Click on the Crowd Control Manager Prefab in the scene’s hierarchy and expand it.

Click on "CC Effects" and go into the inspector. You'll see the "Force Jump" class still there. We will attach this new class to the prefab. The new class display is identical to the first one, but with a new list of "Parameter Types". We can add multiple parameter types for players to choose from, but for this effect we only need one. Set the amount to 1 and expand the entry to see its details.

There are two parameter types: Item and Quantity

  • Item: A list of strings that the viewer can choose from when activating the effect. The viewer’s choice is returned to the streamer.
  • Quantity: Specifies a minimum and maximum numeric value the viewer can send to the streamer.

Since we want to specific the amount of coins the player should receive, we will use the Quantity type for this effect. The maximum amount of coins a player can hold is 99, so let’s set the minimum to 1 and the maximum to 99. Name the effect “Give Coins”, the name of the parameter type “Total Coins” and fill out the other fields appropriately.

Alt

The inspector also has a "Test Parameter" field, which you can use to test specific parameters for that type if triggering it from the inspector.

Start a new session, load up the menu again. Selecting the effect will present the viewer with an additional menu where the amount of coins for this effect can be set. The amount of Crowd Control coins required increase with the quantity. After selecting "order", the player should receive coins if they're able to hold enough. If not, the effect will retry again (per the Retry Count) and if it's out of tries, will fail and refund the viewer.

Congratulations! You've just added an effect that gives the viewer options!