Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RespawnSystemComponent.c
Go to the documentation of this file.
2 {
3 }
4 
7 [ComponentEditorProps(icon: HYBRID_COMPONENT_ICON)]
8 class SCR_RespawnSystemComponent : RespawnSystemComponent
9 {
10  [Attribute(category: "Respawn System")]
11  protected ref SCR_SpawnLogic m_SpawnLogic;
12 
13  [Attribute("1", uiwidget: UIWidgets.CheckBox, category: "Respawn System")]
14  protected bool m_bEnableRespawn;
15 
16  [Attribute("1.5", desc: "Delay (in seconds) for opening deploy menu after death.")]
17  protected float m_fDeployMenuOpenDelay;
18 
19  [Attribute("{A39BE59EB6F41125}Configs/Respawn/SpawnPointRequestResultInfoConfig.conf", desc: "Holds a config of all reasons why a specific spawnpoint can be disabled")]
20  protected ResourceName m_sSpawnPointRequestResultInfoHolder;
21 
22  protected ref SCR_SpawnPointRequestResultInfoConfig m_SpawnPointRequestResultInfoHolder;
23 
24  // Instance of this component
25  private static SCR_RespawnSystemComponent s_Instance = null;
26 
27  // The parent of this entity which should be a gamemode
28  protected SCR_BaseGameMode m_pGameMode;
29  // Parent entity's rpl component
30  protected RplComponent m_pRplComponent;
31 
33  protected RplComponent m_RplComponent;
34 
35  // Preload
36  protected ref SimplePreload m_Preload;
37 
38  protected ref ScriptInvoker Event_OnRespawnEnabledChanged;
39 
40  //------------------------------------------------------------------------------------------------
45  SCR_BaseSpawnPointRequestResultInfo GetSpawnPointRequestResultInfo(SCR_SpawnRequestComponent requestComponent, SCR_ESpawnResult response, SCR_SpawnData data)
46  {
47  if (!m_SpawnPointRequestResultInfoHolder)
48  return null;
49 
50  return m_SpawnPointRequestResultInfoHolder.GetFirstValidRequestResultInfo(requestComponent, response, data);
51  }
52 
53  //------------------------------------------------------------------------------------------------
55  static SCR_RespawnSystemComponent GetInstance()
56  {
57  if (!s_Instance)
58  {
59  BaseGameMode pGameMode = GetGame().GetGameMode();
60  if (pGameMode)
61  s_Instance = SCR_RespawnSystemComponent.Cast(pGameMode.FindComponent(SCR_RespawnSystemComponent));
62  }
63 
64  return s_Instance;
65  }
66 
67  //------------------------------------------------------------------------------------------------
69  [Obsolete("Use SCR_FactionManager.SGetLocalPlayerFaction instead")]
70  static Faction GetLocalPlayerFaction(IEntity player = null)
71  {
72  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(player);
73  if (character)
74  return character.GetFaction();
75 
76  return SCR_FactionManager.SGetLocalPlayerFaction();
77  }
78 
79  //------------------------------------------------------------------------------------------------
81  RplComponent GetRplComponent()
82  {
83  return m_RplComponent;
84  }
85 
86  //------------------------------------------------------------------------------------------------
87  [Obsolete("Use SCR_SpawnHandlerComponent instead.")]
88  protected override GenericEntity RequestSpawn(int playerId);
89 
90  //------------------------------------------------------------------------------------------------
91  [Obsolete("Use SCR_RespawnComponent.RequestSpawn instead!")]
92  GenericEntity CustomRespawn(int playerId, string prefab, vector position, vector rotation = vector.Zero);
93 
94  //------------------------------------------------------------------------------------------------
95  [Obsolete("Utilize SCR_LoadoutManager instead!")]
96  bool CanSetLoadout(int playerId, int loadoutIndex);
97 
98  //------------------------------------------------------------------------------------------------
99  [Obsolete("Use SCR_PlayerLoadoutComponent instead!")]
100  void DoSetPlayerLoadout(int playerId, int loadoutIndex);
101 
102  //------------------------------------------------------------------------------------------------
103  [Obsolete("Use SCR_PlayerFactionAffiliationComponent instead")]
104  bool CanSetFaction(int playerId, int factionIndex);
105 
106  //------------------------------------------------------------------------------------------------
107  [Obsolete("Spawn points are no longer assigned and are utilized directly through SCR_SpawnPointSpawnHandlerComponent")]
108  bool CanSetSpawnPoint(int playerId, RplId spawnPointId);
109 
110  //------------------------------------------------------------------------------------------------
111  [Obsolete("Spawn points are no longer assigned and are utilized directly through SCR_SpawnPointSpawnHandlerComponent")]
112  void DoSetPlayerSpawnPoint(int playerId, RplId spawnPointIdentity);
113 
114  //------------------------------------------------------------------------------------------------
115  [Obsolete("Use SCR_FactionManager.SGetFactionPlayerCount instead.")]
116  int GetFactionPlayerCount(Faction faction)
117  {
118  return SCR_FactionManager.SGetFactionPlayerCount(faction);
119  }
120 
121  //------------------------------------------------------------------------------------------------
124  [Obsolete("Use SCR_LoadoutManager.SGetLoadoutPlayerCount instead")]
126  {
127  return SCR_LoadoutManager.SGetLoadoutPlayerCount(loadout);
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  [Obsolete("Use SCR_PlayerLoadoutComponent.RequestLoadout instead")]
132  void SetPlayerLoadout(int playerId, int loadoutIndex);
133 
134  //------------------------------------------------------------------------------------------------
135  [Obsolete("Use SCR_PlayerFactionAffiliationComponent instead.")]
136  void SetPlayerFaction(int playerId, int factionIndex);
137 
138  //------------------------------------------------------------------------------------------------
139  [Obsolete("Use SCR_FactionManager instead.")]
140  Faction GetFactionByIndex(int factionIndex);
141 
142  //------------------------------------------------------------------------------------------------
143  [Obsolete("Use SCR_FactionManager instead.")]
144  int GetFactionIndex(Faction faction)
145  {
146  return -1;
147  }
148 
149  //------------------------------------------------------------------------------------------------
152  [Obsolete("Use SCR_FactionManager.SGetPlayerFaction instead")]
153  Faction GetPlayerFaction(int playerId)
154  {
155  return SCR_FactionManager.SGetPlayerFaction(playerId);
156  }
157 
158  //------------------------------------------------------------------------------------------------
159  [Obsolete("Use SCR_LoadoutManager instead!")]
160  SCR_BasePlayerLoadout GetLoadoutByIndex(int loadoutIndex);
161 
162  //------------------------------------------------------------------------------------------------
163  [Obsolete("Use SCR_LoadoutManager.SGetPlayerLoadout instead")]
165 
166  //------------------------------------------------------------------------------------------------
167  [Obsolete("Use SCR_LoadoutManager instead!")]
169  {
170  return -1;
171  }
172 
173  //------------------------------------------------------------------------------------------------
175  static MenuBase OpenRespawnMenu()
176  {
177  MenuManager pMenuManager = GetGame().GetMenuManager();
178  if (!pMenuManager)
179  return null;
180 
181  return pMenuManager.OpenMenu(ChimeraMenuPreset.RespawnSuperMenu);
182  }
183 
184  //------------------------------------------------------------------------------------------------
186  static void CloseRespawnMenu()
187  {
188  MenuManager pMenuManager = GetGame().GetMenuManager();
189  if (!pMenuManager)
190  return;
191 
192  MenuBase menu = pMenuManager.FindMenuByPreset(ChimeraMenuPreset.RespawnSuperMenu);
193  if (menu)
194  pMenuManager.CloseMenu(menu);
195  }
196 
197  //------------------------------------------------------------------------------------------------
199  [Obsolete("...")]
200  static bool IsRespawnMenuOpened()
201  {
202  MenuManager pMenuManager = GetGame().GetMenuManager();
203  if (!pMenuManager)
204  return false;
205 
206  return (pMenuManager.FindMenuByPreset(ChimeraMenuPreset.RespawnSuperMenu) != null);
207  }
208 
209  //------------------------------------------------------------------------------------------------
211  [Obsolete("...")]
212  static void ToggleRespawnMenu()
213  {
214  if (IsRespawnMenuOpened())
215  CloseRespawnMenu();
216  else
217  OpenRespawnMenu();
218  }
219 
220  //------------------------------------------------------------------------------------------------
223  void ServerSetEnableRespawn(bool enableSpawning)
224  {
225  if (enableSpawning == m_bEnableRespawn || !Replication.IsServer())
226  return;
227 
228  SetEnableRespawnBroadcast(enableSpawning);
229  Rpc(SetEnableRespawnBroadcast, enableSpawning);
230  }
231 
232  //------------------------------------------------------------------------------------------------
235  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
236  protected void SetEnableRespawnBroadcast(bool enableSpawning)
237  {
238  m_bEnableRespawn = enableSpawning;
239  if (Event_OnRespawnEnabledChanged)
240  Event_OnRespawnEnabledChanged.Invoke(m_bEnableRespawn);
241  }
242 
243  //------------------------------------------------------------------------------------------------
245  bool IsRespawnEnabled()
246  {
247  return m_bEnableRespawn;
248  }
249 
250  //------------------------------------------------------------------------------------------------
252  bool IsFactionChangeAllowed()
253  {
254  return m_pGameMode.IsFactionChangeAllowed();
255  }
256 
257  //------------------------------------------------------------------------------------------------
259  ScriptInvoker GetOnRespawnEnabledChanged()
260  {
261  if (!Event_OnRespawnEnabledChanged)
262  Event_OnRespawnEnabledChanged = new ScriptInvoker();
263 
264  return Event_OnRespawnEnabledChanged;
265  }
266 
267  //------------------------------------------------------------------------------------------------
277  bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, out SCR_ESpawnResult result = SCR_ESpawnResult.SPAWN_NOT_ALLOWED)
278  {
279  #ifdef _ENABLE_RESPAWN_LOGS
280  Print(string.Format("%1::CanRequestSpawn_S(playerId: %2, handler: %2, data: %3)", Type().ToString(),
281  requestComponent.GetPlayerId(),
282  handlerComponent,
283  data), LogLevel.NORMAL);
284  #endif
285 
286  if (!m_bEnableRespawn)
287  {
288  result = SCR_ESpawnResult.NOT_ALLOWED_SPAWNING_DISABLED;
289  return false;
290  }
291 
292  return m_pGameMode.CanPlayerSpawn_S(requestComponent, handlerComponent, data, result);
293  }
294 
295  //------------------------------------------------------------------------------------------------
307  bool PreparePlayerEntity_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
308  {
309  return m_pGameMode.PreparePlayerEntity_S(requestComponent, handlerComponent, data, entity);
310  }
311 
312  //------------------------------------------------------------------------------------------------
322  void OnPlayerEntityChange_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, IEntity previousEntity, IEntity newEntity, SCR_SpawnData data)
323  {
324  m_pGameMode.OnPlayerEntityChanged_S(requestComponent.GetPlayerId(), previousEntity, newEntity);
325  m_SpawnLogic.OnPlayerEntityChanged_S(requestComponent.GetPlayerId(), previousEntity, newEntity);
326  }
327 
328  //------------------------------------------------------------------------------------------------
331  void OnSpawnPlayerEntityFailure_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, IEntity entity, SCR_SpawnData data, SCR_ESpawnResult reason)
332  {
333  m_pGameMode.OnSpawnPlayerEntityFailure_S(requestComponent, handlerComponent, entity, data, reason);
334  }
335 
336  //------------------------------------------------------------------------------------------------
345  void OnPlayerSpawnFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
346  {
347  m_pGameMode.OnPlayerSpawnFinalize_S(requestComponent, handlerComponent, data, entity);
348  m_SpawnLogic.OnPlayerSpawned_S(requestComponent.GetPlayerId(), entity);
349  }
350 
351  //------------------------------------------------------------------------------------------------
353  void OnPlayerRegistered_S(int playerId)
354  {
355  m_SpawnLogic.OnPlayerRegistered_S(playerId);
356  }
357 
358  //------------------------------------------------------------------------------------------------
362  void OnPlayerDisconnected_S(int playerId, KickCauseCode cause, int timeout)
363  {
364  m_SpawnLogic.OnPlayerDisconnected_S(playerId, cause, timeout);
365  }
366 
367  //------------------------------------------------------------------------------------------------
372  void OnPlayerKilled_S(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
373  {
374  m_SpawnLogic.OnPlayerKilled_S(playerId, playerEntity, killerEntity, killer);
375  }
376 
377  //------------------------------------------------------------------------------------------------
379  void OnPlayerDeleted_S(int playerId)
380  {
381  m_SpawnLogic.OnPlayerDeleted_S(playerId);
382  }
383 
384  //------------------------------------------------------------------------------------------------
386  float GetDeployMenuOpenDelay_ms()
387  {
388  return m_fDeployMenuOpenDelay * 1000;
389  }
390 
391  //------------------------------------------------------------------------------------------------
393  bool CanOpenDeployMenu()
394  {
395  return m_SpawnLogic && m_SpawnLogic.Type() == SCR_MenuSpawnLogic;
396  }
397 
398  //------------------------------------------------------------------------------------------------
400  SCR_SpawnLogic GetSpawnLogic()
401  {
402  return m_SpawnLogic;
403  }
404 
405  //------------------------------------------------------------------------------------------------
406  override void OnInit(IEntity owner)
407  {
408  m_SpawnPointRequestResultInfoHolder = SCR_ConfigHelperT<SCR_SpawnPointRequestResultInfoConfig>.GetConfigObject(m_sSpawnPointRequestResultInfoHolder);
409  if (!m_SpawnPointRequestResultInfoHolder)
410  Print("'SCR_RespawnSystemComponent' has no valid m_SpawnPointRequestResultInfoHolder! This means the disabled reason cannot be disabled spawn point!", LogLevel.ERROR);
411 
412  m_pGameMode = SCR_BaseGameMode.Cast(owner);
413  if (!m_pGameMode)
414  Print("SCR_RespawnSystemComponent has to be attached to a SCR_BaseGameMode (or inherited) entity!", LogLevel.ERROR);
415  m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
416 
417  if (!m_SpawnLogic)
418  Print("SCR_RespawnSystemComponent is missing SCR_SpawnLogic!", LogLevel.ERROR);
419 
420  if (GetGame().InPlayMode())
421  {
422  m_SpawnLogic.OnInit(this);
423 
424  // Validate faction manager
425  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
426  if (!factionManager)
427  {
428  string text = string.Format("No %1 found in the world, %2 might not work as intended!",
429  SCR_FactionManager, SCR_RespawnSystemComponent);
430  Print(text, LogLevel.WARNING);
431  }
432 
433  // Validate loadout manager
434  SCR_LoadoutManager loadoutManager = GetGame().GetLoadoutManager();
435  if (!loadoutManager)
436  {
437  string text = string.Format("No %1 found in the world, %2 might not work as intended!",
438  SCR_LoadoutManager, SCR_RespawnSystemComponent);
439  Print(text, LogLevel.WARNING);
440  }
441  }
442  }
443 
444  //------------------------------------------------------------------------------------------------
445  protected override event bool OnRplSave(ScriptBitWriter w)
446  {
447  w.WriteBool(m_bEnableRespawn);
448 
449  return super.OnRplSave(w);
450  }
451 
452  //------------------------------------------------------------------------------------------------
453  protected override event bool OnRplLoad(ScriptBitReader r)
454  {
455  bool enableRespawn;
456  r.ReadBool(enableRespawn);
457 
458  SetEnableRespawnBroadcast(enableRespawn);
459 
460  return super.OnRplLoad(r);
461  }
462 
463  //------------------------------------------------------------------------------------------------
464  // destructor
465  void ~SCR_RespawnSystemComponent()
466  {
467  s_Instance = null;
468  }
469 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
GetPlayerFaction
protected Faction GetPlayerFaction(int playerID)
Definition: SCR_PlayerProfileManagerComponent.c:28
SCR_ESpawnResult
SCR_ESpawnResult
Definition: SCR_ESpawnResult.c:8
GetLocalPlayerFaction
Faction GetLocalPlayerFaction()
Definition: SCR_FactionManager.c:190
OnSpawnPlayerEntityFailure_S
override void OnSpawnPlayerEntityFailure_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, IEntity entity, SCR_SpawnData data, SCR_ESpawnResult reason)
Definition: SCR_SpawnProtectionComponent.c:79
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetFactionIndex
int GetFactionIndex()
Definition: SCR_EditableFactionComponent.c:57
GetPlayerLoadout
SCR_BasePlayerLoadout GetPlayerLoadout(int playerId)
Definition: SCR_LoadoutManager.c:35
loadout
string loadout
Definition: SCR_ArsenalManagerComponent.c:2
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_LoadoutManager
void SCR_LoadoutManager(IEntitySource src, IEntity parent)
Definition: SCR_LoadoutManager.c:500
GetLoadoutByIndex
SCR_BasePlayerLoadout GetLoadoutByIndex(int index)
Definition: SCR_LoadoutManager.c:318
DoSetPlayerLoadout
protected void DoSetPlayerLoadout(int playerId, string loadoutString, GameEntity characterEntity, SCR_EArsenalSupplyCostType arsenalSupplyType)
Definition: SCR_ArsenalManagerComponent.c:741
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_RespawnSystemComponentClass
Definition: SCR_RespawnSystemComponent.c:1
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
GetRplComponent
RplComponent GetRplComponent()
Returns the replication component associated to this entity.
Definition: SCR_RespawnComponent.c:200
KickCauseCode
KickCauseCode
Definition: KickCauseCode.c:19
Instigator
Definition: Instigator.c:6
SCR_SpawnData
Definition: SCR_SpawnData.c:9
GetLoadoutPlayerCount
int GetLoadoutPlayerCount(SCR_BasePlayerLoadout loadout)
Definition: SCR_LoadoutManager.c:86
s_Instance
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
SCR_SpawnPointRequestResultInfoConfig
Definition: SCR_SpawnPointRequestResultInfoConfig.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetFactionPlayerCount
int GetFactionPlayerCount(Faction faction)
Definition: SCR_FactionManager.c:215
SCR_BaseSpawnPointRequestResultInfo
Definition: SCR_BaseSpawnPointRequestResultInfo.c:2
rotation
RespawnSystemComponentClass GameComponentClass vector vector rotation
Definition: RespawnSystemComponent.c:23
m_pGameMode
SCR_BaseGameModeComponentClass m_pGameMode
The game mode entity this component is attached to.
SimplePreload
Definition: SimplePreload.c:1
CanRequestSpawn_S
bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out SCR_ESpawnResult result)
Definition: SCR_SpawnHandlerComponent.c:190
OnRplLoad
event protected bool OnRplLoad(ScriptBitReader r)
Definition: RespawnSystemComponent.c:36
OnRplSave
event protected bool OnRplSave(ScriptBitWriter w)
Definition: RespawnSystemComponent.c:31
Faction
Definition: Faction.c:12
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignBuildingManagerComponent.c:42
OnPlayerSpawnFinalize_S
override void OnPlayerSpawnFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
Definition: SCR_SpawnProtectionComponent.c:72
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
SCR_SpawnLogic
Definition: SCR_SpawnLogic.c:11
ComponentEditorProps
SCR_RespawnSystemComponentClass RespawnSystemComponentClass ComponentEditorProps(icon:HYBRID_COMPONENT_ICON)
Definition: SCR_RespawnSystemComponent.c:7
RequestSpawn
bool RequestSpawn(SCR_SpawnData data)
Definition: SCR_RespawnComponent.c:364
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
RespawnSystemComponentClass
Definition: RespawnSystemComponent.c:12
OnInit
override protected void OnInit(IEntity owner)
Definition: SCR_CharacterCommandHandler_Tests.c:523
SCR_MenuSpawnLogic
Definition: SCR_MenuSpawnLogic.c:2
m_SpawnLogic
private SCR_MenuSpawnLogic m_SpawnLogic
Definition: SCR_PlayerDeployMenuHandlerComponent.c:27
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
GetLoadoutIndex
int GetLoadoutIndex(SCR_BasePlayerLoadout loadout)
Definition: SCR_LoadoutManager.c:303
SCR_BasePlayerLoadout
Definition: SCR_BasePlayerLoadout.c:2
GetFactionByIndex
proto external Faction GetFactionByIndex(int index)
Obsolete
RespawnSystemComponentClass GameComponentClass Obsolete()] proto external GenericEntity DoSpawn(string prefab
RespawnSystemComponent should be attached to a gamemode to handle player spawning and respawning.
PreparePlayerEntity_S
bool PreparePlayerEntity_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
Definition: SCR_BaseGameModeComponent.c:98
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180