Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AutoSpawnLogic.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
2/*
3 Object responsible for handling respawn logic on the authority side.
4*/
6class SCR_AutoSpawnLogic : SCR_SpawnLogic
7{
8 [Attribute("", uiwidget: UIWidgets.EditBox, category: "Respawn", desc: "Default faction for players to spawn with or empty if none.")]
10
11 [Attribute("", uiwidget: UIWidgets.EditBox, category: "Respawn", desc: "Default loadout for players to spawn with or empty if none")]
12 protected string m_sForcedLoadout;
13
14 //------------------------------------------------------------------------------------------------
15 override void OnPlayerAuditSuccess_S(int playerId)
16 {
17 super.OnPlayerAuditSuccess_S(playerId);
18 ExcuteInitialLoadOrSpawn_S(playerId);
19 }
20
21 //------------------------------------------------------------------------------------------------
22 override void OnPlayerEntityLost_S(int playerId)
23 {
24 super.OnPlayerEntityLost_S(playerId);
25 DoSpawn_S(playerId);
26 }
27
28 //------------------------------------------------------------------------------------------------
29 override void OnPlayerSpawnFailed_S(int playerId)
30 {
31 super.OnPlayerSpawnFailed_S(playerId);
32
33 const int delay = Math.RandomFloat(900, 1100);
34 GetGame().GetCallqueue().CallLater(DoSpawn_S, delay, false, playerId);
35 }
36
37 //------------------------------------------------------------------------------------------------
38 override protected void DoSpawn_S(int playerId)
39 {
40 array<Faction> factions = {};
41 GetGame().GetFactionManager().GetFactionsList(factions);
42
43 Faction targetFaction;
44 if (!GetForcedFaction(targetFaction))
45 targetFaction = factions.GetRandomElement();
46
47 GetPlayerFactionComponent_S(playerId).RequestFaction(targetFaction);
48
49 SCR_BasePlayerLoadout targetLoadout;
50 if (!GetForcedLoadout(targetLoadout))
51 targetLoadout = GetGame().GetLoadoutManager().GetRandomFactionLoadout(targetFaction);
52
53 GetPlayerLoadoutComponent_S(playerId).RequestLoadout(targetLoadout);
54
55 Faction faction = GetPlayerFactionComponent_S(playerId).GetAffiliatedFaction();
56 if (!faction)
57 {
58 OnPlayerSpawnFailed_S(playerId);
59 return;
60 }
61
62 SCR_BasePlayerLoadout loadout = GetPlayerLoadoutComponent_S(playerId).GetLoadout();
63 if (!loadout)
64 {
65 OnPlayerSpawnFailed_S(playerId);
66 return;
67 }
68
69 SCR_SpawnPoint point = SCR_SpawnPoint.GetRandomSpawnPointForFaction(faction.GetFactionKey());
70 if (!point)
71 {
72 OnPlayerSpawnFailed_S(playerId);
73 return;
74 }
75
76 SCR_SpawnPointSpawnData data = new SCR_SpawnPointSpawnData(loadout.GetLoadoutResource(), point.GetRplId());
77 if (!GetPlayerRespawnComponent_S(playerId).CanSpawn(data))
78 {
79 OnPlayerSpawnFailed_S(playerId);
80 return;
81 }
82
83 GetPlayerRespawnComponent_S(playerId).RequestSpawn(data);
84 }
85
86 //------------------------------------------------------------------------------------------------
87 protected bool GetForcedFaction(out Faction faction)
88 {
89 if (m_sForcedFaction.IsEmpty() &&
90 !System.GetCLIParam("autodeployFaction", m_sForcedFaction) &&
91 !System.GetCLIParam("tdmf", m_sForcedFaction))
92 {
93 return false;
94 }
95
96 faction = GetGame().GetFactionManager().GetFactionByKey(m_sForcedFaction);
97 if (!faction)
98 {
99 Print(string.Format("Auto spawn logic did not find faction by name: %1", m_sForcedFaction), LogLevel.WARNING);
100 return false;
101 }
102
103 return true;
104 }
105
106 //------------------------------------------------------------------------------------------------
108 {
109 if (m_sForcedLoadout.IsEmpty())
110 return false;
111
112 loadout = GetGame().GetLoadoutManager().GetLoadoutByName(m_sForcedLoadout, m_sForcedFaction);
113 if (!loadout)
114 {
115 Print(string.Format("Auto spawn logic did not find loadout by name: %1", m_sForcedLoadout), LogLevel.WARNING);
116 return false;
117 }
118 return true;
119 }
120}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
Get all prefabs that have the spawner data
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
bool CanSpawn(SCR_SpawnData data)
Definition Math.c:13
bool GetForcedLoadout(out SCR_BasePlayerLoadout loadout)
override void OnPlayerEntityLost_S(int playerId)
override void OnPlayerSpawnFailed_S(int playerId)
void DoSpawn_S(int playerId)
override void OnPlayerAuditSuccess_S(int playerId)
bool GetForcedFaction(out Faction faction)
Spawn point entity defines positions on which players can possibly spawn.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute