Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_NetworkedStatsComponent.c
Go to the documentation of this file.
3typedef ScriptInvokerBase<SCR_OnStatChangedMethod> SCR_OnStatChangedInvoker;
4
5[ComponentEditorProps(category: "GameScripted/Network", description: "Stats Tracker between the Authority and the Proxy")]
7{
9
10 //------------------------------------------------------------------------------------------------
14 {
15 if (!m_OnStatsChanged && createIfNull)
17
18 return m_OnStatsChanged;
19 }
20}
21
22class 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 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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
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}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
RplComponent m_RplComponent
SCR_ENetworkedStatType
func SCR_OnStatChangedMethod
void SetStatValueOfAuthority(SCR_ENetworkedStatType statType, int value)
SCR_BaseNetworkedStat GetNetworkedStat(SCR_ENetworkedStatType statType)
void UpdateStats()
SCR_NetworkedStatsComponentClass GetNetworkedStatPrefabData()
void SetAuthorityStatValue(SCR_ENetworkedStatType statType, int valueInt)
ScriptInvokerBase< SCR_OnStatChangedMethod > SCR_OnStatChangedInvoker
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external int SetEventMask(notnull IEntity owner, int mask)
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external Managed FindComponent(typename typeName)
void OnAuthorityStatValueSet(int value)
static bool IsEditMode()
Definition Functions.c:1566
ref SCR_OnStatChangedInvoker m_OnStatsChanged
SCR_OnStatChangedInvoker GetOnStatsChanged(bool createIfNull=true)
proto external GenericEntity GetOwner()
Get owner entity.
void EOnInit(IEntity owner)
SCR_FieldOfViewSettings Attribute
RplComponent GetRplComponent()
Returns the replication component associated to this entity.
EntityEvent
Various entity events.
Definition EntityEvent.c:14
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14