Skip to main content

Lightningblocker

Overview

This component enables an entity to act as a lightning strike blocker: it dynamically applies or removes the "lightningblocker" tag based on a configurable blocking range squared (block_rsq). It also supports registering a callback to execute custom logic when a lightning strike occurs at the entity's location.

Dependencies & Tags

  • Adds/Removes the "lightningblocker" tag on the entity based on range condition.
  • Requires inst:AddTag and inst:RemoveTag to be available on the entity instance.

Properties

PropertyTypeDefault ValueDescription
block_rsqnumber or nil0Squared blocking radius; if > EPSILON, the entity gains the "lightningblocker" tag. Set via SetBlockRange().
on_strikefunction or nilnilOptional callback invoked when DoLightningStrike() is called.

Main Functions

OnRemoveFromEntity()

  • Description: Ensures the "lightningblocker" tag is removed when the component is detached from the entity.
  • Parameters: None (instance method).

SetBlockRange(newrange)

  • Description: Sets the blocking radius. Internally stores the squared value (newrange²) for efficient comparisons.
  • Parameters:
    • newrange (number or nil): The radius (in world units); if nil, block_rsq becomes nil.

SetOnLightningStrike(fn)

  • Description: Registers a callback function to be executed when a lightning strike occurs at this entity’s location.
  • Parameters:
    • fn (function): A function accepting (inst, pos) as arguments (entity instance and strike position).

DoLightningStrike(pos)

  • Description: Invokes the registered on_strike callback (if present), passing the entity instance and strike position.
  • Parameters:
    • pos (vector3): The position where the lightning strike occurred.

Events & Listeners

None identified — this component does not register or dispatch events using the ECS event system (inst:ListenForEvent, inst:PushEvent).