Skip to content

Registering & Adding Status Effects

BenevolusGoat edited this page Jan 27, 2025 · 3 revisions

All the basic information you need on creating a simple status effect


Registering a status effect

In order to apply a custom status effect, you need to register it first.

StatusEffectLibrary.RegisterStatusEffect(string identifier, Sprite? icon, Color? color, EntityFlag? ignoreFlags, boolean? customTargetCheck, boolean? staticIconPosition): StatusConfig

Register your status effect with a variety of options, which then returns the configuration data created for it if needed. All values with a question mark means they're optional

  • identifier: The unique string name for your status effect. This is converted into an enum under StatusFlag. So, if you used "MY_EFFECT" as your identifier, your enum would be StatusEffectLibrary.StatusFlag.MY_EFFECT.
  • icon: Optional. If your status effect involves an icon to render above the entity, provide a Sprite object. It will render for the duration of the effect. This sprite will be COPIED and not used as a direct render!
  • color: Optional. If your status effect changes the color of an enemy, provide a Color object. It will be applied constantly until the effect ends.
  • ignoreFlags: Optional. When bosses receive most of any status effects, they cannot receive another one until a custom countdown timer has expired. Sometimes your status effects may involve the use of vanilla effects. Define the respective EntityFlag(s) so that one doesn't block out the other.
  • customTargetCheck: Optional. When applying a status effect, the library has a custom check it goes through to determine if that entity should have a status effect applied or not. Set this to true if you wish to override this check, allowing you to do a custom check yourself.
  • staticIconPosition: Optional. Some icons are more literal floating icons above the entity's head. Some are meant to be attached to the head, like posion, burn, and charm. Set this to true if you wish this icon to not change positions when other icons are present.

An example from the main.lua:

local SEL = StatusEffectLibrary

local smilyFace = Sprite()
smilyFace:Load("gfx/status_effect_smiley_face.anm2", true)
smilyFace:Play("Idle", true)

SEL.RegisterStatusEffect(
	"SMILY_FACE",
	smilyFace
)

Applying your status effect

With your status effect registered, or if you want to use one from another mod, you can now apply it to an entity.

StatusEffectLibrary:AddStatusEffect(EntityPlayer | EntityNPC ent, StatusFlag statusFlag, integer duration, EntityRef source, Color? color, table? customData): boolean

Apply your status effect to an enemy or player. Returns a boolean on if it was successful applying the effect or not.

  • ent: The target of this status effect, being an EntityPlayer or EntityNPC. Entity also works, so long as the :ToPlayer() or ToNPC() type conversions can work on them.
  • statusFlag: The bitflag of the status effect being applied. You should use the StatusEffectLibrary.StatusFlag enumeration table for convenience.
  • duration: The duration of the effect before it is removed. 30 = One (1) second.
  • EntityRef: The source of the effect. Remember that the provided EntityRef can also be nil, but it cannot be nil itself.
  • color: Optional. Apply a color for this specific application of the status effect. Will override any default color provided by the StatusConfig of the effect.
  • customData: Optional. A table for arbitrary data you can do whatever you want with.

An example from the main.lua:

local function happyTime(_, npc)
	-- -1 for infinite duration
	SEL:AddStatusEffect(npc, SEL.StatusFlag.SMILY_FACE, -1, EntityRef(npc))
end

SELExample:AddCallback(ModCallbacks.MC_POST_NPC_INIT, happyTime)