8 [
Attribute(
"", uiwidget: UIWidgets.EditBox,
category:
"Respawn",
desc:
"Default faction for players to spawn with or empty if none.")]
9 protected FactionKey m_sForcedFaction;
11 [
Attribute(
"", uiwidget: UIWidgets.EditBox,
category:
"Respawn",
desc:
"Default loadout for players to spawn with or empty if none")]
12 protected string m_sForcedLoadout;
14 protected ref set<int> m_DisconnectingPlayers =
new set<int>();
17 protected bool GetForcedFaction(out
Faction faction)
19 if (m_sForcedFaction.IsEmpty())
22 faction =
GetGame().GetFactionManager().GetFactionByKey(m_sForcedFaction);
25 Print(
string.Format(
"Auto spawn logic did not find faction by name: %1", m_sForcedFaction), LogLevel.WARNING);
35 if (m_sForcedLoadout.IsEmpty())
38 loadout =
GetGame().GetLoadoutManager().GetLoadoutByName(m_sForcedLoadout);
41 Print(
string.Format(
"Auto spawn logic did not find loadout by name: %1", m_sForcedLoadout), LogLevel.WARNING);
48 override void OnInit(SCR_RespawnSystemComponent owner)
54 override void OnPlayerRegistered_S(
int playerId)
56 super.OnPlayerRegistered_S(playerId);
60 int indexOf = m_DisconnectingPlayers.Find(playerId);
63 m_DisconnectingPlayers.Remove(indexOf);
70 GetGame().GetCallqueue().CallLater(DoInitialSpawn, 0,
false, playerId);
74 override void OnPlayerDisconnected_S(
int playerId,
KickCauseCode cause,
int timeout)
76 super.OnPlayerDisconnected_S(playerId, cause, timeout);
77 m_DisconnectingPlayers.Insert(playerId);
82 private void DoInitialSpawn(
int playerId)
85 IEntity returnedEntity;
86 if (ResolveReconnection(playerId, returnedEntity))
93 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
94 IEntity controlledEntity = playerController.GetControlledEntity();
102 override void OnPlayerEntityLost_S(
int playerId)
104 super.OnPlayerEntityLost_S(playerId);
109 override void OnPlayerSpawnFailed_S(
int playerId)
111 super.OnPlayerSpawnFailed_S(playerId);
113 int delay = Math.RandomFloat(900, 1100);
114 GetGame().GetCallqueue().CallLater(Spawn, delay,
false, playerId);
118 protected void Spawn(
int playerId)
122 int indexOf = m_DisconnectingPlayers.Find(playerId);
125 m_DisconnectingPlayers.Remove(indexOf);
129 array<Faction> factions = {};
130 GetGame().GetFactionManager().GetFactionsList(factions);
133 if (!GetForcedFaction(targetFaction))
134 targetFaction = factions.GetRandomElement();
137 if (!GetPlayerFactionComponent_S(playerId).RequestFaction(targetFaction))
143 if (!GetForcedLoadout(targetLoadout))
144 targetLoadout =
GetGame().GetLoadoutManager().GetRandomFactionLoadout(targetFaction);
146 if (!GetPlayerLoadoutComponent_S(playerId).RequestLoadout(targetLoadout))
151 Faction faction = GetPlayerFactionComponent_S(playerId).GetAffiliatedFaction();
154 OnPlayerSpawnFailed_S(playerId);
161 OnPlayerSpawnFailed_S(playerId);
168 OnPlayerSpawnFailed_S(playerId);
173 if (GetPlayerRespawnComponent_S(playerId).
CanSpawn(
data))
174 DoSpawn(playerId,
data);
176 OnPlayerSpawnFailed_S(playerId);