Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_NetworkedStatsComponent.c
Go to the documentation of this file.
3 typedef ScriptInvokerBase<SCR_OnStatChangedMethod> SCR_OnStatChangedInvoker;
4 
5 [ComponentEditorProps(category: "GameScripted/Network", description: "Stats Tracker between the Authority and the Proxy")]
6 class SCR_NetworkedStatsComponentClass : ScriptComponentClass
7 {
8  protected ref SCR_OnStatChangedInvoker m_OnStatsChanged;
9 
10  //------------------------------------------------------------------------------------------------
13  SCR_OnStatChangedInvoker GetOnStatsChanged(bool createIfNull = true)
14  {
15  if (!m_OnStatsChanged && createIfNull)
17 
18  return m_OnStatsChanged;
19  }
20 }
21 
22 class SCR_NetworkedStatsComponent : ScriptComponent
23 {
24  [Attribute()]
25  protected ref array<ref SCR_BaseNetworkedStat> m_aStats;
26  protected RplComponent m_RplComponent;
27 
28  [Attribute("3", uiwidget: UIWidgets.EditBox, desc: "How many seconds should we wait before checking and updating the stats again?")]
29  protected int m_iUpdateTimer;
30 
31  //------------------------------------------------------------------------------------------------
35  {
36  foreach (SCR_BaseNetworkedStat stat : m_aStats)
37  {
38  if (stat.GetStatType() == statType)
39  return stat;
40  }
41 
42  return null;
43  }
44 
45  //------------------------------------------------------------------------------------------------
48  {
50  }
51 
52  //------------------------------------------------------------------------------------------------
54  RplComponent GetRplComponent()
55  {
56  return m_RplComponent;
57  }
58 
59  //------------------------------------------------------------------------------------------------
62  void SetAuthorityStatValue(SCR_ENetworkedStatType statType, int valueInt)
63  {
64  if (m_RplComponent.IsProxy())
65  return;
66 
67  Rpc(SetStatValueOfAuthority, statType, valueInt);
68  }
69 
70  //------------------------------------------------------------------------------------------------
73  [RplRpc(RplChannel.Unreliable, RplRcver.Broadcast)]
75  {
76  SCR_BaseNetworkedStat networkedStat = GetNetworkedStat(statType);
77  if (!networkedStat)
78  return;
79 
80  networkedStat.OnAuthorityStatValueSet(value);
81  }
82 
83  //------------------------------------------------------------------------------------------------
85  void UpdateStats()
86  {
87  foreach (SCR_BaseNetworkedStat stat : m_aStats)
88  {
89  stat.UpdateStat();
90  }
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  override void EOnInit(IEntity owner)
95  {
96 #ifdef WORKBENCH
97  if (SCR_Global.IsEditMode())
98  return;
99 #endif
100 
101  m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
102  // For continuously updating stats. As the tick intervals are huge, EOnUpdate is a serious overkill and not needed.
103  GetGame().GetCallqueue().CallLater(UpdateStats, m_iUpdateTimer * 1000, true);
104 
105  foreach (SCR_BaseNetworkedStat networkedStat : m_aStats)
106  {
107  networkedStat.SetOwner(this);
108  }
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  override void OnPostInit(IEntity owner)
113  {
114  SetEventMask(owner, EntityEvent.INIT);
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  override void OnDelete(IEntity owner)
119  {
120  GetGame().GetCallqueue().Remove(UpdateStats);
121  }
122 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
GetNetworkedStatPrefabData
SCR_NetworkedStatsComponentClass GetNetworkedStatPrefabData()
Definition: SCR_NetworkedStatsComponent.c:47
SCR_OnStatChangedInvoker
ScriptInvokerBase< SCR_OnStatChangedMethod > SCR_OnStatChangedInvoker
Definition: SCR_NetworkedStatsComponent.c:3
SetStatValueOfAuthority
void SetStatValueOfAuthority(SCR_ENetworkedStatType statType, int value)
Definition: SCR_NetworkedStatsComponent.c:74
SCR_NetworkedStatsComponentClass
Definition: SCR_NetworkedStatsComponent.c:6
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
SCR_OnStatChangedMethod
func SCR_OnStatChangedMethod
Definition: SCR_NetworkedStatsComponent.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnDelete
override void OnDelete(IEntity owner)
Definition: SCR_NetworkedStatsComponent.c:118
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GetRplComponent
RplComponent GetRplComponent()
Returns the replication component associated to this entity.
Definition: SCR_NetworkedStatsComponent.c:54
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_ENetworkedStatType
SCR_ENetworkedStatType
Definition: SCR_NetworkedStatTypes.c:1
Attribute
SCR_NetworkedStatsComponentClass ScriptComponentClass Attribute()] protected ref array< ref SCR_BaseNetworkedStat > m_aStats
Post-process effect of scripted camera.
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_NetworkedStatsComponent.c:112
m_OnStatsChanged
protected ref SCR_OnStatChangedInvoker m_OnStatsChanged
Definition: SCR_NetworkedStatsComponent.c:4
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SetAuthorityStatValue
void SetAuthorityStatValue(SCR_ENetworkedStatType statType, int valueInt)
Definition: SCR_NetworkedStatsComponent.c:62
EOnInit
override void EOnInit(IEntity owner)
Initialise this component with data from FactionsManager.
Definition: SCR_NetworkedStatsComponent.c:94
SCR_Global
Definition: Functions.c:6
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_NetworkedStatsComponent.c:26
UpdateStats
void UpdateStats()
Definition: SCR_NetworkedStatsComponent.c:85
SCR_BaseNetworkedStat
Definition: SCR_BaseNetworkedStat.c:2
GetNetworkedStat
SCR_BaseNetworkedStat GetNetworkedStat(SCR_ENetworkedStatType statType)
Definition: SCR_NetworkedStatsComponent.c:34
m_iUpdateTimer
protected int m_iUpdateTimer
Definition: SCR_NetworkedStatsComponent.c:29
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180