Joustuser
Overview
The JoustUser component manages jousting state and behavior for an entity by enabling customizable callbacks for joust eligibility (CanJoust), initiation (StartJoust), and termination (EndJoust), as well as performing safety checks to prevent jousting near map edges via the CheckEdge method. It does not manage jousting state directly but acts as a utility for coordinating external joust logic.
Dependencies & Tags
- Requires the
TransformandMapsystems viaTheWorld.Mapfor position and terrain queries. - No components are added or removed by this script.
- No tags are applied or removed.
- None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil (assigned in constructor) | Reference to the owning entity instance. |
edgedistance | number | 2 | Radial distance (in tiles) used to sample terrain for edge detection around the entity. |
canjoustfn | function? | nil | Optional callback that validates whether a joust is allowed; returns true or a fail reason. |
onstartjoustfn | function? | nil | Optional callback executed when a joust begins. |
onendjoustfn | function? | nil | Optional callback executed when a joust ends. |
Main Functions
SetCanJoustFn(fn)
- Description: Sets a custom function that determines whether the joust is valid to proceed. The function receives the entity instance and may return
true(allow joust),false(deny joust), or a string fail reason. - Parameters:
fn(function) – A predicate function with signaturefn(entity) → boolean|string.
CanJoust()
- Description: Returns
trueif no custom validation function is set, or invokes thecanjoustfnto check if jousting is allowed. Used to gate joust initiation. - Parameters: None.
SetOnStartJoustFn(fn)
- Description: Registers a callback function to execute when a joust starts.
- Parameters:
fn(function) – A callback with signaturefn(entity).
StartJoust()
- Description: Invokes the registered
onstartjoustfncallback if it exists, signaling the beginning of a joust action. - Parameters: None.
SetOnEndJoustFn(fn)
- Description: Registers a callback function to execute when a joust ends.
- Parameters:
fn(function) – A callback with signaturefn(entity).
EndJoust()
- Description: Invokes the registered
onendjoustfncallback if it exists, signaling the end of a joust action. - Parameters: None.
CheckEdge()
- Description: Checks for dangerous terrain edges in three angular directions (±30° around the entity's facing direction). Returns
trueonly if an edge (non-ground or blocked ground) is detected at all three sample points — a conservative safety check to prevent jousting near cliffs or voids. - Parameters: None.
SetEdgeDistance(distance)
- Description: Updates the radial distance (in tiles) used for sampling terrain around the entity during edge checks.
- Parameters:
distance(number) – New edge-detection radius.
Events & Listeners
None.