FactionZone
Module: factionzone.lua
Overview
The FactionZone module adds a colored line region to the radar and PDA map for specific faction zones. It also sends TrespassStateChange GUI events (via MrxGui.SendEvent) when players enter or exit these zones.
Inheritance
- Inherits from:
Inheritable - Imports:
MrxGui(sends theTrespassStateChangeGUI event)
Instance pattern
Per-instance object module (keyed by uGuid), created via the standard OnActivate β Awake-equivalent β Create idiom (here OnActivate calls oPrototype:Create(uGuid, uRuntimeOwner) directly, with no separate Awake/hibernation wait β unlike Inheritableβs documented OnActivate/Awake split, this fileβs own OnActivate skips straight to Create). Tracks the following key fields:
uFaction: The GUID of the faction associated with the zone (Ai.GetFactionGuid(oSelf.uGuid)).sFaction: The short faction abbreviation (e.g."All","Pmc"), copied from_tAssociationMap.bActive: Indicates whether the zoneβs visual and event triggers are active (set inEnable, cleared inDisable).bTrespassing: Tracks if a player is currently trespassing in the zone.BoundaryEvent: Persistent event handle for the boundary listener, set inEnable, deleted inDisable.
Functions
Init()
Initializes the module-level global _tAssociationMap, keyed by String.GetHash(<faction name>) (not the plain name string) β e.g. [String.GetHash("Allied")] = {sFaction = "All"}. Covers Allied, China, Civ, Guerilla, OC, Pirate, PMC, VZ.
OnActivate(uGuid, uRuntimeOwner, iArg)
Called when the object instance is activated. Immediately creates a new per-instance table via oPrototype:Create(uGuid, uRuntimeOwner) β note iArg is accepted but not forwarded to Create (only uGuid/uRuntimeOwner are passed).
Create(oPrototype, uGuid, uRuntimeOwner)
Calls Inheritable.Create(oPrototype, uGuid, uRuntimeOwner), then sets oSelf.uFaction from Ai.GetFactionGuid, looks up Object.GetName(oSelf.uFaction) (a hash) in _tAssociationMap, and copies every key/value from the matched entry onto oSelf (currently just sFaction). Calls oSelf:Enable() if bActive is not already set. If the faction nameβs hash isnβt a key in _tAssociationMap, this indexes a nil table in the pairs(...) call and would error β no fallback/default entry exists.
Delete(oSelf)
Tears down the per-instance table by calling oSelf:Disable() if bActive, then Inheritable.Delete(oSelf). This file defines no OnDeactivate/OnDeath; teardown is invoked via Inheritable.OnDeactivate/Inheritable.OnDeath, both inherited, which call oInstance:Delete().
BoundaryCallback(oSelf, uObjectGuid, uBoundaryGuid, sAction)
Callback for Event.Boundary. Fires the TrespassStateChange GUI event and flips oSelf.bTrespassing only when the state actually changes: on sAction == "enter" while not already trespassing, or sAction == "exit" while currently trespassing (guarded by if not (sAction ~= "enter" or oSelf.bTrespassing) or sAction == "exit" and oSelf.bTrespassing then) β repeated βenterβ events while already trespassing (or βexitβ while not) are no-ops.
Enable(oSelf)
Enables the faction zone by calling Hud.Radar:AddLineRegion and Pda.Map:AddLineRegion with a dark-red region (nRed=64, nGreen=0, nBlue=0, nAlpha=160) keyed by uGuid. Sets up a persistent Event.Boundary listener (Player.GetLocalCharacter(), oSelf.uGuid, "any", false) calling BoundaryCallback, and sets bActive = true.
Disable(oSelf)
Disables the faction zone by calling Hud.Radar:RemoveLineRegion/Pda.Map:RemoveLineRegion (keyed by uGuid only), deletes BoundaryEvent, sends a final TrespassStateChange (bTrespassing = false) event if bTrespassing was set, and clears bActive (sets it to nil, not false).
Events
- Listens for
Event.Boundary(viaEvent.CreatePersistent) to callBoundaryCallbackwhen a player enters or exits the faction zone boundary. - Sends
TrespassStateChangeas a GUI event payload viaMrxGui.SendEvent(not anEvent.*engine constant) on state changes inBoundaryCallbackand on forced-false inDisable.
Module constants & tunables
- Region colour (radar + PDA line region):
nRed = 64, nGreen = 0, nBlue = 0, nAlpha = 160β a translucent dark red. Change these inEnableβstRegionParamto recolour the zone outline. - Faction association map (
_tAssociationMap, hash-keyed):AlliedβAll,ChinaβChi,CivβCiv,GuerillaβGur,OCβOil,PirateβPir,PMCβPmc,VZβVz. The short code becomesoSelf.sFactionand is the payload of theTrespassStateChangeevent.
Notes for modders
OnActivate/Createhappen synchronously here β thereβs no hibernation-wait step in this fileβs ownOnActivate, unlike the more commonOnActivateβEvent.Create(Event.ObjectHibernation, ...)βAwakepattern seen elsewhere inresident/.- The zone draws through
Hud.Radar:AddLineRegionandPda.Map:AddLineRegion, and its faction is resolved viaAi.GetFactionGuidβ those are the primitives to reach for if you build a similar map-region prop. - Customize the faction association by modifying
_tAssociationMapinInit; remember the map is keyed byString.GetHash(name), not the raw name string. OnDeactivate/OnDeathare not defined in this file β they come fromInheritable, which calls this fileβsDeleteoverride.- Be aware that enabling/disabling the zone affects both radar and PDA map visualizations, and that
Enable/Disableare idempotent-guarded viabActiveat the call site (Create/Delete), not insideEnable/Disablethemselves.