Nightstick
Based on game build 722832 | Last updated: 2026-04-17
Overview
nightstick is a weapon prefab that functions as a light source and deals electric damage. It consumes fuel over time and can be recharged using batteries via the batteryuser component. When equipped, it ignites to provide illumination and spawns a fire child entity. The prefab integrates with the equipment system through the equippable component and handles skin overrides for customized appearances.
Usage example
-- Spawn a nightstick in the world
local nightstick = SpawnPrefab("nightstick")
-- Access components for modification
nightstick.components.weapon:SetDamage(50)
nightstick.components.fueled:SetPercent(1.0)
-- Check partial charge setting
local allowpartial = nightstick.components.batteryuser.allowpartialcharge
Dependencies & tags
External dependencies:
TUNING-- references NIGHTSTICK_DAMAGE, NIGHTSTICK_FUEL, TURNON_FUELED_CONSUMPTION, TURNON_FULL_FUELED_CONSUMPTION
Components used:
weapon-- sets damage, electric stimulus, and onattack callbackinventoryitem-- enables item to be picked up and carriedequippable-- handles equip/unequip/pocket behavior and model overridesinspectable-- enables player inspection of the itemburnable-- manages ignition/extinguish state for light emissionfueled-- tracks fuel consumption and depletion callbacksbatteryuser-- enables battery recharging functionality
Tags:
wildfireprotected-- added on creation, prevents wildfire spreadingbatteryuser-- added on creation, marks entity as rechargeableweapon-- added on creation, marks entity as a weapon
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
| None | No entity-level properties are defined. |
Main functions
fn()
- Description: Constructor function that creates and configures the nightstick entity. Adds all components, sets up callbacks, and applies tags. Server-side logic is guarded by TheWorld.ismastersim check.
- Parameters: None
- Returns: Entity instance (inst)
- Error states: None
onpocket(inst)
- Description: Called when the nightstick is placed in a player's pocket. Extinguishes the burnable component to stop light emission.
- Parameters:
inst-- the nightstick entity instance - Returns: None
- Error states: Errors if
inst.components.burnableis nil (no nil guard present).
onremovefire(fire)
- Description: Callback for when the fire child entity is removed. Clears the fire reference on the nightstick.
- Parameters:
fire-- the fire child entity being removed - Returns: None
- Error states: Errors if
fireis nil orfire.nightstickis nil (no nil guard present before member access).
onequip(inst, owner)
- Description: Called when the nightstick is equipped by a player. Ignites the burnable component, spawns the fire child entity, overrides animation symbols for skin support, and plays equip sound.
- Parameters:
inst-- the nightstick entity instanceowner-- the player entity equipping the item
- Returns: None
- Error states: Errors if
owner.AnimStateis nil or ifSpawnPrefabfails. May error ifinst.fireexists but lacksnightsticktable field.
onunequip(inst, owner)
- Description: Called when the nightstick is unequipped. Removes the fire child entity, extinguishes the burnable component, restores normal arm animations, and stops the torch sound.
- Parameters:
inst-- the nightstick entity instanceowner-- the player entity unequipping the item
- Returns: None
- Error states: Errors if
owner.AnimStateis nil or ifinst.SoundEmitteris nil.
onequiptomodel(inst, owner, from_ground)
- Description: Called when equipping to a model (e.g., mannequin display). Removes fire entity and extinguishes burnable without player animation changes.
- Parameters:
inst-- the nightstick entity instanceowner-- the entity receiving the equipmentfrom_ground-- boolean indicating if equipped from ground
- Returns: None
- Error states: Errors if
inst.components.burnableorinst.SoundEmitteris nil (no nil guard present before member access).
OnRemoveEntity(inst)
- Description: Called when the nightstick entity is being removed from the world. Cleans up the fire child entity if it exists.
- Parameters:
inst-- the nightstick entity instance - Returns: None
- Error states: None
onfuelchange(newsection, oldsection, inst)
- Description: Callback when fuel section changes. If fuel reaches zero, extinguishes the burnable, removes the nightstick, and pushes
itemranoutevent to owner if equipped. - Parameters:
newsection-- number, new fuel section valueoldsection-- number, previous fuel section valueinst-- the nightstick entity instance
- Returns: None
- Error states: Errors if
inst.components.burnableorinst.components.equippableis nil when fuel depletes.
onattack(inst, attacker, target)
- Description: Called when the nightstick successfully hits a target. Spawns electric hit spark effects.
- Parameters:
inst-- the nightstick entity instanceattacker-- the entity performing the attacktarget-- the entity being attacked
- Returns: None
- Error states: Errors if
attackerortargetis nil when passed toSpawnElectricHitSparks(no parameter validation before global function call).
CalcBatteryChargeMult(inst, battery)
- Description: Calculates the charge multiplier based on current fuel percentage. Returns higher multiplier when fuel is lower.
- Parameters:
inst-- the nightstick entity instancebattery-- the battery entity being used to charge
- Returns: Number between 0 and 1 representing charge multiplier
- Error states: Errors if
inst.components.fueledis nil.
OnBatteryUsed(inst, battery, mult)
- Description: Called when a battery is used to charge the nightstick. Adds charge based on multiplier if not already full. Spawns electric hit sparks on success.
- Parameters:
inst-- the nightstick entity instancebattery-- the battery entity used for chargingmult-- number, charge multiplier from CalcBatteryChargeMult
- Returns: Boolean
trueon success, orfalse, "CHARGE_FULL"if already full ormult <= 0 - Error states: Errors if
inst.components.fueledis nil.
Events & listeners
- Listens to:
onremove-- registered on the fire child entity to clean up reference when fire is removed - Pushes:
equipskinneditem-- fired on owner when equipping with skin override - Pushes:
unequipskinneditem-- fired on owner when unequipping with skin override - Pushes:
itemranout-- fired on owner when fuel depletes while equipped