Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayerSpawnPoint.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/GameMode", description: "")]
3 {
4 }
5 
6 class SCR_PlayerSpawnPoint : SCR_SpawnPoint
7 {
8  [Attribute("1", desc: "How often will the spawn's position be updated to match assigned player's position (in seconds).", category: "Player Spawn Point")]
9  protected float m_fUpdateInterval;
10 
11  [Attribute(desc: "Spawn point visualization. Original 'Info' attribute will be ignored.", category: "Player Spawn Point")]
12  protected ref SCR_PlayerUIInfo m_PlayerInfo;
13 
14  [RplProp(onRplName: "OnSetPlayerID")]
15  protected int m_iPlayerID;
16 
17  [RplProp()]
18  protected bool m_bIsActive;
19 
20  protected Faction m_CachedFaction;
21  protected IEntity m_TargetPlayer;
22 
23  //------------------------------------------------------------------------------------------------
25  IEntity GetTargetPlayer()
26  {
27  return m_TargetPlayer;
28  }
29 
30  //------------------------------------------------------------------------------------------------
34  void SetPlayerID(int playerID)
35  {
36  if (playerID == m_iPlayerID || !Replication.IsServer())
37  return;
38 
39  //--- Set and broadcast new player ID
40  m_iPlayerID = playerID;
41  OnSetPlayerID();
42  Replication.BumpMe();
43 
44  IEntity player = SCR_PossessingManagerComponent.GetPlayerMainEntity(m_iPlayerID);
45  if (player)
46  EnablePoint(m_iPlayerID, player);
47  else
49  }
50 
51  //------------------------------------------------------------------------------------------------
55  {
56  return m_iPlayerID;
57  }
58 
59  //------------------------------------------------------------------------------------------------
60  protected void OnSetPlayerID()
61  {
62  //--- Link player info
63  if (!m_PlayerInfo)
64  m_PlayerInfo = new SCR_PlayerUIInfo();
65 
66  m_PlayerInfo.SetPlayerID(m_iPlayerID);
67  LinkInfo(m_PlayerInfo);
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  protected override string GetSpawnPointName()
72  {
73  return GetGame().GetPlayerManager().GetPlayerName(m_iPlayerID);
74  }
75 
76  //------------------------------------------------------------------------------------------------
80  void EnablePoint(int playerId, IEntity playerEntity)
81  {
82  if (playerId != m_iPlayerID)
83  {
84  Print(string.Format("Couldn't enable point, mismatching playerId(s), expected: %1, got: %2", m_iPlayerID, playerId), LogLevel.WARNING);
85  return;
86  }
87 
88  m_CachedFaction = SCR_FactionManager.SGetPlayerFaction(m_iPlayerID);
89  m_TargetPlayer = playerEntity;
91  }
92 
93  //------------------------------------------------------------------------------------------------
96  void DisablePoint(int playerId)
97  {
98  if (playerId != m_iPlayerID)
99  {
100  Print(string.Format("Couldn't disable point, mismatching playerId(s), expected: %1, got: %2", m_iPlayerID, playerId), LogLevel.WARNING);
101  return;
102  }
103 
105 
106  m_CachedFaction = null;
107  m_TargetPlayer = null;
108  }
109 
110  //------------------------------------------------------------------------------------------------
111  protected void ActivateSpawnPoint()
112  {
113  SetFaction(m_CachedFaction);
114 
115  //--- Periodically refresh spawn's position
116  //--- Clients cannot access another player's entity directly, because it may not be streamed for them
117  ClearFlags(EntityFlags.STATIC, false);
118  GetGame().GetCallqueue().CallLater(UpdateSpawnPos, m_fUpdateInterval * 1000, true);
119 
120  m_bIsActive = true;
121  Replication.BumpMe();
122  }
123 
124  //------------------------------------------------------------------------------------------------
125  override bool IsSpawnPointActive()
126  {
127  return m_bIsActive;
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  protected void DeactivateSpawnPoint()
132  {
133  SetFaction(null);
134 
135  //--- Stop periodic refresh
136  SetFlags(EntityFlags.STATIC, false);
137  GetGame().GetCallqueue().Remove(UpdateSpawnPos);
138 
139  m_bIsActive = false;
140  Replication.BumpMe();
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  protected void UpdateSpawnPos()
145  {
146  if (!m_TargetPlayer)
147  return;
148 
149  vector pos = m_TargetPlayer.GetOrigin();
151  Rpc(UpdateSpawnPosBroadcast, pos);
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
156  protected void UpdateSpawnPosBroadcast(vector pos)
157  {
158  SetOrigin(pos);
159  }
160 
161  //------------------------------------------------------------------------------------------------
162  override void GetPositionAndRotation(out vector pos, out vector rot)
163  {
164  super.GetPositionAndRotation(pos, rot);
165 
166  if (m_TargetPlayer)
167  {
168  SCR_CompartmentAccessComponent compartmentAccessTarget = SCR_CompartmentAccessComponent.Cast(m_TargetPlayer.FindComponent(SCR_CompartmentAccessComponent));
169  IEntity vehicle = compartmentAccessTarget.GetVehicle();
170  if (vehicle)
171  rot = vehicle.GetAngles();
172  else
173  rot = m_TargetPlayer.GetAngles();
174  }
175  }
176 
177  //------------------------------------------------------------------------------------------------
178  protected Vehicle GetTargetVehicle()
179  {
180  if (!m_TargetPlayer)
181  return null;
182 
183  SCR_CompartmentAccessComponent compartmentAccessTarget = SCR_CompartmentAccessComponent.Cast(m_TargetPlayer.FindComponent(SCR_CompartmentAccessComponent));
184  if (!compartmentAccessTarget)
185  return null;
186 
187  return Vehicle.Cast(compartmentAccessTarget.GetVehicle());
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  override bool CanReserveFor_S(int playerId, out SCR_ESpawnResult result = SCR_ESpawnResult.SPAWN_NOT_ALLOWED)
192  {
193  //~ Check if super fails or not if the spawnpoint can be reserved
194  if (!super.CanReserveFor_S(playerId))
195  return false;
196 
197  Vehicle targetVehicle = GetTargetVehicle();
198  if (targetVehicle)
199  {
200  // See if there are any slots left
201  BaseCompartmentManagerComponent compartmentManager = BaseCompartmentManagerComponent.Cast(targetVehicle.FindComponent(BaseCompartmentManagerComponent));
202  array<BaseCompartmentSlot> compartments = {};
203  int count = compartmentManager.GetCompartments(compartments);
204  for (int i = 0; i < count; i++)
205  {
206  BaseCompartmentSlot slot = compartments[i];
207  if (!slot.IsOccupied() && !slot.IsReserved())
208  return true;
209  }
210 
211  // No slots available
212  result = SCR_ESpawnResult.NOT_ALLOWED_VEHICLE_FULL;
213  return false;
214  }
215 
216  // No vehicle and all other tests passed
217  return true;
218  }
219 
220  //------------------------------------------------------------------------------------------------
221  override bool PrepareSpawnedEntity_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
222  {
223  #ifdef _ENABLE_RESPAWN_LOGS
224  Print(string.Format("%1::PrepareSpawnedEntity_S(playerId: %2, data: %3, entity: %4)", Type().ToString(),
225  requestComponent.GetPlayerId(), data, entity), LogLevel.NORMAL);
226  #endif
227 
228  //~ Check if can prepare spawn from super
229  if (!super.PrepareSpawnedEntity_S(requestComponent, data, entity))
230  return false;
231 
232  // Spawned entity must have a compartment access component
233  SCR_CompartmentAccessComponent compartmentAccessPlayer = SCR_CompartmentAccessComponent.Cast(entity.FindComponent(SCR_CompartmentAccessComponent));
234  if (!compartmentAccessPlayer)
235  return false;
236 
237  // Spawning on vehicle; resolve vehicle logic
238  Vehicle targetVehicle = GetTargetVehicle();
239  if (targetVehicle)
240  return PrepareSpawnedEntityForVehicle_S(requestComponent, data, entity, targetVehicle);
241 
242  // All checks succeed
243  return true;
244  }
245 
246  //------------------------------------------------------------------------------------------------
247  protected bool PrepareSpawnedEntityForVehicle_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity, Vehicle vehicle)
248  {
249  #ifdef _ENABLE_RESPAWN_LOGS
250  Print(string.Format("%1::PrepareSpawnedEntityForVehicle_S(playerId: %2, data: %3, entity: %4, vehicle: %5)", Type().ToString(),
251  requestComponent.GetPlayerId(), data, entity, vehicle), LogLevel.NORMAL);
252  #endif
253 
255  BaseCompartmentManagerComponent compartmentManager = BaseCompartmentManagerComponent.Cast(vehicle.FindComponent(BaseCompartmentManagerComponent));
256 
257  array<BaseCompartmentSlot> compartments = {};
258  int count = compartmentManager.GetCompartments(compartments);
259  for (int i = 0; i < count; i++)
260  {
261  BaseCompartmentSlot slot = compartments[i];
262  if (!slot.IsOccupied() && (!slot.IsReserved() || slot.IsReservedBy(entity)))
263  return accessComponent.MoveInVehicle(vehicle, slot);
264  }
265 
266  return false;
267  }
268 
269  //------------------------------------------------------------------------------------------------
270  override bool CanFinalizeSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
271  {
272  if (!super.CanFinalizeSpawn_S(requestComponent, data, entity))
273  return false;
274 
275  // Do not finalize if character is in the middle of entering a vehicle, leave that to be resolved on the authority first
277  if (accessComponent && accessComponent.IsGettingIn())
278  return false;
279 
280  return true;
281  }
282 
283  //------------------------------------------------------------------------------------------------
284  override void OnFinalizeSpawnDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
285  {
286  }
287 
288  //------------------------------------------------------------------------------------------------
289  // destructor
291  {
292  GetGame().GetCallqueue().Remove(UpdateSpawnPos);
293  }
294 }
OnFinalizeSpawnDone_S
override void OnFinalizeSpawnDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
Definition: SCR_PlayerSpawnPoint.c:284
SCR_CompartmentAccessComponent
Definition: SCR_CompartmentAccessComponent.c:15
SCR_ESpawnResult
SCR_ESpawnResult
Definition: SCR_ESpawnResult.c:8
Attribute
SCR_PlayerSpawnPointClass SCR_SpawnPointClass Attribute("1", desc:"How often will the spawn's position be updated to match assigned player's position (in seconds).", category:"Player Spawn Point")
Definition: SCR_PlayerSpawnPoint.c:8
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
DeactivateSpawnPoint
protected void DeactivateSpawnPoint()
Definition: SCR_PlayerSpawnPoint.c:131
CanReserveFor_S
override bool CanReserveFor_S(int playerId, out SCR_ESpawnResult result=SCR_ESpawnResult.SPAWN_NOT_ALLOWED)
Definition: SCR_PlayerSpawnPoint.c:191
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_PlayerUIInfo
Definition: SCR_PlayerUIInfo.c:2
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
OnSetPlayerID
protected void OnSetPlayerID()
Definition: SCR_PlayerSpawnPoint.c:60
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
SCR_SpawnPointClass
Definition: SCR_SpawnPoint.c:2
~SCR_PlayerSpawnPoint
void ~SCR_PlayerSpawnPoint()
Definition: SCR_PlayerSpawnPoint.c:290
ActivateSpawnPoint
protected void ActivateSpawnPoint()
Definition: SCR_PlayerSpawnPoint.c:111
SCR_SpawnData
Definition: SCR_SpawnData.c:9
PrepareSpawnedEntityForVehicle_S
protected bool PrepareSpawnedEntityForVehicle_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity, Vehicle vehicle)
Definition: SCR_PlayerSpawnPoint.c:247
EnablePoint
void EnablePoint(int playerId, IEntity playerEntity)
Definition: SCR_PlayerSpawnPoint.c:80
GetPlayerID
int GetPlayerID()
Definition: SCR_PlayerSpawnPoint.c:54
GetSpawnPointName
protected override string GetSpawnPointName()
Definition: SCR_PlayerSpawnPoint.c:71
GetTargetVehicle
protected Vehicle GetTargetVehicle()
Definition: SCR_PlayerSpawnPoint.c:178
GetPositionAndRotation
override void GetPositionAndRotation(out vector pos, out vector rot)
Definition: SCR_PlayerSpawnPoint.c:162
CanFinalizeSpawn_S
override bool CanFinalizeSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
Definition: SCR_PlayerSpawnPoint.c:270
SetPlayerID
void SetPlayerID(int playerID)
Definition: SCR_PlayerSpawnPoint.c:34
PrepareSpawnedEntity_S
override bool PrepareSpawnedEntity_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
Definition: SCR_PlayerSpawnPoint.c:221
Faction
Definition: Faction.c:12
SCR_PlayerSpawnPointClass
Definition: SCR_PlayerSpawnPoint.c:2
SetFaction
void SetFaction(SCR_CampaignFaction faction)
Definition: SCR_CampaignMilitaryBaseComponent.c:1788
m_iPlayerID
SCR_EditorManagerCore m_iPlayerID
DisablePoint
void DisablePoint(int playerId)
Definition: SCR_PlayerSpawnPoint.c:96
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
m_bIsActive
SCR_HintSequenceComponentClass m_bIsActive
UpdateSpawnPos
protected void UpdateSpawnPos()
Definition: SCR_PlayerSpawnPoint.c:144
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
UpdateSpawnPosBroadcast
protected void UpdateSpawnPosBroadcast(vector pos)
Definition: SCR_PlayerSpawnPoint.c:156
IsSpawnPointActive
override bool IsSpawnPointActive()
Definition: SCR_PlayerSpawnPoint.c:125