Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FiringRangeScoringComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/FiringRange", description: "Handles Score on Firing Range.", color: "0 0 255 255")]
3 {
4 }
5 
7 {
9 
10  [RplProp()]
11  protected ref array<ref SCR_PlayerScoreInfoFiringRange> m_aAllPlayersInfo = {};
12 
13  //------------------------------------------------------------------------------------------------
15  void OnDisconnected(int playerID)
16  {
17  RemovePlayer(playerID);
18 
19  // Remove player from assigned firing line
20  s_Manager.RemoveAssignedPlayerFromFireline(playerID);
21 
22  ClearScore(playerID);
23  // If player is in Firing line area and has his line in scoreborad, remove him from it.
24  if (s_Manager.IsPlayerInFiringRangeArea(playerID))
25  s_Manager.RemovePlayerFromArea(playerID);
26 
27  }
28 
29  //------------------------------------------------------------------------------------------------
35  void OnKill(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
36  {
37  // Remove player from assigned firing line
38  s_Manager.RemoveAssignedPlayerFromFireline(playerId);
39 
40  ClearScore(playerId);
41  // If player is in Firing line area and has his line in scoreborad, remove him from it.
42  if (s_Manager.IsPlayerInFiringRangeArea(playerId))
43  s_Manager.RemovePlayerFromArea(playerId);
44  }
45 
46  //------------------------------------------------------------------------------------------------
50  {
52  playerInfo.m_iID = playerID;
53  m_aAllPlayersInfo.Insert(playerInfo);
54  Replication.BumpMe();
55 
56  return playerInfo;
57  }
58 
59  //------------------------------------------------------------------------------------------------
62  void RemovePlayer(int playerID)
63  {
64  m_aAllPlayersInfo.RemoveItem(GetPlayerScoreInfo(playerID));
65  Replication.BumpMe();
66  }
67 
68  //------------------------------------------------------------------------------------------------
71  void ClearScore(int playerID)
72  {
73  SCR_PlayerScoreInfoFiringRange playerScoreInfoFiringRange = GetPlayerScoreInfo(playerID);
74  if (playerScoreInfoFiringRange)
75  playerScoreInfoFiringRange.Clear();
76  }
77 
78  //------------------------------------------------------------------------------------------------
82  void AddScore(int playerID, int scorePoints)
83  {
84  SCR_PlayerScoreInfoFiringRange playerScoreInfoFiringRange = GetPlayerScoreInfo(playerID);
85  if (playerScoreInfoFiringRange)
86  playerScoreInfoFiringRange.m_iScore = playerScoreInfoFiringRange.GetScore() + scorePoints;
87  }
88 
89  //------------------------------------------------------------------------------------------------
93  void SetScoreMax(int playerID, int scorePointsMax)
94  {
95  SCR_PlayerScoreInfoFiringRange playerScoreInfoFiringRange = GetPlayerScoreInfo(playerID);
96  if (playerScoreInfoFiringRange)
97  playerScoreInfoFiringRange.m_iScoreMax = scorePointsMax;
98  }
99 
100  //------------------------------------------------------------------------------------------------
104  int GetScore(int playerID)
105  {
106  SCR_PlayerScoreInfoFiringRange playerScoreInfoFiringRange = GetPlayerScoreInfo(playerID);
107  if (playerScoreInfoFiringRange)
108  return playerScoreInfoFiringRange.GetScore();
109  else return 0;
110  }
111 
112  //------------------------------------------------------------------------------------------------
115  {
116  return m_aAllPlayersInfo.Count();
117  }
118 
119  //------------------------------------------------------------------------------------------------
123  {
124  for (int i = 0, count = m_aAllPlayersInfo.Count(); i < count; i++)
125  {
126  if (m_aAllPlayersInfo[i].m_iID == playerID)
127  return m_aAllPlayersInfo[i];
128  }
129 
130  return null;
131  }
132 
133  //------------------------------------------------------------------------------------------------
136  int GetAllPlayersScoreInfo(notnull out array<SCR_PlayerScoreInfoFiringRange> output)
137  {
138  output.Clear();
139  int y = 0;
140 
141  for (int i = 0, count = m_aAllPlayersInfo.Count(); i < count; i++)
142  {
143  output.Insert(m_aAllPlayersInfo[i]);
144  Replication.BumpMe();
145  y++;
146  }
147 
148  return y;
149  }
150 
151  //------------------------------------------------------------------------------------------------
152  override void OnPostInit(IEntity owner)
153  {
154  SetEventMask(owner, EntityEvent.INIT);
155  }
156 
157  //------------------------------------------------------------------------------------------------
158  override void EOnInit(IEntity owner)
159  {
161  if (!gameMode)
162  return;
163 
164  gameMode.GetOnPlayerConnected().Insert(AddPlayer);
165  gameMode.GetOnPlayerDisconnected().Insert(OnDisconnected);
166  gameMode.GetOnPlayerKilled().Insert(OnKill);
167 
168  array<int> playerIds = {};
169  GetGame().GetPlayerManager().GetPlayers(playerIds);
170 
171  foreach (int id : playerIds)
172  {
173  AddPlayer(id);
174  }
175  }
176 
177  //------------------------------------------------------------------------------------------------
178  // constructor
182  void SCR_FiringRangeScoringComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
183  {
184  s_Manager = SCR_FiringRangeManager.Cast(ent);
185  }
186 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetPlayerScoreInfo
private SCR_PlayerScoreInfoFiringRange GetPlayerScoreInfo(int playerID)
Definition: SCR_FiringRangeScoringComponent.c:122
s_Manager
SCR_FiringRangeScoringComponentClass s_Manager
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SetScoreMax
void SetScoreMax(int playerID, int scorePointsMax)
Definition: SCR_FiringRangeScoringComponent.c:93
m_iID
protected int m_iID
Definition: SCR_AmbientPatrolSpawnPointComponent.c:42
AddScore
void AddScore(int playerID, int scorePoints)
Definition: SCR_FiringRangeScoringComponent.c:82
Instigator
Definition: Instigator.c:6
SCR_PlayerScoreInfoFiringRange
Holds scoring data of players.
Definition: SCR_PlayerScoreInfoFiringRange.c:3
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
GetAllPlayersScoreInfo
int GetAllPlayersScoreInfo(notnull out array< SCR_PlayerScoreInfoFiringRange > output)
Definition: SCR_FiringRangeScoringComponent.c:136
ClearScore
void ClearScore(int playerID)
Definition: SCR_FiringRangeScoringComponent.c:71
RemovePlayer
void RemovePlayer(int playerID)
Definition: SCR_FiringRangeScoringComponent.c:62
SCR_FiringRangeManager
Definition: SCR_FiringRangeManager.c:7
m_aAllPlayersInfo
protected ref array< ref SCR_PlayerScoreInfoFiringRange > m_aAllPlayersInfo
Contains score info of all the players.
Definition: SCR_FiringRangeScoringComponent.c:11
SCR_FiringRangeScoringComponentClass
Definition: SCR_FiringRangeScoringComponent.c:2
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_FiringRangeScoringComponent.c:152
GetPlayersCount
int GetPlayersCount()
Definition: SCR_FiringRangeScoringComponent.c:114
GetScore
int GetScore(int playerID)
Definition: SCR_FiringRangeScoringComponent.c:104
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_FiringRangeScoringComponent.c:158
OnKill
void OnKill(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
Definition: SCR_FiringRangeScoringComponent.c:35
AddPlayer
SCR_PlayerScoreInfoFiringRange AddPlayer(int playerID)
Definition: SCR_FiringRangeScoringComponent.c:49
SCR_FiringRangeScoringComponent
void SCR_FiringRangeScoringComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_FiringRangeScoringComponent.c:182
SCR_BaseGameModeComponentClass
Definition: SCR_BaseGameModeComponent.c:2
OnDisconnected
void OnDisconnected(int playerID)
Definition: SCR_FiringRangeScoringComponent.c:15
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BaseGameModeComponent.c:199