Bait
Based on game build 714014 | Last updated: 2026-03-03
Overview
The Bait component enables an entity to function as bait for traps. It tracks an optional association with a trap entity (self.trap) and responds to key lifecycle events (onremove, onpickup, oneaten, onstolen) to notify the trap of bait state changes. When the bait is removed or stolen without a connected trap, it attempts to give itself to the thief’s inventory.
Usage example
local inst = Prefab("bait_item", ...)
inst:AddComponent("bait")
-- Attach to a trap (e.g., a snare)
inst.components.bait.trap = some_trap
-- When bait is eaten, stolen, or removed, the trap is notified automatically.
Dependencies & tags
Components used: inventory (accessed only on thieves during onstolen when no trap is attached)
Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
trap | entity or nil | nil | Reference to the trap this bait is attached to. Set externally; not managed by this component. |
Main functions
GetDebugString()
- Description: Returns a string representation for debugging, showing the current trap reference.
- Parameters: None.
- Returns:
string— formatted as"Trap:"..tostring(trap), e.g.,"Trap:table"or"Trap:nil".
IsFree()
- Description: Indicates whether this bait is currently unattached to any trap.
- Parameters: None.
- Returns:
boolean—trueiftrapisnil, otherwisefalse.
OnRemoveFromEntity()
- Description: Cleanup function called when the component is removed from its entity. Unregisters all event callbacks to prevent memory leaks.
- Parameters: None.
- Returns: Nothing.
Events & listeners
-
Listens to:
onremove— triggersOnRemove, which notifies the attached trap (if any) viatrap:RemoveBait().onpickup— triggersOnRemove, same behavior as above.oneaten— triggersOnEaten, which notifies the attached trap viatrap:BaitTaken(eater)if attached.onstolen— triggersOnStolen:- If a trap is attached, calls
trap:BaitTaken(thief). - Otherwise, gives the bait entity to the thief’s inventory via
thief.components.inventory:GiveItem(inst).
- If a trap is attached, calls
-
Pushes: None.