Junk pile common
Based on game build 714014 | Last updated: 2026-03-05
Overview
junk_pile_common.lua is a utility module that defines loot tables and helper functions for spawning loot and creatures from junk piles. It centralizes the logic for weighted random selection of critters and items, perishable item initialization, and prefab dependency registration. This module does not define a component itself but returns a table of constants and functions intended for reuse across multiple junk pile-related prefabs.
The module interacts with the lootdropper, combat, perishable, and inventory components to spawn, fling, target, and position items or creatures.
Usage example
local junk_pile_common = require "prefabs/junk_pile_common"
-- Use the loot generation function
junk_pile_common.SpawnJunkLoot(junk_pile_inst, digger_inst, false)
-- Register prefabs for preloading
local prefabs = {}
junk_pile_common.AddPrefabDeps(prefabs)
Dependencies & tags
Components used: lootdropper, combat, perishable, inventory
Tags: None identified.
Properties
No public properties. This module exports only functions and lookup tables in the returned table.
Main functions
SpawnJunkLoot(inst, digger, nopickup)
- Description: Spawns either a random critter (with low chance) or a random item from the junk pile. If spawning a critter, it may be given a combat target (e.g., the digger) and directed into an attack state. Items may be given to the digger’s inventory or flung into the world.
- Parameters:
inst(Entity) — The junk pile entity; used to calllootdropper:FlingItem.digger(Entity) — The entity that dug up the pile; used as potential combat target and inventory recipient.nopickup(boolean) — Iftrue, items are always flung instead of given to inventory.
- Returns: Nothing.
- Error states: No critter spawns if
enabled_tuningis defined and evaluates tofalse. No item spawns if the weighted selection yieldsEMPTY. Critters withoutcombatcomponent ignore targeting logic.
AddPrefabDeps(prefabs)
- Description: Populates the provided
prefabstable with all critter and item prefabs referenced in the loot tables (excludingEMPTY). - Parameters:
prefabs(table, array) — A table to append prefab names into.
- Returns: Nothing.
Events & listeners
None — this module is purely functional and does not attach or respond to any events.