Skip to content

Creating new effects in VScript

Mikusch edited this page Aug 26, 2023 · 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:

// The name of the function needs to be `Chaos_OnGameEvent_name`
function Chaos_OnGameEvent_player_spawn(params)
{
    local player = GetPlayerFromUserID(params.userid)
    if (player == null)
        return

    // Your code here
}

// Do not use the base `__CollectEventCallbacks` function
Chaos_CollectEventCallbacks(this)

Chaos also offers a chaos_util.nut file that can be included in your effect script:

IncludeScript("chaos_util")
Clone this wiki locally