Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_GameModeLastStand.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
5
6//------------------------------------------------------------------------------------------------
8{
9 [Attribute("10", UIWidgets.EditBox, "How long between clearing the last wave and a new one")]
10 float m_TimeoutBetweenWaves;
11
12 [Attribute("4", UIWidgets.EditBox, "How many groups spawned each wave")]
13 int m_InitialGroupsCount;
14
15 [Attribute("1", UIWidgets.EditBox, "How many new groups should spawn each round")]
16 int m_AddedGroupsPerRound;
17
18 [Attribute("", UIWidgets.ResourceNamePicker, "What group type should spawn")]
19 ResourceName m_GroupType;
20
21 [Attribute("USSR", UIWidgets.EditBox, "Enemy faction key")]
23
24 [Attribute("US", UIWidgets.EditBox, "Friendly faction key")]
26
29
32 ref array<IEntity> m_aEnemySoldiers;
33 ref array<SCR_AIGroup> m_aGroups;
34 ref array<SCR_SpawnPoint> m_aEnemySpawnPoints;
35 ref array<SCR_SpawnPoint> m_aPlayerSpawnPoints;
37 AIWaypoint m_AttackWP;
38
39 //------------------------------------------------------------------------------------------------
40 override void EOnFrame(IEntity owner, float timeSlice)
41 {
42 //PrintString("printing");
43 super.EOnFrame(owner, timeSlice);
44
45 if (m_fCurrentTimeout > 0)
46 {
47 m_fCurrentTimeout -= timeSlice;
48 if (m_fCurrentTimeout < 0)
49 {
52 if (m_iRoundNumber > 0)
53 {
55 Print("Sending next wave of enemies.");
56 ShowHint("Sending next wave of enemies.", 5);
57 }
58 }
59 }
60 else if (m_aEnemySoldiers.Count() == 0)
61 {
62 Print("All enemies are dead. Wave cleared.");
63 ShowHint("All enemies are dead. Wave cleared.", 5);
64 m_fCurrentTimeout = m_TimeoutBetweenWaves;
65 }
66 }
67
68 //------------------------------------------------------------------------------------------------
69 void ShowHint(string text, float showTime)
70 {
71 if (!m_wText || !m_wRoot)
72 return;
73
74 m_wText.SetText(text);
76
77 ScriptCallQueue queue = GetGame().GetCallqueue();
78 queue.CallLater(this.HideHint, showTime * 1000);
79 }
80
81 //------------------------------------------------------------------------------------------------
82 void HideHint()
83 {
84 if (m_wRoot)
86 }
87
88 //------------------------------------------------------------------------------------------------
89 void SpawnEnemies(int round)
90 {
91 if (m_aEnemySpawnPoints.Count() == 0)
92 return;
93
94 // Clean up groups
95 for (int i = m_aGroups.Count() - 1; i >= 0; i--)
96 {
97 delete m_aGroups[i];
98 }
99 m_aGroups.Clear();
100 m_aEnemySoldiers.Clear();
101
102 m_iGroupsToSpawn = m_InitialGroupsCount + (round - 1) * m_AddedGroupsPerRound;
103
104 for (int i = 0; i < m_iGroupsToSpawn; i++)
105 {
106 RandomGenerator generator = new RandomGenerator;
107 generator.SetSeed(Math.RandomInt(0,100));
108
109 SCR_SpawnPoint spawnPoint = m_aEnemySpawnPoints.GetRandomElement();
110 if (!spawnPoint)
111 return;
112
113 vector position = generator.GenerateRandomPointInRadius(0, 2, spawnPoint.GetOrigin());
114 position[1] = spawnPoint.GetOrigin()[1];
116 params.TransformMode = ETransformMode.WORLD;
117 params.Transform[3] = position;
118
119 Resource res = Resource.Load(m_GroupType);
120 SCR_AIGroup newGrp = SCR_AIGroup.Cast(GetGame().SpawnEntityPrefab(res, null, params));
121 m_aGroups.Insert(newGrp);
122
123 array<AIAgent> agents = new array<AIAgent>;
124
125 newGrp.GetAgents(agents);
126 foreach (AIAgent agent : agents)
127 {
128 if (agent)
129 {
130 m_aEnemySoldiers.Insert(agent.GetControlledEntity());
131 }
132 }
133
134 if (m_AttackWP)
135 {
137 }
138 }
139 }
140
141 //------------------------------------------------------------------------------------------------
142 override void OnControllableDestroyed(IEntity entity, IEntity killerEntity, notnull Instigator instigator)
143 {
144 super.OnControllableDestroyed(entity, killerEntity, instigator);
145
146 m_aEnemySoldiers.RemoveItemOrdered(entity);
147 }
148
149 //------------------------------------------------------------------------------------------------
150 override void EOnInit(IEntity owner)
151 {
152 super.EOnInit(owner);
153
154 m_fCurrentTimeout = m_TimeoutBetweenWaves;
155
156 m_wRoot = GetGame().GetWorkspace().CreateWidgets("{EA1CC57D868E94F9}UI/layouts/HUD/Hint.layout");
157 if (m_wRoot)
158 {
159 m_wText = TextWidget.Cast(m_wRoot.FindAnyWidget("Text"));
160 TextWidget title = TextWidget.Cast(m_wRoot.FindAnyWidget("Title"));
161 if (title)
162 title.SetText("LAST STAND");
163
164 m_wRoot.SetOpacity(0);
165 }
166 BaseWorld world = owner.GetWorld();
167 m_AttackWP = AIWaypoint.Cast(world.FindEntityByName("WP1"));
168 m_aEnemySoldiers = {};
169 m_aGroups = {};
172 array<SCR_SpawnPoint> spawnPoints = {};
173 spawnPoints = SCR_SpawnPoint.GetSpawnPoints();
174
175 FactionKey faction;
176 SCR_SpawnPoint spawnPoint;
177 for (int i = spawnPoints.Count() - 1; i >= 0; i--)
178 {
179 spawnPoint = spawnPoints[i];
180 if (!spawnPoint)
181 continue;
182
183 faction = spawnPoint.GetFactionKey();
184 if (faction == m_sEnemyFactionKey)
185 m_aEnemySpawnPoints.Insert(spawnPoint);
186
187 if (faction == m_sFriendlyFactionKey)
188 m_aPlayerSpawnPoints.Insert(spawnPoint);
189 }
190 }
191};
192
ArmaReforgerScripted GetGame()
Definition game.c:1398
vector position
void SpawnEnemies()
static WidgetAnimationOpacity Opacity(Widget widget, float targetValue, float speed, bool toggleVisibility=false)
proto external BaseWorld GetWorld()
Definition Math.c:13
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void AddWaypointToGroup(AIWaypoint waypoint)
void SCR_BaseGameMode(IEntitySource src, IEntity parent)
override void EOnFrame(IEntity owner, float timeSlice)
ref array< SCR_SpawnPoint > m_aPlayerSpawnPoints
override void EOnInit(IEntity owner)
ref array< SCR_AIGroup > m_aGroups
override void OnControllableDestroyed(IEntity entity, IEntity killerEntity, notnull Instigator instigator)
ref array< SCR_SpawnPoint > m_aEnemySpawnPoints
ref array< IEntity > m_aEnemySoldiers
void ShowHint(string text, float showTime)
Spawn point entity defines positions on which players can possibly spawn.
string GetFactionKey()
ScriptCallQueue Class provide "lazy" calls - when we don't want to execute function immediately but l...
Definition tools.c:53
void EntitySpawnParams()
Definition gameLib.c:130
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
SCR_FieldOfViewSettings Attribute