Multi
Module: Multi.lua
Overview
The Multi module provides utility functions for spawning multiple game objects in the world. It includes functions to spawn templates in front of the camera and to scatter objects over a specified area.
Inheritance
- Inherits from: none — base/utility module
- Imports: none
Instance pattern
This is a stateless manager/utility module with no per-instance tables or fields.
Functions
Multi(tObjects)
Spawns multiple templates in front of the camera. Iterates tObjects with ipairs and calls Pg.SpawnFromCamera(object, 10, 0.5) for each — i.e. 10 metres out, 0.5 up (both hardcoded here). All objects spawn at the same point, so they stack.
- Parameters:
tObjects: A table (array) of object template names to spawn.
- Returns: None
- Notes: If no
tObjectsis provided, prints the usage string viaDebug.Printfand returns.
Scatter(sObject, nNumber, nOffset, nTime, nDistance, nHeight)
Spawns nNumber copies of a template near a point in front of the camera, spread out in time. Finds the base point once with Pg.FindPointFromCamera(nDistance, nHeight), spawns the first copy there immediately (Pg.Spawn), then schedules the rest with Event.TimerRelative at evenly spaced offsets (nTime / nNumber * i). Each subsequent copy’s X and Z are jittered by (math.randf()*nOffset - math.randf()*nOffset)/2 — a small +/- wobble around the base point (nOffset is a jitter magnitude, not a strict radius), while Y stays fixed.
- Parameters:
sObject: The name of the object template to scatter.nNumber: The number of objects to spawn (default1).nOffset: The XZ jitter magnitude for each spawned object (default0— no jitter, objects stack).nTime: The total time in seconds over which to spread the spawns (default0— all at once).nDistance: Distance from the camera to the base point (default10).nHeight: Height of the base point (default0.5).
- Returns: None
- Notes: If no
sObjectis provided, prints the usage/example string viaDebug.Printfand returns.
Events
- Listens for none — this module does not subscribe to any engine events.
- Fires:
Event.TimerRelativeto schedule the spawning of additional objects in theScatterfunction.
Notes for modders
- These are camera-relative spawn helpers, handy from the console — both print a usage string if called with no template, so
Multi()/Scatter()alone tell you the argument shape. Example from source:Scatter('assault rifle', 3, 0, 6)stacks 3 assault rifles, one every two seconds. Multi’s10/0.5distance/height are hardcoded;Scatterexposes them asnDistance/nHeight(defaults10/0.5). UseScatterif you need to control where the objects land.- Templates must be real spawnable object names (the same names used elsewhere with
Pg.Spawn/Pg.SpawnFromCamera); a bad name just fails to spawn.