Skip to content

Creating a Basic Effect ​

An effect has two parts: a resource holding what viewers see in the menu (name, price, description), and a script deciding what happens in the game when someone buys it.

Create the Effect List ​

All effects of a game live in one CCEffectEntries resource.

  1. In the FileSystem dock, right-click and choose Create New > Resource..., then pick CCEffectEntries.
  2. Save it as res://effects.tres, or anywhere else and set crowd_control/common/effects to its path.

Write the Effect Script ​

Create a script that extends CCEffect and give it a class_name:

gdscript
class_name CCDamage
extends CCEffect


func _trigger(_instance: CCEffectInstance) -> EffectResult:
	GameManager.instance.player.damage(1)
	return SUCCESS


func _can_run() -> bool:
	return GameManager.instance != null and GameManager.instance.player.alive

_trigger() is required. _can_run() is optional and is checked first.

Effects are resources, not nodes, so they have no scene tree of their own. Reach your game through an autoload or a static reference, as GameManager.instance does above.

Add It to the List ​

  1. Open your CCEffectEntries resource in the Inspector.
  2. Add an element to Effects and choose New CCDamage.
  3. Fill in its properties.
PropertyUse
idUnique ID of the effect, for example damageplayer. Letters, numbers, and underscores only. Required.
display_nameName shown to viewers.
descriptionDescription shown to viewers, up to 512 characters.
priceDefault price in coins. Streamers can change it for their channel.
iconIcon shown in the effect menu. Exported with your effect pack.
categoriesCategories the effect is listed under in the menu.
groupsGroups the effect belongs to.
moralityWhether the effect helps (Good) or hurts (Evil) the player.
orderlinessWhether the effect is Orderly or Chaotic.
noteShort note shown next to the name.
session_maxHow often the effect can be bought per session, 0 for no limit.
pooling_disabledViewers may not pool coins for this effect.
conflictsIDs of effects this one cannot run alongside, see Controlling the Effect Menu.
max_retries, retry_delayHow often and how many seconds apart the effect is retried, see below.
icon_colorFor your own overlay; not sent to Crowd Control.

What the Script Returns ​

The plugin answers Crowd Control based on the result of _trigger():

ResultMeaningViewer
SUCCESSThe effect happened.Charged.
FAILUREIt could not happen right now.Refunded.
UNAVAILABLEIt cannot happen at all, for example because the effect is obsolete.Refunded.
RETRYNot now, try again shortly.Waits.

When _can_run() returns false or _trigger() returns RETRY, the request is tried again every retry_delay seconds, up to max_retries times (3 times, 5 seconds apart by default). If it still cannot run, the viewer is refunded.

A request is never held for more than 55 seconds. Requests that could not start by then are refunded automatically, so you do not have to answer them yourself.

WARNING

Every effect must implement _trigger() and return one of the results above. An effect without it is answered as unavailable and an error is printed.

The Request ​

_trigger() receives a CCEffectInstance describing the request:

gdscript
func _trigger(instance: CCEffectInstance) -> EffectResult:
	var viewer: StreamUser = instance.get_user()
	print("%s bought %s" % [viewer.name, instance.get_effect().display_name])
	return SUCCESS
MethodUse
get_user()The viewer as a StreamUser (name, profile_icon). The icon is downloaded in the background; icon_downloaded is emitted on the user when it is there. Anonymous and test requests come from a placeholder user.
get_effect()The effect resource.
get_id()The ID of this request.
is_test()Whether this is a test rather than a purchase.

Reacting Outside the Effect ​

The singleton reports every step, which is what an overlay or a log needs:

SignalWhen
effect_requested(effect)A request arrived.
effect_queued(instance)The request is waiting to start.
effect_triggered(instance)An effect ran successfully.
effect_dequeued(id, result)The request left the queue, with its result.

Next Step ​

Continue with Creating a Parameter Effect.