Heavymg
Module: heavymg.lua
Overview
The Heavymg module is responsible for handling the removal of heavy machine gun (HMG) objects when they are dropped by a human player. It listens for specific weapon events and triggers the appropriate actions to despawn the HMG.
Inheritance
- Inherits from:
none β base/utility module - Imports:
MrxUtil
Instance pattern
Not a per-uGuid object pattern β no OnActivate/Awake/Create/setmetatable/tInstance registry. Itβs a stateless-object utility module with one shared table, tEvents (tEvents = tEvents or {}, guarding against re-initialization), keyed by uGuid to hold each HMGβs single event handle. import("MrxUtil") is present but unused by any function in this file.
Functions
OnActivate(uGuid, iArg)
Called when the HMG object instance is activated (engine world-object lifecycle hook, not a per-instance Create). Registers tEvents[uGuid] as an Event.Create(Event.WeaponEvent, {"Human", "Drop", uGuid}, ...) listener, with Object.Remove as the callback and {uGuid} as its argument β so dropping the weapon as a human directly removes the object.
OnDeactivate(uGuid)
Called when the HMG object instance is deactivated. Deletes tEvents[uGuid] if set. Does not clear the table entry afterward (leaves a stale/deleted event handle in tEvents[uGuid] rather than setting it to nil).
Events
Event.WeaponEventβ the onlyEvent.*reference in this file. Filtered on{"Human", "Drop", uGuid}; firesObject.Remove(uGuid)directly as the callback (no intermediate handler function in this file).
Notes for modders
- Behavior lever: the entire module is one rule β βwhen a human drops this HMG, delete it.β To keep a dropped HMG in the world, remove or replace the
Object.Removecallback inOnActivate. The filter triple{"Human", "Drop", uGuid}is what scopes it to human-drop events on this object (see the weapon namespace forEvent.WeaponEventsemantics). - This module has no public API beyond the two engine lifecycle hooks;
import("MrxUtil")is present but unused here. OnDeactivatedoes not null outtEvents[uGuid]after deleting the event β harmless in practice sinceOnActivatealways overwrites it on the next activation, but worth knowing if youβre auditing for leaks.