Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapMarkerSyncComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Misc", description: "")]
2 class SCR_MapMarkerSyncComponentClass : ScriptComponentClass
3 {
4 }
5 
8 class SCR_MapMarkerSyncComponent : ScriptComponent
9 {
10  protected bool m_bIsDeleteRestricted = true; // server side only, only allow marker owners to delete their placed markers
11  protected int m_iPlacedMarkerLimit = 10; // server side only, limit of allowed synchronized markers per client
12  protected ref array<int> m_OwnedMarkers = {}; // server side only, list of markers owned by this controller to enforce limits
13 
14  //------------------------------------------------------------------------------------------------
19  {
20  Rpc(RPC_AskAddStaticMarker, marker);
21  }
22 
23  //------------------------------------------------------------------------------------------------
27  void AskRemoveStaticMarker(int markerID)
28  {
29  SCR_MapMarkerManagerComponent markerMgr = SCR_MapMarkerManagerComponent.GetInstance();
30  if (!markerMgr)
31  return;
32 
33  SCR_MapMarkerBase marker = markerMgr.GetStaticMarkerByID(markerID);
34  if (!marker) // client side sanity check
35  return;
36 
37  Rpc(RPC_AskRemoveStaticMarker, markerID);
38  }
39 
40  //------------------------------------------------------------------------------------------------
45  {
46  for (int i; i < m_OwnedMarkers.Count(); i++)
47  {
48  if (m_OwnedMarkers.IsIndexValid(i))
49  {
51  i--;
52  }
53  }
54  }
55 
56  //------------------------------------------------------------------------------------------------
59  void RemovePlayerMarker(int markerID)
60  {
61  m_OwnedMarkers.RemoveItemOrdered(markerID);
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  // RPC
66  //------------------------------------------------------------------------------------------------
67 
68  //------------------------------------------------------------------------------------------------
69  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
70  protected void RPC_AskAddStaticMarker(SCR_MapMarkerBase markerData)
71  {
72  SCR_MapMarkerManagerComponent markerMgr = SCR_MapMarkerManagerComponent.GetInstance();
73  if (!markerMgr || m_iPlacedMarkerLimit <= 0)
74  return;
75 
76  if (m_OwnedMarkers.Count() >= m_iPlacedMarkerLimit) // remove first if over limit
78 
79  markerMgr.AssignMarkerUID(markerData);
80 
81  markerData.SetMarkerOwnerID(SCR_PlayerController.Cast(GetOwner()).GetPlayerId());
82  m_OwnedMarkers.Insert(markerData.GetMarkerID());
83 
84  markerMgr.OnAddSynchedMarker(markerData); // add server side
85  markerMgr.OnAskAddStaticMarker(markerData);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
90  protected void RPC_AskRemoveStaticMarker(int markerID)
91  {
92  SCR_MapMarkerManagerComponent markerMgr = SCR_MapMarkerManagerComponent.GetInstance();
93  if (!markerMgr)
94  return;
95 
96  SCR_MapMarkerBase marker = markerMgr.GetStaticMarkerByID(markerID);
97  if (!marker
98  || marker.GetMarkerOwnerID() == -1 // cannot delete server marker by client request
99  ||(m_bIsDeleteRestricted && marker.GetMarkerOwnerID() != SCR_PlayerController.Cast(GetOwner()).GetPlayerId())) // delete by anyone not allowed && is not the callers marker
100  return;
101 
102  if (marker.GetMarkerOwnerID() != -1) // dedicated servers dont track their marker limits
103  {
104  PlayerController ownerController = GetGame().GetPlayerManager().GetPlayerController(marker.GetMarkerOwnerID());
105  if (ownerController)
106  {
107  SCR_MapMarkerSyncComponent ownerSyncComp = SCR_MapMarkerSyncComponent.Cast(ownerController.FindComponent(SCR_MapMarkerSyncComponent));
108  if (ownerSyncComp)
109  ownerSyncComp.RemovePlayerMarker(markerID); // this has to be called on this component of the markers owner, not the RPC sender
110  }
111  }
112 
113  markerMgr.OnRemoveSynchedMarker(markerID); // remove server side
114  markerMgr.OnAskRemoveStaticMarker(markerID);
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  override void OnPostInit(IEntity owner)
119  {
120  SCR_MissionHeader header = SCR_MissionHeader.Cast(GetGame().GetMissionHeader());
121  if (header)
122  {
123  m_iPlacedMarkerLimit = header.m_iMapMarkerLimitPerPlayer;
124  m_bIsDeleteRestricted = !header.m_bMapMarkerEnableDeleteByAnyone;
125  }
126  }
127 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
m_OwnedMarkers
protected ref array< int > m_OwnedMarkers
Definition: SCR_MapMarkerSyncComponent.c:12
SCR_PlayerController
Definition: SCR_PlayerController.c:31
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
SCR_MapMarkerBase
Definition: SCR_MapMarkerBase.c:3
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_MapMarkerSyncComponentClass
Definition: SCR_MapMarkerSyncComponent.c:2
AskRemoveStaticMarker
void AskRemoveStaticMarker(int markerID)
Definition: SCR_MapMarkerSyncComponent.c:27
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_MapMarkerSyncComponent.c:118
AskAddStaticMarker
void AskAddStaticMarker(notnull SCR_MapMarkerBase marker)
Definition: SCR_MapMarkerSyncComponent.c:18
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
RemovePlayerMarker
void RemovePlayerMarker(int markerID)
Definition: SCR_MapMarkerSyncComponent.c:59
m_bIsDeleteRestricted
SCR_MapMarkerSyncComponentClass m_bIsDeleteRestricted
RPC_AskAddStaticMarker
protected void RPC_AskAddStaticMarker(SCR_MapMarkerBase markerData)
Definition: SCR_MapMarkerSyncComponent.c:70
RPC_AskRemoveStaticMarker
protected void RPC_AskRemoveStaticMarker(int markerID)
Definition: SCR_MapMarkerSyncComponent.c:90
ClearOwnedMarkers
void ClearOwnedMarkers()
Definition: SCR_MapMarkerSyncComponent.c:44
m_iPlacedMarkerLimit
protected int m_iPlacedMarkerLimit
Definition: SCR_MapMarkerSyncComponent.c:11
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1
GetPlayerId
proto external int GetPlayerId()
Definition: SCR_SpawnRequestComponent.c:39
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180