Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DataCollectorShootingModule.c
Go to the documentation of this file.
3{
4 //TODO: Remove this map
6
7 //------------------------------------------------------------------------------------------------
8 protected override void AddInvokers(IEntity player)
9 {
10 super.AddInvokers(player);
11 if (!player)
12 return;
13
15
16 if (!compartmentAccessComponent)
17 return;
18
19 compartmentAccessComponent.GetOnCompartmentEntered().Insert(OnCompartmentEntered);
20 compartmentAccessComponent.GetOnCompartmentLeft().Insert(OnCompartmentLeft);
21
22 EventHandlerManagerComponent eventHandlerManager = EventHandlerManagerComponent.Cast(player.FindComponent(EventHandlerManagerComponent));
23 if (!eventHandlerManager)
24 return;
25
26 eventHandlerManager.RegisterScriptHandler("OnProjectileShot", this, OnWeaponFired);
27 eventHandlerManager.RegisterScriptHandler("OnGrenadeThrown", this, OnGrenadeThrown);
28 }
29
30 //------------------------------------------------------------------------------------------------
31 protected void OnWeaponFired(int playerID, BaseWeaponComponent weapon, IEntity entity)
32 {
33 SCR_PlayerData playerData = GetGame().GetDataCollector().GetPlayerData(playerID);
34
35 //In the future we will use Weapon.GetWeaponType() and Weapon.GetWeaponSubtype() to determine the weapon shot and add it to the player's profile
36 //For now, simply count a shot
37 playerData.AddStat(SCR_EDataStats.SHOTS, 1);
38 }
39
40 //------------------------------------------------------------------------------------------------
41 protected void OnGrenadeThrown(int playerID, BaseWeaponComponent weapon, IEntity entity)
42 {
43 if (!weapon)
44 return;
45
46 SCR_PlayerData playerData = GetGame().GetDataCollector().GetPlayerData(playerID);
47
48 //Not counting smoke grenade 'cause it deals no damage. TO DO: Count it as a different specialization operation
49 if (weapon.GetWeaponType() == EWeaponType.WT_SMOKEGRENADE)
50 return;
51
52 playerData.AddStat(SCR_EDataStats.GRENADES_THROWN, 1);
53 }
54
55 //------------------------------------------------------------------------------------------------
56 protected override void RemoveInvokers(IEntity player)
57 {
58 super.RemoveInvokers(player);
59 if (!player)
60 return;
61
63
64 if (!compartmentAccessComponent)
65 return;
66
67 compartmentAccessComponent.GetOnCompartmentEntered().Remove(OnCompartmentEntered);
68 compartmentAccessComponent.GetOnCompartmentLeft().Remove(OnCompartmentLeft);
69
70 EventHandlerManagerComponent eventHandlerManager = EventHandlerManagerComponent.Cast(player.FindComponent(EventHandlerManagerComponent));
71 if (!eventHandlerManager)
72 return;
73
74 eventHandlerManager.RemoveScriptHandler("OnProjectileShot", this, OnWeaponFired);
75 eventHandlerManager.RemoveScriptHandler("OnGrenadeThrown", this, OnGrenadeThrown);
76 }
77
78 //Players who enter a vehicle do not need to be tracked as possible shooters, unless using a turret
79 //------------------------------------------------------------------------------------------------
80 protected void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
81 {
82 BaseCompartmentSlot compartment = manager.FindCompartment(slotID, mgrID);
83
84 //Turrets can shoot
85 if (!compartment || !compartment.GetOccupant() || compartment.GetType() == ECompartmentType.TURRET)
86 return;
87
88 PlayerManager playerManager = GetGame().GetPlayerManager();
89
90 int playerID = playerManager.GetPlayerIdFromControlledEntity(compartment.GetOccupant());
91
92 m_mTrackedPossibleShooters.Remove(playerID);
93 }
94
95 //Players who leave a vehicle can be shooters
96 //------------------------------------------------------------------------------------------------
97 protected void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
98 {
99 BaseCompartmentSlot compartment = manager.FindCompartment(slotID, mgrID);
100 if (!compartment)
101 return;
102
103 if (!compartment.GetOccupant())
104 return;
105
106 PlayerManager playerManager = GetGame().GetPlayerManager();
107
108 int playerID = playerManager.GetPlayerIdFromControlledEntity(compartment.GetOccupant());
109 if (playerID == 0) // Non-player character
110 return;
111
112 m_mTrackedPossibleShooters.Insert(playerID, compartment.GetOccupant());
113 }
114
115 //------------------------------------------------------------------------------------------------
116 override void OnPlayerDisconnected(int playerID, IEntity controlledEntity = null)
117 {
118 controlledEntity = m_mTrackedPossibleShooters.Get(playerID);
119 super.OnPlayerDisconnected(playerID, controlledEntity);
120
121 m_mTrackedPossibleShooters.Remove(playerID);
122 }
123
124 //------------------------------------------------------------------------------------------------
125 override void OnPlayerSpawned(int playerID, IEntity controlledEntity)
126 {
127 super.OnPlayerSpawned(playerID, controlledEntity);
128 m_mTrackedPossibleShooters.Insert(playerID, controlledEntity);
129 }
130
131#ifdef ENABLE_DIAG
132 //------------------------------------------------------------------------------------------------
133 override void OnControlledEntityChanged(IEntity from, IEntity to)
134 {
135 super.OnControlledEntityChanged(from, to);
136
137 if (to)
138 {
139 int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(to);
140 m_mTrackedPossibleShooters.Insert(playerID, to);
141 }
142 else if (from)
143 {
144 int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(from);
145 m_mTrackedPossibleShooters.Remove(playerID);
146 }
147 }
148#endif
149
150 override void OnAIKilled(IEntity AIEntity, IEntity killerEntity, notnull Instigator instigator, notnull SCR_InstigatorContextData instigatorContextData)
151 {
152 super.OnAIKilled(AIEntity, killerEntity, instigator, instigatorContextData);
153
154 //This method adds a kill no matter the mean by which the AI was killed.
155 //The name of the module is a little bit misleading
156 if (instigator.GetInstigatorType() != InstigatorType.INSTIGATOR_PLAYER)
157 return;
158
159 //~ Not a player kill so ignore (Like suicide)
160 if (!instigatorContextData.HasAnyVictimKillerRelation(SCR_ECharacterDeathStatusRelations.KILLED_BY_ENEMY_PLAYER | SCR_ECharacterDeathStatusRelations.KILLED_BY_FRIENDLY_PLAYER))
161 return;
162
163 int killerId = instigator.GetInstigatorPlayerID();
164
165 SCR_PlayerData killerData = GetGame().GetDataCollector().GetPlayerData(killerId);
166 if (!killerData)
167 return;
168
169 //~ Add an AI kill or friendly kill stats
170 if (instigatorContextData.HasAnyVictimKillerRelation(SCR_ECharacterDeathStatusRelations.KILLED_BY_ENEMY_PLAYER))
171 {
172 if (!instigatorContextData.IsEnemyKillPunished(SCR_EDisguisedKillingPunishment.WARCRIME))
173 killerData.AddStat(SCR_EDataStats.AI_KILLS);
174 //~ Killing while disguised is a warcrime
175 else
176 killerData.AddStat(SCR_EDataStats.FRIENDLY_AI_KILLS);
177
178 return;
179 }
180 else
181 {
182 if (instigatorContextData.DoesPlayerKillCountAsTeamKill())
183 killerData.AddStat(SCR_EDataStats.FRIENDLY_AI_KILLS);
184
185 return;
186 }
187 }
188
189 //------------------------------------------------------------------------------------------------
190 override void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator instigator, notnull SCR_InstigatorContextData instigatorContextData)
191 {
192 super.OnPlayerKilled(playerId, playerEntity, killerEntity, instigator, instigatorContextData);
193 m_mTrackedPossibleShooters.Remove(playerId);
194
195 SCR_PlayerData playerData = GetGame().GetDataCollector().GetPlayerData(playerId);
196 playerData.AddStat(SCR_EDataStats.DEATHS);
197
198 //~ Also tracks Possessed AI as if player kill as the data is not seen by player
199 if (instigator.GetInstigatorType() != InstigatorType.INSTIGATOR_PLAYER)
200 return;
201
202 //~ Not a player kill so ignore (Like suicide)
203 if (!instigatorContextData.HasAnyVictimKillerRelation(SCR_ECharacterDeathStatusRelations.KILLED_BY_ENEMY_PLAYER | SCR_ECharacterDeathStatusRelations.KILLED_BY_FRIENDLY_PLAYER))
204 return;
205
206 int killerId = instigator.GetInstigatorPlayerID();
207
208 SCR_PlayerData killerData = GetGame().GetDataCollector().GetPlayerData(killerId);
209 if (!killerData)
210 return;
211
212 SCR_ECharacterControlType victimControlType = instigatorContextData.GetVictimCharacterControlType();
213
214 //~ Possessed AI count towards AI kills
215 if (victimControlType == SCR_ECharacterControlType.POSSESSED_AI)
216 {
217 //~ Add an AI kill or friendly kill stats
218 if (instigatorContextData.HasAnyVictimKillerRelation(SCR_ECharacterDeathStatusRelations.KILLED_BY_ENEMY_PLAYER))
219 {
220 if (!instigatorContextData.IsEnemyKillPunished(SCR_EDisguisedKillingPunishment.WARCRIME))
221 killerData.AddStat(SCR_EDataStats.AI_KILLS);
222 //~ Killing while disguised is a warcrime
223 else
224 killerData.AddStat(SCR_EDataStats.FRIENDLY_AI_KILLS);
225
226 return;
227 }
228 else
229 {
230 if (instigatorContextData.DoesPlayerKillCountAsTeamKill(possessedKillsCount: true))
231 killerData.AddStat(SCR_EDataStats.FRIENDLY_AI_KILLS);
232
233 return;
234 }
235 }
236
237 //~ Add kill or friendly kill stats
238 if (instigatorContextData.HasAnyVictimKillerRelation(SCR_ECharacterDeathStatusRelations.KILLED_BY_ENEMY_PLAYER))
239 {
240 if (!instigatorContextData.IsEnemyKillPunished(SCR_EDisguisedKillingPunishment.WARCRIME))
241 killerData.AddStat(SCR_EDataStats.KILLS);
242 //~ Killing while disguised is a warcrime
243 else
244 killerData.AddStat(SCR_EDataStats.FRIENDLY_KILLS);
245
246 return;
247 }
248 else
249 {
250 if (instigatorContextData.DoesPlayerKillCountAsTeamKill())
251 killerData.AddStat(SCR_EDataStats.FRIENDLY_KILLS);
252
253 return;
254 }
255
256 }
257
258 //------------------------------------------------------------------------------------------------
259 override void Update(float timeTick)
260 {
261 //If there's no data collector, do nothing
262 if (!GetGame().GetDataCollector())
263 return;
264
265 m_fTimeSinceUpdate += timeTick;
266
268 return;
269
270 SCR_PlayerData playerData;
271 int playerId;
272
273 for (int i = m_mTrackedPossibleShooters.Count() - 1; i >= 0; i--)
274 {
275
276 playerId = m_mTrackedPossibleShooters.GetKey(i);
277 playerData = GetGame().GetDataCollector().GetPlayerData(playerId);
278
279 //DEBUG display
280#ifdef ENABLE_DIAG
282 {
283 m_StatsVisualization.Get(SCR_EShootingModuleStats.DEATHS).SetText((playerData.GetStat(SCR_EDataStats.DEATHS) - playerData.GetStat(SCR_EDataStats.DEATHS, false)).ToString());
284 m_StatsVisualization.Get(SCR_EShootingModuleStats.PLAYERKILLS).SetText((playerData.GetStat(SCR_EDataStats.KILLS) - playerData.GetStat(SCR_EDataStats.KILLS, false)).ToString());
285 m_StatsVisualization.Get(SCR_EShootingModuleStats.AIKILLS).SetText((playerData.GetStat(SCR_EDataStats.AI_KILLS) - playerData.GetStat(SCR_EDataStats.AI_KILLS, false)).ToString());
286 m_StatsVisualization.Get(SCR_EShootingModuleStats.FRIENDLYPLAYERKILLS).SetText((playerData.GetStat(SCR_EDataStats.FRIENDLY_KILLS) - playerData.GetStat(SCR_EDataStats.FRIENDLY_KILLS, false)).ToString());
287 m_StatsVisualization.Get(SCR_EShootingModuleStats.FRIENDLYAIKILLS).SetText((playerData.GetStat(SCR_EDataStats.FRIENDLY_AI_KILLS) - playerData.GetStat(SCR_EDataStats.FRIENDLY_AI_KILLS, false)).ToString());
288 m_StatsVisualization.Get(SCR_EShootingModuleStats.BULLETSSHOT).SetText((playerData.GetStat(SCR_EDataStats.SHOTS) - playerData.GetStat(SCR_EDataStats.SHOTS, false)).ToString());
289 m_StatsVisualization.Get(SCR_EShootingModuleStats.GRENADESTHROWN).SetText((playerData.GetStat(SCR_EDataStats.GRENADES_THROWN) - playerData.GetStat(SCR_EDataStats.GRENADES_THROWN, false)).ToString());
290 }
291#endif
292 }
294 }
295
296#ifdef ENABLE_DIAG
297 //------------------------------------------------------------------------------------------------
298 override void CreateVisualization()
299 {
300 super.CreateVisualization();
302 return;
303
304 CreateEntry("Deaths: ", 0, SCR_EShootingModuleStats.DEATHS);
305 CreateEntry("Player Kills: ", 0, SCR_EShootingModuleStats.PLAYERKILLS);
306 CreateEntry("AI Kills: ", 0, SCR_EShootingModuleStats.AIKILLS);
307 CreateEntry("Friendly Player Kills: ", 0, SCR_EShootingModuleStats.FRIENDLYPLAYERKILLS);
308 CreateEntry("Friendly AI Kills: ", 0, SCR_EShootingModuleStats.FRIENDLYAIKILLS);
309 CreateEntry("Bullets Shot: ", 0, SCR_EShootingModuleStats.BULLETSSHOT);
310 CreateEntry("Grenades Thrown: ", 0, SCR_EShootingModuleStats.GRENADESTHROWN);
311 }
312#endif
313};
314
315#ifdef ENABLE_DIAG
316enum SCR_EShootingModuleStats
317{
318 DEATHS,
319 PLAYERKILLS,
320 AIKILLS,
321 FRIENDLYPLAYERKILLS,
322 FRIENDLYAIKILLS,
323 BULLETSSHOT,
324 GRENADESTHROWN
325};
326#endif
ECompartmentType
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_DataCollectorComponent GetDataCollector()
Definition game.c:110
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_ECharacterControlType
What kind of controller the character or (in some cases vehicle) has, eg: AI, Player,...
SCR_EDataStats
@ DEATHS
Deaths.
proto external Managed FindComponent(typename typeName)
ScriptInvoker GetOnCompartmentEntered(bool createNew=true)
ScriptInvoker GetOnCompartmentLeft(bool createNew=true)
void OnControlledEntityChanged(IEntity from, IEntity to)
ref map< int, TextWidget > m_StatsVisualization
void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
override void OnAIKilled(IEntity AIEntity, IEntity killerEntity, notnull Instigator instigator, notnull SCR_InstigatorContextData instigatorContextData)
override void OnPlayerDisconnected(int playerID, IEntity controlledEntity=null)
void OnGrenadeThrown(int playerID, BaseWeaponComponent weapon, IEntity entity)
override void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator instigator, notnull SCR_InstigatorContextData instigatorContextData)
void OnWeaponFired(int playerID, BaseWeaponComponent weapon, IEntity entity)
override void OnPlayerSpawned(int playerID, IEntity controlledEntity)
void AddStat(SCR_EDataStats stat, float amount=1, bool temp=true)
float GetStat(SCR_EDataStats stat, bool newStat=true)
static SCR_PlayerData GetPlayerData(int playerID)
Definition Types.c:486
InstigatorType
EWeaponType
Definition EWeaponType.c:13