Playermetrics
Overview
The PlayerMetrics component is a lightweight network-oriented component attached to player entities that listens for recipe-unlocking events and forwards them to the Stats analytics system via the PushMetricsEvent function. It ensures that protoyping actions (i.e., recipe unlocks) are logged for telemetry and analytics purposes.
Dependencies & Tags
- Dependency:
stats(custom module, required viarequire("stats")) - Event Listener: Registers callback for
"unlockrecipe"event on its entity - No components added or tags applied
Properties
No public properties are initialized in the constructor. The component stores only a reference to its entity (self.inst) internally.
Main Functions
OnUnlockRecipe(inst, data)
- Description: Callback invoked when the
"unlockrecipe"event is fired. If the event data contains a valid recipe, it triggers a metrics event"character.prototyped"with the unlocked recipe’s prefab name. - Parameters:
inst: The entity (player) that unlocked the recipe.data: Event payload containing at leastrecipe(string or table withprefabfield).
PlayerMetrics:OnRemoveFromEntity()
- Description: Cleans up event listener registration when the component is removed from the entity.
- Parameters: None.
Events & Listeners
- Listens to:
"unlockrecipe"event (viainst:ListenForEvent("unlockrecipe", OnUnlockRecipe)) - Triggers:
"character.prototyped"event (viaPushEvent("character.prototyped", inst, { prefab = data.recipe }))- This event is an internal metrics payload, not an engine-level game event; actual event name used by
Stats.PushMetricsEventis implementation detail of theStatsmodule.