Skip to content

Creating new effects in SourcePawn

Mikusch edited this page Feb 5, 2023 · 4 revisions

The SourcePawn API allows developers to access effect data such as name, duration, or a custom-defined data section.

The ChaosEffect struct is always passed into callbacks as the first parameter. This struct should not be modified, as changes to it may affect subsequent effect activations.

To get started, create a config entry in configs/effects.cfg, with the section name being the unique ID of the effect. In addition, each effect requires at least a name and an effect class. All other keys are optional and will be initialized to a default value.

"my_effect"
{
    "name"          "#Chaos_Effect_MyEffect"
    "duration"      "60"
    "effect_class"  "MyEffect"
    "data"
    {
        "key"    "value"
    }
}

Then, create a new file for your effect in scripting/chaos/effects:

#pragma semicolon 1
#pragma newdecls required

public bool MyEffect_OnStart(ChaosEffect effect)
{
    // Called once when the effect starts
    
    // Return true to start the effect, false to abort
    return true;
}

public void MyEffect_Update(ChaosEffect effect)
{
    // Called every frame
}

public void MyEffect_OnEnd(ChaosEffect effect)
{
    // Called once when the effect ends
}

Finally, include your effect at the top of chaos.sp:

#include "chaos/effects/myeffect.sp
Clone this wiki locally