Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DataCollectorCommunicationComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/DataCollection/", description: "Component used to send data to specific clients.")]
2 class SCR_DataCollectorCommunicationComponentClass : ScriptComponentClass
3 {
4 }
5 
6 class SCR_DataCollectorCommunicationComponent : ScriptComponent
7 {
8  protected ref ScriptInvoker m_OnDataReceived;
9 
10  //------------------------------------------------------------------------------------------------
11  notnull ScriptInvoker GetOnDataReceived()
12  {
13  if (!m_OnDataReceived)
14  m_OnDataReceived = new ScriptInvoker();
15 
16  return m_OnDataReceived;
17  }
18 
19  //------------------------------------------------------------------------------------------------
25  void SendData(notnull SCR_PlayerData playerData, notnull array<FactionKey> factionKeys, notnull array<float> values, int valuesSize)
26  {
27  Rpc(Rpc_DoSendData, playerData.GetStats(), playerData.GetPreviousStats(), factionKeys, values, valuesSize);
28  }
29 
30  //------------------------------------------------------------------------------------------------
37  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
38  void Rpc_DoSendData(notnull array<float> stats, notnull array<float> previousStats, notnull array<FactionKey> factionKeys, notnull array<float> values, int valuesSize)
39  {
40  foreach (float stat : stats)
41  {
42  Print(stat, LogLevel.DEBUG);
43  }
44 
45  foreach (float stat : previousStats)
46  {
47  Print(stat, LogLevel.DEBUG);
48  }
49 
50  BaseGameMode gameMode = GetGame().GetGameMode();
51  if (!gameMode)
52  return;
53 
54  SCR_DataCollectorComponent dataCollector = GetGame().GetDataCollector();
55  if (!dataCollector)
56  return;
57 
58  for (int i = 0, factionsCount = factionKeys.Count(); i < factionsCount; i++)
59  {
60  array<float> valuesForFaction = {};
61  for (int j = 0; j < valuesSize; j++)
62  {
63  valuesForFaction.Insert(values[i * valuesSize + j]);
64  }
65 
66  dataCollector.AddStatsToFaction(factionKeys[i], valuesForFaction);
67  }
68 
69  SCR_PlayerData playerData = dataCollector.GetPlayerData(0, true, false); // Use 0 as ID for local player, as this is always on the client
70  playerData.SetStats(stats);
71  playerData.SetPreviousStats(previousStats);
72 
73  if (m_OnDataReceived)
74  m_OnDataReceived.Invoke(playerData);
75  }
76 }
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_PlayerData
Definition: SCR_PlayerData.c:2
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
m_OnDataReceived
SCR_DataCollectorCommunicationComponentClass m_OnDataReceived
Rpc_DoSendData
void Rpc_DoSendData(notnull array< float > stats, notnull array< float > previousStats, notnull array< FactionKey > factionKeys, notnull array< float > values, int valuesSize)
Definition: SCR_DataCollectorCommunicationComponent.c:38
SendData
void SendData(notnull SCR_PlayerData playerData, notnull array< FactionKey > factionKeys, notnull array< float > values, int valuesSize)
Definition: SCR_DataCollectorCommunicationComponent.c:25
SCR_DataCollectorCommunicationComponentClass
Definition: SCR_DataCollectorCommunicationComponent.c:2
GetOnDataReceived
notnull ScriptInvoker GetOnDataReceived()
Definition: SCR_DataCollectorCommunicationComponent.c:11
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180