Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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")]
5
6class SCR_FiringRangeScoringComponent : SCR_BaseGameModeComponent
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(notnull SCR_InstigatorContextData instigatorContextData)
36 {
37 int playerId = instigatorContextData.GetVictimPlayerID();
38
39 // Remove player from assigned firing line
40 s_Manager.RemoveAssignedPlayerFromFireline(playerId);
41
42 ClearScore(playerId);
43 // If player is in Firing line area and has his line in scoreborad, remove him from it.
44 if (s_Manager.IsPlayerInFiringRangeArea(playerId))
45 s_Manager.RemovePlayerFromArea(playerId);
46 }
47
48 //------------------------------------------------------------------------------------------------
52 {
54 playerInfo.m_iID = playerID;
55 m_aAllPlayersInfo.Insert(playerInfo);
56 Replication.BumpMe();
57
58 return playerInfo;
59 }
60
61 //------------------------------------------------------------------------------------------------
64 void RemovePlayer(int playerID)
65 {
66 m_aAllPlayersInfo.RemoveItem(GetPlayerScoreInfo(playerID));
67 Replication.BumpMe();
68 }
69
70 //------------------------------------------------------------------------------------------------
73 void ClearScore(int playerID)
74 {
75 SCR_PlayerScoreInfoFiringRange playerScoreInfoFiringRange = GetPlayerScoreInfo(playerID);
76 if (playerScoreInfoFiringRange)
77 playerScoreInfoFiringRange.Clear();
78 }
79
80 //------------------------------------------------------------------------------------------------
84 void AddScore(int playerID, int scorePoints)
85 {
86 SCR_PlayerScoreInfoFiringRange playerScoreInfoFiringRange = GetPlayerScoreInfo(playerID);
87 if (playerScoreInfoFiringRange)
88 playerScoreInfoFiringRange.m_iScore = playerScoreInfoFiringRange.GetScore() + scorePoints;
89 }
90
91 //------------------------------------------------------------------------------------------------
95 void SetScoreMax(int playerID, int scorePointsMax)
96 {
97 SCR_PlayerScoreInfoFiringRange playerScoreInfoFiringRange = GetPlayerScoreInfo(playerID);
98 if (playerScoreInfoFiringRange)
99 playerScoreInfoFiringRange.m_iScoreMax = scorePointsMax;
100 }
101
102 //------------------------------------------------------------------------------------------------
106 int GetScore(int playerID)
107 {
108 SCR_PlayerScoreInfoFiringRange playerScoreInfoFiringRange = GetPlayerScoreInfo(playerID);
109 if (playerScoreInfoFiringRange)
110 return playerScoreInfoFiringRange.GetScore();
111 else return 0;
112 }
113
114 //------------------------------------------------------------------------------------------------
117 {
118 return m_aAllPlayersInfo.Count();
119 }
120
121 //------------------------------------------------------------------------------------------------
124 private SCR_PlayerScoreInfoFiringRange GetPlayerScoreInfo(int playerID)
125 {
126 for (int i = 0, count = m_aAllPlayersInfo.Count(); i < count; i++)
127 {
128 if (m_aAllPlayersInfo[i].m_iID == playerID)
129 return m_aAllPlayersInfo[i];
130 }
131
132 return null;
133 }
134
135 //------------------------------------------------------------------------------------------------
138 int GetAllPlayersScoreInfo(notnull out array<SCR_PlayerScoreInfoFiringRange> output)
139 {
140 output.Clear();
141 int y = 0;
142
143 for (int i = 0, count = m_aAllPlayersInfo.Count(); i < count; i++)
144 {
145 output.Insert(m_aAllPlayersInfo[i]);
146 Replication.BumpMe();
147 y++;
148 }
149
150 return y;
151 }
152
153 //------------------------------------------------------------------------------------------------
154 override void OnPostInit(IEntity owner)
155 {
156 SetEventMask(owner, EntityEvent.INIT);
157 }
158
159 //------------------------------------------------------------------------------------------------
160 override void EOnInit(IEntity owner)
161 {
162 SCR_BaseGameMode gameMode = SCR_BaseGameMode.Cast(GetGame().GetGameMode());
163 if (!gameMode)
164 return;
165
166 gameMode.GetOnPlayerConnected().Insert(AddPlayer);
167 gameMode.GetOnPlayerDisconnected().Insert(OnDisconnected);
168 gameMode.GetOnPlayerKilled().Insert(OnKill);
169
170 array<int> playerIds = {};
171 GetGame().GetPlayerManager().GetPlayers(playerIds);
172
173 foreach (int id : playerIds)
174 {
175 AddPlayer(id);
176 }
177 }
178
179 //------------------------------------------------------------------------------------------------
180 // constructor
184 void SCR_FiringRangeScoringComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
185 {
186 s_Manager = SCR_FiringRangeManager.Cast(ent);
187 }
188}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void AddPlayer(int playerID)
Called on the server (authority).
SCR_BaseGameMode GetGameMode()
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void RemovePlayer(int playerID)
void AddScore(int playerID, int scorePoints)
ref array< ref SCR_PlayerScoreInfoFiringRange > m_aAllPlayersInfo
Contains score info of all the players.
SCR_FiringRangeScoringComponentClass s_Manager
void OnKill(notnull SCR_InstigatorContextData instigatorContextData)
int GetScore(int playerID)
void ClearScore(int playerID)
void SetScoreMax(int playerID, int scorePointsMax)
void OnDisconnected(int playerID)
enum EVehicleType IEntity
Main replication API.
Definition Replication.c:14
ScriptInvokerBase< SCR_BaseGameMode_OnPlayerDisconnected > GetOnPlayerDisconnected()
ScriptInvokerBase< SCR_BaseGameMode_PlayerId > GetOnPlayerConnected()
ScriptInvokerBase< SCR_BaseGameMode_OnControllableDestroyed > GetOnPlayerKilled()
override void EOnInit(IEntity owner)
EntityEvent
Various entity events.
Definition EntityEvent.c:14