DangerousBuilding
Module: dangerousbuilding.lua
Overview
The DangerousBuilding module manages dangerous buildings in the game. It handles the activation, deactivation, and state changes of these buildings, including their radar blips, health monitoring, and attached spawners. The module also supports setting properties such as rarity and reward for these buildings.
Inheritance
- Inherits from: none β base/utility module
- Imports:
MrxGui(kill-reward toast),MrxPmc(cash payout),MrxUtil(CallWithOptionalArgsfor the optional wakeup function)
Instance pattern
Not the Inheritable/rich-instance pattern, and not a class-factory either β confirmed from source: a plain module-level table, tDBs[uGuid] = tDBs[uGuid] or {}, with no Create/Delete/setmetatable anywhere. Each activated building gets a small sub-table entry in tDBs, not a full instance object with inherited methods. It tracks the following key fields:
tDBs: A table storing data for each dangerous building instance.nDBCount: The current count of active dangerous buildings.nMaxDBs: The maximum number of active dangerous buildings allowed.nDefaultRarity: The default rarity value for dangerous buildings.nGlobalRarity: The global rarity value that affects the activation probability.nDefaultCashReward: The default cash reward for destroying a dangerous building.
Functions
OnActivate(uGuid, uRuntimeOwner, iArg)
Called when the object instance is activated. It sets up an event to call Start once the object leaves hibernation.
Start(uGuid)
Handles the initialization of the dangerous building instance. If the building is occupied, it calls SetupOccupied. Otherwise, it rolls a random chance based on rarity and activates a random dangerous building if conditions are met.
SetupOccupied(uGuid, bForceOnClient)
Sets up an occupied dangerous building by adding a grey radar blip and monitoring its health. If the building is permanently occupied, it sends a network event to update the server.
TurnOn(uGuid, bRadar, bPermanent, bForceOnClient)
Activates the dangerous building by turning on attached spawners and changing the radar blip to red active. It also animates the blip size and sends a network event if necessary.
OccupiedBuildingSpawnCallback(uGuid)
Animates the radar blip alpha for an occupied dangerous building when it spawns.
TurnOnRandomDB(uGuid, bForceOnClient)
Activates a random dangerous building by turning on attached spawners with specific settings and sending a network event if necessary.
OnDeactivate(uGuid)
Called when the object instance is deactivated. It removes the dangerous building if itβs not permanent and deletes associated events.
Delete(oSelf)
Calls RemoveDB(oSelf.uGuid). Note the oSelf.uGuid access is the Inheritable-style calling convention, but this module has no Create/setmetatable factory β so Delete is only meaningful if something external passes it a table with a .uGuid field; it is not wired to the bare tDBs[uGuid] lifecycle used elsewhere in this file.
OnDeath(uGuid)
Handles the death of a dangerous building by removing it and rewarding the player if applicable.
ClearProperties(uGuid)
Clears properties for the specified dangerous building by calling RemoveDB.
RemoveDB(uGuid, bKilled, bForceOnClient)
Removes the specified dangerous building, updates radar blips, turns off attached spawners, and sends network events as necessary. If the building is killed, it rewards the player.
RemoveAllDBs()
Removes all active dangerous buildings by calling RemoveDB for each one.
GetAllDBs()
Prints debug information about all currently active dangerous buildings.
GetRarity(uGuid)
Returns the rarity value of the specified dangerous building or the global rarity if none is set.
SetProperties(uGuid, tProps)
Sets properties for the specified dangerous building, including density, faction, reward, and spawner settings.
_Process(tTable, data)
Processes and inserts data into a table, converting names to GUIDs if necessary.
ConvertToTableOfGuids(tData)
Converts input data into a table of GUIDs.
ProcessProperties(uGuid, tProps)
Processes properties for the specified dangerous building, updating density, faction, reward, and spawner settings as needed.
SetFaction(uGuid, sFaction)
Sets the faction for the specified dangerous building and updates attached spawners accordingly.
SetWakeupFunction(uGuid, fFunction)
Sets a wakeup function for the specified dangerous building.
SetRarity(uGuid, iRarity)
Sets the rarity value for the specified dangerous building or updates the global rarity if applicable.
SetDBFaction(uGuid, sFaction, tProps)
Updates the faction settings for attached spawners of the specified dangerous building.
Events
- Creates
Event.ObjectHibernation(OnActivate) to callStartwhen the object leaves hibernation. The handle is stored astDBs[uGuid].WakeEvent. - Creates
Event.ObjectHealth(SetupOccupied, server only) with comparator"<"against the buildingβs current health, soTurnOnfires when the occupied building takes any damage. Stored astDBs[uGuid].HealthEvent. OnActivate/OnDeactivate/OnDeath/Delete/ClearPropertiesare engine lifecycle callbacks, notEvent.*subscriptions.
The
Net.SendEvent_AddDangerousBuilding/Net.SendEvent_RemoveDangerousBuilding/Net.SendEvent_AddRandomDangerousBuilding/Net.SendEvent_SetOccupiedDangerousBuildingcalls are outgoing engine net-events (server β clients), notEvent.Createsubscriptions this module listens for. (A previous version of this page incorrectly listed aRemoveDangerousBuildinglistener β there is none; only the send exists.)
Module constants & tunables
- Caps/tuning:
nMaxDBs = 8(max simultaneously-active random DBs),nDefaultRarity = 16,nGlobalRarity(starts atnDefaultRarity),nDefaultCashReward = 0,nDBCount(live counter). - Inactive/occupied radar blip: texture
"temp_radar_icon_db", colour170,170,170(grey), size8x8,nSortOrder = 3,bSticky = false. - Active radar blip: texture
"temp_radar_icon_dbactive", colour250,0,0(red), size8x8, then pulsed viaHud.Radar:AnimateObjectiveSize(nDuration = 5, width/height oscillating4β12). - Blip name key:
"db_" .. tostring(uGuid). - Random-DB spawner tweak (
TurnOnRandomDB):SpawnerType = "Once",RadiusType = "RADIUS_PLAYER_2D",ActiveRadius = 100,SkipPercentChange = 100,SpawnList = "Spawnlist (VZ Tower)"; also turns the"ground"spawner group off. - Kill reward message:
"[green]Occupied building destroyed! +$" .. nReward(4s), paid viaMrxPmc.AddCashQty(nReward, true)β only whennReward > 0. SetRaritymagic strings:"never"β-1(never activates),"always"β0,"default"βnDefaultRarity; anduGuidof"default"/"all"/"global"setsnGlobalRarityinstead of a per-object rarity.
Notes for modders
SetProperties(uGuid, tProps)is the main authoring lever β recognized keys includeDensity(0β100, converted toChanceNotActive/SkipPercentChance),Faction,Reward,Rarity,WakeupFunction,Group, and any spawner fields passed straight toAi.TweakAttachedSpawners.- Activation is probabilistic:
Startrollsmath.randf() * nMaxDBs * iRarityand only turns the building on if that is< nMaxDBs, so largerRaritymeans less likely (and< 0/"never"disables it). - Cash rewards flow through
MrxPmc.AddCashQtyand the on-screen toast throughMrxGui.AddMessage; the default reward is0, so buildings pay nothing unless a per-objectRewardis set viaSetProperties. Permanentbuildings surviveOnDeactivate(early return) β set viaTurnOn(..., bPermanent=true).- This is the module Alarm calls into:
DangerousBuilding.TurnOn(tBuildings, true, false, true)activates every occupied building near a tripped alarm. - Debug helpers
GetAllDBs()andGetRarity(uGuid)are handy from the console for inspecting live state.