Carnival Crowkid
Based on game build 714014 | Last updated: 2026-03-04
Overview
carnival_crowkid defines the entity prefab for the Carnival Crowkid NPC, a seasonal trader that accepts specific food items in exchange for rewards during the Carnival event. It integrates the talker, trader, eater, locomotor, and timer components to handle dialogue, item trading, movement, and temporary snack possession logic. The entity uses a custom state graph and brain for behavioral control.
Usage example
local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddAnimState()
-- ... other entity setup ...
inst:AddComponent("talker")
inst:AddComponent("trader")
inst.components.trader:SetAcceptTest(function(inst, item, giver) return item.prefab == "corn_cooked" end)
-- ... additional initialization ...
Dependencies & tags
Components used: talker, named, locomotor, knownlocations, eater, trader, inspectable, fueler, timer, dynamicshadow, soundemitter, animstate, transform, network
Tags added: character, _named, NOBLOCK, trader
Tags removed (during initialization): _named (later re-added via named component)
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
shape | number | math.random(3) | Determines the scarf variant (1–3); controls scarf_1 symbol override. |
has_snack | string or nil | nil | Stores the prefab name of the currently held snack; resets when timer expires. |
ShouldFlyAway | boolean | not IsSpecialEventActive(SPECIAL_EVENTS.CARNIVAL) | If true, Crowkid will attempt to fly away instead of remain stationary. |
Main functions
SetScarfBuild(inst)
- Description: Updates the visual appearance of the scarf based on the
shapeproperty by overriding or clearing thescarf_1symbol in the animstate. - Parameters:
inst(Entity) – the entity instance. - Returns: Nothing.
OnTimerDone(inst, data)
- Description: Callback for timer completion; clears
inst.has_snackif the timer name matches"has_snack". - Parameters:
inst(Entity) – the entity instance.
data(table) – timer data containingnamefield. - Returns: Nothing.
AcceptTest(inst, item, giver)
- Description: Test function for the
tradercomponent; determines whether the Crowkid will accept the given item. - Parameters:
inst(Entity) – the entity instance.
item(Entity) – the item being offered.
giver(Entity) – the entity offering the item. - Returns:
trueifinst.has_snackisnilanditem.prefabis"corn_cooked"or"carnivalfood_corntea"; otherwisefalse.
OnGetItemFromPlayer(inst, giver, item)
- Description: Triggered upon successful trade; sets
has_snack, starts a timer to expire it, transitions to"give_reward"state, and removes the item. - Parameters:
inst(Entity) – the entity instance.
giver(Entity) – the entity offering the item.
item(Entity) – the accepted item. - Returns: Nothing.
OnRefuseItem(inst, giver, item)
- Description: Triggered when a trade is refused; plays a refusal or "already holding snack" dialogue via
talker:Say, unless the entity is taggedbusy. - Parameters:
inst(Entity) – the entity instance.
giver(Entity) – the entity offering the item.
item(Entity) – the refused item. - Returns: Nothing.
onsave(inst, data)
- Description: Serialization hook; stores
shapeandhas_snackinto save data. - Parameters:
inst(Entity) – the entity instance.
data(table) – save data table. - Returns: Nothing.
onload(inst, data)
- Description: Deserialization hook; restores
shapeandhas_snack, then reapplies scarf build. - Parameters:
inst(Entity) – the entity instance.
data(table) – loaded save data (may benil). - Returns: Nothing.
Events & listeners
- Listens to:
timerdone– triggersOnTimerDonewhen timers complete.