Skip to content

Creating new effects in VScript

Mikusch edited this page Dec 19, 2024 · 6 revisions

For full context, please read Creating new effects in SourcePawn first, even if you do not plan on working with it.

The Squirrel API is very similar to the SourcePawn API, but it only has 3 callbacks: OnStart, Update, and OnEnd.

As usual, add your effect to the effect config:

"my_effect"
{
    "name"          "#Chaos_Effect_MyEffect"
    "duration"      "60"
    "script_file"   "myeffect"
}

Then, create a new file for your effect in scripts/vscripts/chaos/effects. It is not needed to prefix each callback with the effect name, because all functions are put into their own scope. The name of this scope can be accessed using the Chaos_EffectName variable.

// Called once when the effect starts
function ChaosEffect_OnStart()
{
    // Returning `false` will prevent the effect from starting
    if (!GamemodeUsesCurrency())
        return false

    // Returning `true` or `null` (no return) will allow the effect to start
    return true
}

// Called repeatedly every frame
function ChaosEffect_Update()
{
    // Your code here
}

// Called once when the effect ends (except for one-shot effects)
function ChaosEffect_OnEnd()
{
    // Your code here
}

You can also hook events in your effect. Chaos has its own implementation of game events to ensure that external scripts can not clear the event callbacks. Do not call __CollectGameEventCallbacks or ClearGameEventCallbacks yourself, as the master script handles that for you.

Chaos also offers a util.nut file that is automatically included in every effect.

Clone this wiki locally