Carnival Cannons
Based on game build 714014 | Last updated: 2026-03-04
Overview
The carnival_cannons file defines prefabs for decorative carnival cannons used in the Carnival event. These cannons support two activation paths: direct player interaction (OnActivate) and item-based trading via carnival_gametoken. Upon activation, they play a shooting animation, spawn a particle effect (confetti, sparkle, or streamer), enter a cooldown state, and optionally trigger a chained cannon if present. They also support inspection status display, work (hammer) interaction, and loot drop.
The prefabs are defined as three variants: carnivalcannon_confetti, carnivalcannon_sparkle, and carnivalcannon_streamer, each differing only in visual FX type.
Usage example
-- Example of manually firing a cannon instance
local cannon = Prefab("carnivalcannon_confetti")
cannon.components.activatable:OnActivate(cannon, player)
-- Or trigger via token trade
local item = CreateEntity()
item:AddTag("item")
item.prefab = "carnival_gametoken"
cannon.components.trader.onaccept(cannon, item)
-- Cannon cooldown resets automatically after 4 seconds via Enable()
Dependencies & tags
Components used: inspectable, lootdropper, carnivaldecor, trader, workable, activatable, burnable, propagator
Tags added: carnivaldecor, carnivalcannon, structure, cattoy
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
def | table | nil (set on master) | Stores cannon variant metadata (bank, build, fx) for FX spawning and setup. Set after TheWorld.ismastersim check. |
_lastchaintime | number | nil | Timestamp of last chain activation (set during chain firing). |
Main functions
FireCannon(inst, chain)
- Description: Initiates the cannon firing sequence: sets active, plays "shoot" then "cooldown" animation, spawns FX after 10 frames, and enables cooldown after 4 seconds. If
chainis true, schedules a chain-reaction trigger for the nearest inactive cannon within 4 units. - Parameters:
inst(Entity) – The cannon instance to fire.
chain(boolean) – Iftrue, attempts to trigger a linked cannon. - Returns: Nothing.
- Error states: No explicit error handling; relies on entity integrity and network sync.
OnActivate(inst, doer)
- Description: Callback for direct player activation (e.g., via quick action). Fires the cannon without chain propagation.
- Parameters:
inst(Entity) – Cannon instance.
doer(Entity) – Entity triggering activation (unused). - Returns:
true(indicates successful activation).
OnAcceptItem(inst, doer)
- Description: Callback for the
tradercomponent when a valid item is accepted. Fires the cannon with chain propagation (chain = true). - Parameters:
inst(Entity) – Cannon instance.
doer(Entity) – Entity accepting trade (unused). - Returns:
true.
AbleToAcceptTest(inst, item, giver)
- Description: Predicate used by
traderto determine if the cannon will accept a given item. Only acceptscarnival_gametokenand only while the cannon isinactive. - Parameters:
inst(Entity) – Cannon instance.
item(Entity) – Item being offered.
giver(Entity) – Item's owner (unused). - Returns:
trueifitem.prefab == "carnival_gametoken"andinst:HasTag("inactive");
false, "CARNIVALGAME_INVALID_ITEM"otherwise.
Enable(inst)
- Description: Marks the cannon as ready for reuse by setting
inactive = trueand playing the "idle" animation. - Parameters:
inst(Entity) – Cannon instance. - Returns: Nothing.
ChainActivate(inst)
- Description: Finds the nearest inactive cannon within radius
4(must have tags"carnivalcannon"and"inactive") and triggers itstrader.onacceptcallback. - Parameters:
inst(Entity) – Source cannon triggering the chain. - Returns: Nothing.
- Error states: No-op if entity is not awake or no matching cannon found.
GetStatus(inst)
- Description: Returns the current status string for inspection UI:
"COOLDOWN"when active,nilwhen inactive. - Parameters:
inst(Entity) – Cannon instance. - Returns:
"COOLDOWN"ornil.
onhammered(inst, worker)
- Description: Callback for
workable(HAMMER action). Spawns a "collapse_small" FX, drops loot, and removes the cannon entity. - Parameters:
inst(Entity) – Cannon instance.
worker(Entity) – Hammering entity (unused). - Returns: Nothing.
Events & listeners
-
Listens to:
onbuilt– TriggersOnBuilt, which plays "place" then "idle" animation and plays the placement sound. -
Pushes: None directly. Visual FX like "collapse_small" and loot are managed by
lootdropper:DropLoot()andSpawnPrefab.
Note:
inst.FireCannonis exposed as a public method, enabling external code to directly fire the cannon (e.g., via world events or scripts).