Sgcritter Common
Based on game build 718694 | Last updated: 2026-04-04
Overview
SGcritter_common is a utility module that provides reusable state and event definitions for building critter entity stategraphs. It contains helper functions in the SGCritterStates and SGCritterEvents tables that modders can use to add common critter behaviors like idling, eating, emotes, combat avoidance, playful interactions, and walking. This module integrates with the locomotor, crittertraits, and follower components to manage critter movement and trait-based behavior.
Usage example
local states = {}
local events = {}
local actionhandlers = {}
-- Add common critter states
SGCritterStates.AddIdle(states, 3, nil, nil)
SGCritterStates.AddEat(states, nil, nil)
SGCritterStates.AddHungry(states, nil)
SGCritterStates.AddWalkStates(states, nil, false)
-- Add common critter events
table.insert(events, SGCritterEvents.OnEat())
table.insert(events, SGCritterEvents.OnAvoidCombat())
return StateGraph("SGCritter", states, events, "idle", actionhandlers)
Dependencies & tags
Components used: locomotor, crittertraits, follower
Tags: Adds idle, canrotate, busy, moving, softstop, playful (varies by state)
Properties
No public properties. This is a utility module with helper functions, not a class with instance properties.
Main functions
SGCritterEvents.OnEat()
- Description: Returns an event handler that transitions the critter to the
eatstate when theoneatevent fires. - Parameters: None.
- Returns:
EventHandlerobject for theoneatevent.
SGCritterEvents.OnAvoidCombat()
- Description: Returns an event handler that sets the
avoidingcombatmemory flag when thecritter_avoidcombatevent fires. - Parameters: None.
- Returns:
EventHandlerobject for thecritter_avoidcombatevent.
SGCritterEvents.OnTraitChanged()
- Description: Returns an event handler that transitions to the
emote_cutestate when thecrittertraitchangedevent fires, or queues the transition if the critter is currently busy. - Parameters: None.
- Returns:
EventHandlerobject for thecrittertraitchangedevent.
SGCritterStates.AddIdle(states, num_emotes, timeline, idle_anim_fn)
- Description: Adds an
idlestate to the states table with logic for random emotes, trait-based behavior, and queued actions. - Parameters:
states(table) - the states table to insert into.num_emotes(number) - number of emote variations.timeline(table) - optional timeline data.idle_anim_fn(function) - optional function receivinginstand returning idle animation name. - Returns: Nothing. Modifies the
statestable in place.
SGCritterStates.AddEat(states, timeline, fns)
- Description: Adds an
eatstate with pre, loop, and post eat animations. - Parameters:
states(table) - the states table to insert into.timeline(table) - optional timeline data.fns(table) - optional table withonenterandonexitcallbacks. - Returns: Nothing. Modifies the
statestable in place.
SGCritterStates.AddHungry(states, timeline)
- Description: Adds a
hungrystate that plays a distress animation. - Parameters:
states(table) - the states table to insert into.timeline(table) - optional timeline data. - Returns: Nothing. Modifies the
statestable in place.
SGCritterStates.AddNuzzle(states, actionhandlers, timeline, fns)
- Description: Adds a
nuzzlestate and registers theNUZZLEaction handler. - Parameters:
states(table) - the states table to insert into.actionhandlers(table) - the actionhandlers table to insert into.timeline(table) - optional timeline data.fns(table) - optional table withonenterandonexitcallbacks. - Returns: Nothing. Modifies the
statesandactionhandlerstables in place.
SGCritterStates.AddRandomEmotes(states, emotes)
- Description: Adds multiple emote states based on the provided emotes table configuration. States are named
emote_1,emote_2, etc., corresponding to the index in theemotesarray. - Parameters:
states(table) - the states table to insert into.emotes(table) - array of emote configurations withtags,anim,timeline,fns, andignorestandardonenterfields.fnscan containonenter,animover, andonexitcallbacks.ignorestandardonenter(boolean) - if true, skips default locomotor stop and animation play. - Returns: Nothing. Modifies the
statestable in place.
SGCritterStates.AddEmote(states, name, timeline)
- Description: Adds a single named emote state.
- Parameters:
states(table) - the states table to insert into.name(string) - the emote name suffix.timeline(table) - optional timeline data. - Returns: Nothing. Modifies the
statestable in place.
SGCritterStates.AddPetEmote(states, timeline, onexit)
- Description: Adds an
emote_petstate that pushes thecritter_onpetevent on completion. - Parameters:
states(table) - the states table to insert into.timeline(table) - optional timeline data.onexit(function) - optional exit callback. - Returns: Nothing. Modifies the
statestable in place.
SGCritterStates.AddCombatEmote(states, timelines)
- Description: Adds three combat-related states:
combat_pre,combat_loop, andcombat_pst. - Parameters:
states(table) - the states table to insert into.timelines(table) - optional table withpre,loop, andpsttimeline data. - Returns: Nothing. Modifies the
statestable in place.
SGCritterStates.AddPlayWithOtherCritter(states, events, timeline, onexit)
- Description: Adds playful interaction states (
playful,playful2) and event handlers for critter-to-critter play. - Parameters:
states(table) - the states table to insert into.events(table) - the events table to insert into.timeline(table) - optional table withactiveandpassivetimeline data.onexit(table) - optional table withactiveandinactiveexit callbacks. - Returns: Nothing. Modifies the
statesandeventstables in place.
SGCritterStates.AddWalkStates(states, timelines, softstop)
- Description: Adds three walking states:
walk_start,walk, andwalk_stopwith optional soft stopping behavior. - Parameters:
states(table) - the states table to insert into.timelines(table) - optional table withstarttimeline,walktimeline, andendtimelinedata.softstop(boolean or function) - enables gradual speed reduction on stop. If function, receivesinstas argument. - Returns: Nothing. Modifies the
statestable in place.
Events & listeners
- Listens to:
oneat,critter_avoidcombat,crittertraitchanged,animover,animqueueover,start_playwithplaymate,critterplaywithme - Pushes:
critter_doemote(to leader),critter_onnuzzle,critter_onpet,oncritterplaying