Skip to content

Creating a Parameter-Based Effect

A Parameter Effect allows players specify values such as the quantity or type of an effect.

Quantity Parameters

As it is the most common type, quantity is a special parameter with additional handling. Unlike other parameters, the price of the effect will scale with the quantity specified by the viewer. The price is calculated as (Base Cost * Quantity). This allows you to have a base cost for the effect, but also charge more for higher quantities.

The effect class should look like this:

cs
using CrowdControl.Client.Unity;
using CrowdControl.Common;
using UnityEngine;

namespace Assets.Scripts.Crowd_Control.Effects
{
    internal class ExampleEffect : UnityEffectBase
    {
        public override EffectStatus StartEffect(EffectRequest request)
        {
            Debug.Log($"ExampleEffect started with quantity: {request.Quantity}...");
            return EffectStatus.Success;
        }
    }
}

Non-Quantity Parameters

For other types of parameters, such as item parameters, the viewer can choose from a list of options that you provide. Parameters are accessed by their name, which is defined when you set up the effect in the inspector.

Alt

Parameters have an ID, Name, Type. The "Options" type also permits a list of options that the viewer can choose from, which is defined in the inspector.

ID

The ID is used by the Crowd Control service and effect code to identify the parameter.

Name

The Name is a human-readable identifier for the parameter, which is displayed to the viewer in the UI.

Type

The Type defines the kind of value the parameter can hold. The available types are "Options" and "Hex Color". The "Options" type allows you to provide a list of options for the viewer to choose from, while the "Hex Color" type allows the viewer to specify a color using a hex code.

Options

The "Options" type allows you to create a parameter that lets viewers select from a list of choices. Each option has its own name and value, which can be found in the effect request to determine the specific option chosen by the viewer.

You can have as many parameters as you want for an effect, and they can be of different types. Non-quantity parameters do not have any special handling, so the price of the effect will not scale with the parameters specified by the viewer.

The effect class should look like this:

cs
using CrowdControl.Client.Unity;
using CrowdControl.Common;
using UnityEngine;

namespace Assets.Scripts.Crowd_Control.Effects
{
    internal class ExampleEffect : UnityEffectBase
    {
        public override EffectStatus StartEffect(EffectRequest request)
        {
            //example with a single parameter called "stringValue" of type **Options**
            Debug.Log($"ExampleEffect started with stringValue: {(string)request.Parameters["stringValue"].Value}.");

            return EffectStatus.Success;
        }
    }
}