Skip to main content

Aoeweapon Base

Based on game build 714014 | Last updated: 2026-03-20

Overview

Aoeweapon_Base is a component that provides area-of-effect weapon functionality for entities. It handles targeting logic for three interaction types: workable objects (chopping, mining, digging), pickable items (harvesting), and combat targets (attacking enemies). The component supports configurable damage values, tag-based filtering for valid targets, and callback functions for hit/miss events. It is commonly used as a base for throwable weapons, traps, or AOE attack abilities.

Usage example

local inst = CreateEntity()
inst:AddComponent("aoeweapon_base")
inst.components.aoeweapon_base:SetDamage(25)
inst.components.aoeweapon_base:SetWorkActions(ACTIONS.CHOP, ACTIONS.MINE)
inst.components.aoeweapon_base:SetOnHitFn(function(inst, doer, target)
print("Hit target: "..tostring(target))
end)

Dependencies & tags

Components used: combat, workable, pickable, mine, spawner, childspawner, inventoryitem, physics Tags: Default tags include _combat, pickable, NPC_workable. Excludes FX, DECOR, INLIMBO.

Properties

PropertyTypeDefault ValueDescription
damagenumber10Base damage value dealt to combat targets.
tagstable{"_combat", "pickable", "NPC_workable"}Entity tags to include in targeting.
notagstable{"FX", "DECOR", "INLIMBO"}Entity tags to exclude from targeting.
workactionstablenilMap of work action types this weapon can perform.
combinedtagstablenilInternally computed union of tags and work action tags.
stimulianynilCombat stimuli data passed during attacks.
onprehitfnfunctionnilCallback fired before hit resolution.
onhitfnfunctionnilCallback fired on successful hit.
onmissfnfunctionnilCallback fired when hit fails.
canpickbooleannilWhether this weapon can pick pickable entities.

Main functions

SetDamage(dmg)

  • Description: Sets the base damage value for combat attacks.
  • Parameters: dmg (number) - damage value to apply.
  • Returns: Nothing.

SetStimuli(stimuli)

  • Description: Sets the stimuli data passed to combat attacks.
  • Parameters: stimuli (any) - stimuli table or value for combat system.
  • Returns: Nothing.

SetWorkActions(...)

  • Description: Configures which work actions this weapon can perform on workable entities.
  • Parameters: Variable arguments of action types (e.g., ACTIONS.CHOP, ACTIONS.MINE).
  • Returns: Nothing.
  • Error states: Rebuilds combinedtags internally after setting work actions.

SetTags(...)

  • Description: Sets entity tags to include in targeting filter.
  • Parameters: Variable arguments of tag strings.
  • Returns: Nothing.
  • Error states: Rebuilds combinedtags internally after setting tags.

SetNoTags(...)

  • Description: Sets entity tags to exclude from targeting filter.
  • Parameters: Variable arguments of tag strings to exclude.
  • Returns: Nothing.

SetOnPreHitFn(fn)

  • Description: Registers callback function to execute before hit resolution.
  • Parameters: fn (function) - callback with signature (inst, doer, target).
  • Returns: Nothing.

SetOnHitFn(fn)

  • Description: Registers callback function to execute on successful hit.
  • Parameters: fn (function) - callback with signature (inst, doer, target).
  • Returns: Nothing.

SetOnMissFn(fn)

  • Description: Registers callback function to execute when hit fails.
  • Parameters: fn (function) - callback with signature (inst, doer, target).
  • Returns: Nothing.

OnHit(doer, target)

  • Description: Main hit resolution logic. Determines if target is workable, pickable, or combat-valid, then performs appropriate action.
  • Parameters: doer (entity) - the entity performing the hit. target (entity) - the entity being hit.
  • Returns: Nothing.
  • Error states: Workable destruction skips spawner/childspawner entities for DIG action. Pickable items do not pass doer to avoid loot pocketing. Combat requires CanTarget and non-ally status.

OnToss(doer, target, sourceposition, basespeed, startradius)

  • Description: Handles physics-based tossing/throwing of a target entity. Deactivates mines, calculates trajectory, and applies velocity.
  • Parameters: doer (entity) - throwing entity. target (entity) - entity to toss. sourceposition (Vector3 or nil) - starting position. basespeed (number or nil) - base velocity magnitude. startradius (number or nil) - starting radius offset.
  • Returns: Nothing.
  • Error states: Skips toss if target lacks physics or has nobounce inventory flag. Adjusts angle if initial trajectory hits blocked ground.

Events & listeners

None identified. This component does not register event listeners or push events directly. Callbacks are invoked via function references set through SetOnPreHitFn, SetOnHitFn, and SetOnMissFn.