8 class SCR_RespawnSystemComponent : RespawnSystemComponent
14 protected bool m_bEnableRespawn;
16 [
Attribute(
"1.5",
desc:
"Delay (in seconds) for opening deploy menu after death.")]
17 protected float m_fDeployMenuOpenDelay;
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;
25 private static SCR_RespawnSystemComponent
s_Instance =
null;
30 protected RplComponent m_pRplComponent;
38 protected ref ScriptInvoker Event_OnRespawnEnabledChanged;
47 if (!m_SpawnPointRequestResultInfoHolder)
50 return m_SpawnPointRequestResultInfoHolder.GetFirstValidRequestResultInfo(requestComponent, response,
data);
59 BaseGameMode pGameMode =
GetGame().GetGameMode();
61 s_Instance = SCR_RespawnSystemComponent.Cast(pGameMode.FindComponent(SCR_RespawnSystemComponent));
69 [
Obsolete(
"Use SCR_FactionManager.SGetLocalPlayerFaction instead")]
72 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(player);
74 return character.GetFaction();
87 [
Obsolete(
"Use SCR_SpawnHandlerComponent instead.")]
91 [
Obsolete(
"Use SCR_RespawnComponent.RequestSpawn instead!")]
95 [
Obsolete(
"Utilize SCR_LoadoutManager instead!")]
96 bool CanSetLoadout(
int playerId,
int loadoutIndex);
99 [
Obsolete(
"Use SCR_PlayerLoadoutComponent instead!")]
103 [
Obsolete(
"Use SCR_PlayerFactionAffiliationComponent instead")]
104 bool CanSetFaction(
int playerId,
int factionIndex);
107 [
Obsolete(
"Spawn points are no longer assigned and are utilized directly through SCR_SpawnPointSpawnHandlerComponent")]
108 bool CanSetSpawnPoint(
int playerId, RplId spawnPointId);
111 [
Obsolete(
"Spawn points are no longer assigned and are utilized directly through SCR_SpawnPointSpawnHandlerComponent")]
112 void DoSetPlayerSpawnPoint(
int playerId, RplId spawnPointIdentity);
115 [
Obsolete(
"Use SCR_FactionManager.SGetFactionPlayerCount instead.")]
124 [
Obsolete(
"Use SCR_LoadoutManager.SGetLoadoutPlayerCount instead")]
131 [
Obsolete(
"Use SCR_PlayerLoadoutComponent.RequestLoadout instead")]
132 void SetPlayerLoadout(
int playerId,
int loadoutIndex);
135 [
Obsolete(
"Use SCR_PlayerFactionAffiliationComponent instead.")]
136 void SetPlayerFaction(
int playerId,
int factionIndex);
139 [
Obsolete(
"Use SCR_FactionManager instead.")]
143 [
Obsolete(
"Use SCR_FactionManager instead.")]
152 [
Obsolete(
"Use SCR_FactionManager.SGetPlayerFaction instead")]
159 [
Obsolete(
"Use SCR_LoadoutManager instead!")]
163 [
Obsolete(
"Use SCR_LoadoutManager.SGetPlayerLoadout instead")]
167 [
Obsolete(
"Use SCR_LoadoutManager instead!")]
175 static MenuBase OpenRespawnMenu()
177 MenuManager pMenuManager =
GetGame().GetMenuManager();
186 static void CloseRespawnMenu()
188 MenuManager pMenuManager =
GetGame().GetMenuManager();
192 MenuBase menu = pMenuManager.FindMenuByPreset(
ChimeraMenuPreset.RespawnSuperMenu);
194 pMenuManager.CloseMenu(menu);
200 static bool IsRespawnMenuOpened()
202 MenuManager pMenuManager =
GetGame().GetMenuManager();
206 return (pMenuManager.FindMenuByPreset(
ChimeraMenuPreset.RespawnSuperMenu) !=
null);
212 static void ToggleRespawnMenu()
214 if (IsRespawnMenuOpened())
223 void ServerSetEnableRespawn(
bool enableSpawning)
225 if (enableSpawning == m_bEnableRespawn || !Replication.IsServer())
228 SetEnableRespawnBroadcast(enableSpawning);
229 Rpc(SetEnableRespawnBroadcast, enableSpawning);
235 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
236 protected void SetEnableRespawnBroadcast(
bool enableSpawning)
238 m_bEnableRespawn = enableSpawning;
239 if (Event_OnRespawnEnabledChanged)
240 Event_OnRespawnEnabledChanged.Invoke(m_bEnableRespawn);
245 bool IsRespawnEnabled()
247 return m_bEnableRespawn;
252 bool IsFactionChangeAllowed()
259 ScriptInvoker GetOnRespawnEnabledChanged()
261 if (!Event_OnRespawnEnabledChanged)
262 Event_OnRespawnEnabledChanged =
new ScriptInvoker();
264 return Event_OnRespawnEnabledChanged;
279 #ifdef _ENABLE_RESPAWN_LOGS
280 Print(
string.Format(
"%1::CanRequestSpawn_S(playerId: %2, handler: %2, data: %3)", Type().ToString(),
281 requestComponent.GetPlayerId(),
283 data), LogLevel.NORMAL);
286 if (!m_bEnableRespawn)
292 return m_pGameMode.CanPlayerSpawn_S(requestComponent, handlerComponent,
data, result);
309 return m_pGameMode.PreparePlayerEntity_S(requestComponent, handlerComponent,
data, entity);
322 void OnPlayerEntityChange_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, IEntity previousEntity, IEntity newEntity,
SCR_SpawnData data)
324 m_pGameMode.OnPlayerEntityChanged_S(requestComponent.GetPlayerId(), previousEntity, newEntity);
325 m_SpawnLogic.OnPlayerEntityChanged_S(requestComponent.GetPlayerId(), previousEntity, newEntity);
333 m_pGameMode.OnSpawnPlayerEntityFailure_S(requestComponent, handlerComponent, entity,
data, reason);
347 m_pGameMode.OnPlayerSpawnFinalize_S(requestComponent, handlerComponent,
data, entity);
348 m_SpawnLogic.OnPlayerSpawned_S(requestComponent.GetPlayerId(), entity);
353 void OnPlayerRegistered_S(
int playerId)
362 void OnPlayerDisconnected_S(
int playerId,
KickCauseCode cause,
int timeout)
364 m_SpawnLogic.OnPlayerDisconnected_S(playerId, cause, timeout);
372 void OnPlayerKilled_S(
int playerId, IEntity playerEntity, IEntity killerEntity, notnull
Instigator killer)
374 m_SpawnLogic.OnPlayerKilled_S(playerId, playerEntity, killerEntity, killer);
379 void OnPlayerDeleted_S(
int playerId)
386 float GetDeployMenuOpenDelay_ms()
388 return m_fDeployMenuOpenDelay * 1000;
393 bool CanOpenDeployMenu()
406 override void OnInit(IEntity owner)
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);
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));
418 Print(
"SCR_RespawnSystemComponent is missing SCR_SpawnLogic!", LogLevel.ERROR);
428 string text =
string.Format(
"No %1 found in the world, %2 might not work as intended!",
430 Print(text, LogLevel.WARNING);
437 string text =
string.Format(
"No %1 found in the world, %2 might not work as intended!",
439 Print(text, LogLevel.WARNING);
445 protected override event bool OnRplSave(ScriptBitWriter w)
447 w.WriteBool(m_bEnableRespawn);
449 return super.OnRplSave(w);
453 protected override event bool OnRplLoad(ScriptBitReader r)
456 r.ReadBool(enableRespawn);
458 SetEnableRespawnBroadcast(enableRespawn);
460 return super.OnRplLoad(r);
465 void ~SCR_RespawnSystemComponent()