Hitcher
Overview
The Hitcher component enables an entity (typically a character or vehicle) to act as a hitcher—assigning it to be hitched to a hitchable target entity or releasing it. It tracks hitching state, locking status, and updates relevant entity tags (hitcher, hitcher_locked) accordingly.
Dependencies & Tags
- Component Dependencies: None declared directly, but relies on
hitchablecomponent being present on hitch targets for properSetHitchedandUnhitchbehavior. - Tags Added/Removed:
- Adds
hitchertag whencanbehitchedistrue. - Removes
hitchertag whencanbehitchedbecomesfalse. - Adds
hitcher_lockedtag whenlockedistrue. - Removes
hitcher_lockedtag whenlockedbecomesfalse.
- Adds
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
hitched | entity or nil | nil | Reference to the entity this hitcher is currently attached to. |
canbehitched | boolean | true | Controls whether the entity is eligible to be hitched (also triggers the hitcher tag). |
locked | boolean | false | Indicates if the hitcher is locked (also triggers the hitcher_locked tag). |
hitchedfn | function or nil | nil | Optional callback invoked when hitching occurs. |
unhitchfn | function or nil | nil | Optional callback invoked when unhitching occurs. |
Main Functions
GetHitched()
- Description: Returns the current hitched entity reference, or
nilif not hitched. - Parameters: None.
SetHitched(target)
- Description: Assigns this hitcher to a new target entity. Disables further hitching (
canbehitched = false), notifies the target’shitchablecomponent (if present), and invokes the optionalhitchedfncallback. - Parameters:
target: The entity to hitch to. Must (ideally) have ahitchablecomponent.
Unhitch()
- Description: Releases the current hitched target, restores hitching eligibility (
canbehitched = true), notifies the target’shitchablecomponent if needed, invokesunhitchfncallback (if set), clears internal state, and pushes an"unhitched"event. - Parameters: None.
Lock(setting)
- Description: Sets the
lockedstate of the hitcher. Controls whether thehitcher_lockedtag is applied. - Parameters:
setting:boolean–trueto lock,falseto unlock.
OnSave()
- Description: Prepares data for saving (currently returns an empty table—no state is persisted beyond default defaults).
- Parameters: None.
OnLoad(data)
- Description: Restores saved state (currently a no-op—does not restore any persisted data).
- Parameters:
data: Placeholder—unused.
Events & Listeners
- Listens For:
canbehitchedproperty change → triggersonhitched()handlerlockedproperty change → triggersonlocked()handler
- Pushes Events:
"unhitched"(duringUnhitch())