Creating a Timed Effect
A timed effect changes the game for a duration and undoes the change afterwards. The plugin keeps the timer, calls your script when the effect starts and ends, and reports each step to Crowd Control.
Write the Script
Extend CCEffectTimed and implement _start() and _stop():
class_name CCInvertControls
extends CCEffectTimed
func _start(_instance: CCEffectInstanceTimed) -> EffectResult:
GameManager.instance.player.controls_inverted = true
return RUNNING
func _stop(_instance: CCEffectInstanceTimed, _force := false) -> bool:
GameManager.instance.player.controls_inverted = false
return true
func _can_run() -> bool:
return GameManager.instance != null and GameManager.instance.player.alive| Method | Required | Use |
|---|---|---|
_start(instance) | yes | Apply the change. Return RUNNING when it is active, or FAILURE, UNAVAILABLE, or RETRY as for a basic effect. |
_stop(instance, force) | yes | Undo the change and return true. When force is true the effect has to stop no matter what. |
_pause() | no | The effect was paused. |
_resume() | no | The effect continues. |
_reset() | no | The timer was reset to the full duration. |
_stop() is called when the time runs out, when the session ends, and when Crowd Control or the streamer ends the effect early. Write it so it is safe to call in each case.
Duration
Set Duration on the resource, in seconds. This is the default that ends up in your effect pack; the pack accepts whole seconds from 1 to 600.
Streamers can change the duration for their channel, and the request carries the final value. Read it from the instance instead of the resource:
func _start(instance: CCEffectInstanceTimed) -> EffectResult:
hud.show_timer(instance.get_duration())
return RUNNINGinstance.get_time_left() returns the seconds remaining while the effect runs.
Pause and Resume
Timers stop while CrowdControl.paused is true and continue afterwards. Viewers see the same.
To pause a single effect, call CrowdControl.pause_effect(effect) and CrowdControl.resume_effect(effect) with the effect resource. CrowdControl.reset_effect(effect) restarts its timer, and CrowdControl.stop_effect(instance) ends it early.
A Second Request While One Is Running
Only one instance of a timed effect runs at a time. A second request for the same effect waits for the first one to end and then starts.
It waits for up to 55 seconds. If the first one is still running by then, the second request is refunded.
Signals
| Signal | When |
|---|---|
effect_started(instance) | A timed effect started. |
effect_stopped(instance) | It ended, for any reason. |
effect_paused(instance), effect_resumed(instance) | It was paused or resumed through pause_effect() / resume_effect(). |
effect_reset(instance) | Its timer was reset. |
Next Step
Continue with Controlling the Effect Menu.
