Emplaced
Module: emplaced.lua
Overview
The Emplaced module manages the behavior of emplaced weapons, specifically handling events related to a player entering and exiting a gunner seat. It sets camera focus parameters when a player enters the seat and restores them when they exit.
Inheritance
- Inherits from:
none β base/utility module - Imports:
none
Instance pattern
Bare tGuids-style bookkeeping, not stateless and not the Inheritable rich-instance pattern. State lives in one module-level global table, uEvent, keyed by uGuid (uEvent[uGuid] = uEvent[uGuid] or {}), holding just two handles per active weapon: uEvent[uGuid].Enter and uEvent[uGuid].Exit. There is no Create/setmetatable/tInstance factory. Init() seeds the table and Deinit() drops it wholesale.
Functions
Init()
Initializes the uEvent table if it hasnβt been initialized yet.
Deinit()
Sets the uEvent table to nil, effectively cleaning up any stored event handles.
OnActivate(uGuid, uOwner, nArg)
Called when an emplaced weapon instance is activated. It sets up an event to call Activate once the object leaves hibernation.
Activate(uGuid)
Creates an enter event for the specified uGuid.
CreateEnterEvent(uGuid)
Creates an event that listens for a player entering the gunner seat and calls the Enter function when triggered.
CreateExitEvent(uGuid, uChar)
Creates an event that listens for a player exiting the gunner seat and calls the Exit function when triggered.
Enter(uChar, uGuid)
Handles the event where a player enters the gunner seat. It checks if the character is controlled by a local player and sets the camera focus parameters accordingly. Then, it creates an exit event for the same seat.
Exit(uChar, uGuid)
Handles the event where a player exits the gunner seat. It checks if the character is controlled by a local player and restores the camera focus parameters to their default state. Then, it creates an enter event for the same seat.
OnDeactivate(uGuid, nArg)
Called when an emplaced weapon instance is deactivated. It deletes any stored enter and exit events associated with the specified uGuid.
Events
- Creates
Event.ObjectHibernation(OnActivate) to callActivatewhen the object leaves hibernation. - Creates
Event.ObjectInSeatwith the"Gunner"seat +"enter"filter (CreateEnterEvent) to callEnter. Stored asuEvent[uGuid].Enter. - Creates
Event.ObjectInSeatwith the"Gunner"seat +"exit"filter (CreateExitEvent) to callExit. Stored asuEvent[uGuid].Exit. The enter/exit listeners are re-armed alternately (Entercreates the exit listener,Exitre-creates the enter listener), so only one is live at a time. OnActivate/OnDeactivateare engine lifecycle callbacks, notEvent.*subscriptions.
Module constants & tunables
- Seat name filter:
"Gunner"(both enter and exit events). - Camera on entering the seat:
Graphics.Camera.SetFocusParams(0, 0, 2, 2, 600, 4, 0); on exit:Graphics.Camera.RestoreFocusParams(0, 0). These seven numbers are the whole βzoom/focus feelβ of manning the emplaced weapon β the only real tuning lever in the file.
Notes for modders
- The single meaningful mod lever is the camera call: change the
Graphics.Camera.SetFocusParams(...)arguments to alter how the view snaps when the player mounts the gun (see the Camera namespace / Graphics namespace). - Only local player characters trigger the focus change β non-players and remote players hit an early return with a
Debug.Printflog line (βA non-player triggered this event!β), so donβt rely on this for AI gunners.