Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignSuppliesComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Campaign", description: "Makes a vehicle able to carry Conflict resources.", color: "0 0 255 255")]
2 class SCR_CampaignSuppliesComponentClass : ScriptComponentClass
3 {
4 }
5 
8 {
9  // Member variables
13  protected bool m_bAwardUnloadXP = true;
14  protected bool m_bIsPlayerInRange;
15 
16  protected static const float SUPPLY_TRUCK_UNLOAD_RADIUS = 25;
17 
18  [RplProp()]
19  protected ref array<int> m_aLoadingPlayerIDs = {};
20 
21  [RplProp()]
22  protected ref array<int> m_aUnloadingPlayerIDs = {};
23 
24  // Script Invoker
25  ref ScriptInvoker m_OnSuppliesChanged = new ScriptInvoker();
26  ref ScriptInvoker m_OnSuppliesTruckDeleted = new ScriptInvoker();
27 
28  // Synced variables
29  [Attribute("0", desc: "How many supplies this component holds when it is created."), RplProp(onRplName: "OnSuppliesChanged")]
30  protected int m_iSupplies;
31 
32  // Synced variables
33  [Attribute("0", desc: "Maximum supplies this component can hold."), RplProp(onRplName: "OnSuppliesChanged")]
34  protected int m_iSuppliesMax;
35 
36  [Attribute("0", desc: "Maximum distance from a supply depot a player can still (un)load their truck")]
37  protected float m_fOperationalRadius;
38 
39  [Attribute("0", UIWidgets.CheckBox, "This component belongs to a supply depot without a parent base.", "")]
41 
42  //------------------------------------------------------------------------------------------------
45  [Obsolete("Use SCR_ResourceComponent operations instead")]
46  int GetLoadingPlayer(bool unloading = false)
47  {
48  array<int> loadingArray;
49  //Switch between loading and unloading players
50  if(!unloading)
51  loadingArray = m_aLoadingPlayerIDs;
52  else
53  loadingArray = m_aUnloadingPlayerIDs;
54 
55  //return id of first player (if there is any)
56  if(!loadingArray.IsEmpty())
57  return loadingArray[0];
58  else
59  return 0;
60  }
61  //------------------------------------------------------------------------------------------------
64  [Obsolete("Use SCR_ResourceComponent operations instead")]
65  void SetSupplyLoadingPlayer(int playerID)
66  {
67  if(!m_aLoadingPlayerIDs.Contains(playerID))
68  {
69  m_aLoadingPlayerIDs.Insert(playerID);
70  Replication.BumpMe();
71  }
72  }
73 
74  //------------------------------------------------------------------------------------------------
77  // Deletes from loading players array
78  [Obsolete("Use SCR_ResourceComponent operations instead")]
79  void DeleteSupplyLoadingPlayer(int playerID)
80  {
81  if(m_aLoadingPlayerIDs.Contains(playerID))
82  {
83  m_aLoadingPlayerIDs.RemoveItemOrdered(playerID);
84  Replication.BumpMe();
85  }
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  //~ Called on player killed
90  protected void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
91  {
92  /*DeleteSupplyLoadingPlayer(playerId);
93  DeleteSupplyUnloadingPlayer(playerId);*/
94  }
95 
96  //------------------------------------------------------------------------------------------------
99  [Obsolete("Use SCR_ResourceComponent operations instead")]
100  void SetSupplyUnloadingPlayer(int playerID)
101  {
102  if(!m_aUnloadingPlayerIDs.Contains(playerID))
103  {
104  m_aUnloadingPlayerIDs.Insert(playerID);
105  Replication.BumpMe();
106  }
107  }
108 
109  //------------------------------------------------------------------------------------------------
112  [Obsolete("Use SCR_ResourceComponent operations instead")]
113  void DeleteSupplyUnloadingPlayer(int playerID)
114  {
115  if(m_aUnloadingPlayerIDs.Contains(playerID))
116  {
117  m_aUnloadingPlayerIDs.RemoveItemOrdered(playerID);
118  Replication.BumpMe();
119  }
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  [Obsolete("Use SCR_ResourceComponent operations instead")]
125  {
126  // script invoker executed when ammout of supplies in vehicle changed. m_iSupplies is ammout of currently loaded supplies.
128  }
129 
130  //------------------------------------------------------------------------------------------------
132  [Obsolete("Use SCR_ResourceComponent operations instead")]
134  {
135  return m_iSupplies;
136  }
137 
138  //------------------------------------------------------------------------------------------------
140  [Obsolete("Use SCR_ResourceComponent operations instead")]
142  {
143  return m_iSuppliesMax;
144  }
145 
146  //------------------------------------------------------------------------------------------------
148  [Obsolete("Use SCR_ResourceComponent operations instead")]
149  void SetSuppliesMax(int suppliesMax)
150  {
151  m_iSuppliesMax = suppliesMax;
152  if (m_iSupplies > suppliesMax)
154 
155  Replication.BumpMe();
157  }
158 
159  //------------------------------------------------------------------------------------------------
162  [Obsolete("Use SCR_ResourceComponent operations instead")]
164  {
165  if (m_fOperationalRadius != 0)
166  return m_fOperationalRadius;
167 
168  return SUPPLY_TRUCK_UNLOAD_RADIUS;
169  }
170 
171  //------------------------------------------------------------------------------------------------
173  [Obsolete("Use SCR_ResourceComponent operations instead")]
174  void SetIsPlayerInRange(bool status)
175  {
176  m_bIsPlayerInRange = status;
177  }
178 
179  //------------------------------------------------------------------------------------------------
181  [Obsolete("Use SCR_ResourceComponent operations instead")]
183  {
184  return m_bIsPlayerInRange;
185  }
186 
187  //------------------------------------------------------------------------------------------------
189  [Obsolete("Use SCR_ResourceComponent operations instead")]
191  {
192  m_LastLoadedAt = base;
193 
195  m_bAwardUnloadXP = false;
196  else
197  m_bAwardUnloadXP = true;
198  }
199 
200  //------------------------------------------------------------------------------------------------
202  [Obsolete("Use SCR_ResourceComponent operations instead")]
204  {
205  m_LastUnloadedAt = base;
206 
208  m_bAwardUnloadXP = false;
209  else
210  m_LastXPAwardedAt = base;
211  }
212 
213  //------------------------------------------------------------------------------------------------
216  [Obsolete("Use SCR_ResourceComponent operations instead")]
217  bool AwardXP()
218  {
219  return m_bAwardUnloadXP;
220  }
221 
222  //------------------------------------------------------------------------------------------------
226  [Obsolete("Use SCR_ResourceComponent operations instead")]
227  void AddSupplies(int supplies, bool replicate = true)
228  {
229  int oldSupplies = m_iSupplies;
230  m_iSupplies += supplies;
231 
234 
235  if (m_iSupplies < 0)
236  m_iSupplies = 0;
237 
238  if (replicate && m_iSupplies != oldSupplies)
239  Replication.BumpMe();
240 
242  }
243 
244  //------------------------------------------------------------------------------------------------
246  [Obsolete("Use SCR_ResourceComponent operations instead")]
248  {
249  return m_bIsStandaloneDepot;
250  }
251 
252  //------------------------------------------------------------------------------------------------
253  override void EOnInit(IEntity owner)
254  {
256  if (!gamemode)
257  return;
258 
259  gamemode.GetOnPlayerDisconnected().Insert(DeleteSupplyLoadingPlayer);
260  gamemode.GetOnPlayerDisconnected().Insert(DeleteSupplyUnloadingPlayer);
261  gamemode.GetOnPlayerKilled().Insert(OnPlayerKilled);
262 
263  if (m_bIsStandaloneDepot && GetGame().InPlayMode())
264  {
265  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
266 
267  if (campaign)
268  campaign.GetBaseManager().RegisterRemnantSupplyDepot(this);
269  }
270  }
271 
272  //------------------------------------------------------------------------------------------------
273  override void OnPostInit(IEntity owner)
274  {
275  super.OnPostInit(owner);
276  SetEventMask(owner, EntityEvent.INIT);
277 
279  {
280  string err = string.Format("SCR_CampaignSuppliesComponent on %1 carries more supplies (%2) than its maximum (%3)!", owner, m_iSupplies, m_iSuppliesMax);
281  Print(err, LogLevel.ERROR);
282  }
283  }
284 
285  //------------------------------------------------------------------------------------------------
288  static SCR_CampaignSuppliesComponent GetSuppliesComponent(notnull IEntity ent)
289  {
290  SCR_CampaignSuppliesComponent suppliesComponent;
291 
292  suppliesComponent = SCR_CampaignSuppliesComponent.Cast(ent.FindComponent(SCR_CampaignSuppliesComponent));
293  if (suppliesComponent)
294  return suppliesComponent;
295 
296  SlotManagerComponent slotManager = SlotManagerComponent.Cast(ent.FindComponent(SlotManagerComponent));
297  if (!slotManager)
298  return null;
299 
300  array<EntitySlotInfo> slots = {};
301  slotManager.GetSlotInfos(slots);
302  IEntity truckBed;
303 
304  foreach (EntitySlotInfo slot: slots)
305  {
306  if (!slot)
307  continue;
308 
309  truckBed = slot.GetAttachedEntity();
310 
311  if (!truckBed)
312  continue;
313 
314  suppliesComponent = SCR_CampaignSuppliesComponent.Cast(truckBed.FindComponent(SCR_CampaignSuppliesComponent));
315  if (suppliesComponent)
316  return suppliesComponent;
317  }
318 
319  return null;
320  }
321 
322  //------------------------------------------------------------------------------------------------
323  // constructor
327  void SCR_CampaignSuppliesComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
328  {
329  }
330 
331  //------------------------------------------------------------------------------------------------
332  // destructor
334  {
337 
339  if (!gamemode)
340  return;
341 
342  gamemode.GetOnPlayerDisconnected().Remove(DeleteSupplyLoadingPlayer);
343  gamemode.GetOnPlayerDisconnected().Remove(DeleteSupplyUnloadingPlayer);
344  gamemode.GetOnPlayerKilled().Remove(OnPlayerKilled);
345  }
346 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
GetSuppliesMax
int GetSuppliesMax()
Definition: SCR_CampaignSuppliesComponent.c:141
SetSupplyLoadingPlayer
void SetSupplyLoadingPlayer(int playerID)
Definition: SCR_CampaignSuppliesComponent.c:65
m_bIsPlayerInRange
protected bool m_bIsPlayerInRange
Definition: SCR_CampaignSuppliesComponent.c:14
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_iSuppliesMax
protected int m_iSuppliesMax
Definition: SCR_CampaignSuppliesComponent.c:34
m_aLoadingPlayerIDs
protected ref array< int > m_aLoadingPlayerIDs
Definition: SCR_CampaignSuppliesComponent.c:19
DeleteSupplyLoadingPlayer
void DeleteSupplyLoadingPlayer(int playerID)
Definition: SCR_CampaignSuppliesComponent.c:79
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_aUnloadingPlayerIDs
protected ref array< int > m_aUnloadingPlayerIDs
Definition: SCR_CampaignSuppliesComponent.c:22
SCR_CampaignSuppliesComponentClass
Definition: SCR_CampaignSuppliesComponent.c:2
m_LastLoadedAt
SCR_CampaignSuppliesComponentClass m_LastLoadedAt
Makes a vehicle able to carry Conflict resources.
SetLastUnloadedAt
void SetLastUnloadedAt(SCR_CampaignMilitaryBaseComponent base)
Definition: SCR_CampaignSuppliesComponent.c:203
Instigator
Definition: Instigator.c:6
EntitySlotInfo
Adds ability to attach an object to a slot.
Definition: EntitySlotInfo.c:8
m_LastXPAwardedAt
protected SCR_CampaignMilitaryBaseComponent m_LastXPAwardedAt
Definition: SCR_CampaignSuppliesComponent.c:12
GetIsStandaloneDepot
bool GetIsStandaloneDepot()
Definition: SCR_CampaignSuppliesComponent.c:247
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_CampaignSuppliesComponent
void SCR_CampaignSuppliesComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CampaignSuppliesComponent.c:327
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
m_bIsStandaloneDepot
bool m_bIsStandaloneDepot
Definition: SCR_CampaignSuppliesComponent.c:40
DeleteSupplyUnloadingPlayer
void DeleteSupplyUnloadingPlayer(int playerID)
Definition: SCR_CampaignSuppliesComponent.c:113
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_fOperationalRadius
protected float m_fOperationalRadius
Definition: SCR_CampaignSuppliesComponent.c:37
OnSuppliesChanged
void OnSuppliesChanged()
Definition: SCR_CampaignSuppliesComponent.c:124
OnPlayerKilled
protected void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
Definition: SCR_CampaignSuppliesComponent.c:90
m_bAwardUnloadXP
protected bool m_bAwardUnloadXP
Definition: SCR_CampaignSuppliesComponent.c:13
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_CampaignSuppliesComponent.c:273
GetOperationalRadius
float GetOperationalRadius()
Definition: SCR_CampaignSuppliesComponent.c:163
SetLastLoadedAt
void SetLastLoadedAt(SCR_CampaignMilitaryBaseComponent base)
Definition: SCR_CampaignSuppliesComponent.c:190
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SetSuppliesMax
void SetSuppliesMax(int suppliesMax)
Definition: SCR_CampaignSuppliesComponent.c:149
SetIsPlayerInRange
void SetIsPlayerInRange(bool status)
Definition: SCR_CampaignSuppliesComponent.c:174
GetSuppliesComponent
SCR_CampaignSuppliesComponent GetSuppliesComponent()
Definition: SCR_CampaignBuildingProviderComponent.c:879
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_CampaignSuppliesComponent.c:253
m_OnSuppliesChanged
ref ScriptInvoker m_OnSuppliesChanged
Definition: SCR_CampaignSuppliesComponent.c:25
GetIsPlayerInRange
bool GetIsPlayerInRange()
Definition: SCR_CampaignSuppliesComponent.c:182
m_iSupplies
protected int m_iSupplies
Definition: SCR_CampaignSuppliesComponent.c:30
AwardXP
bool AwardXP()
Definition: SCR_CampaignSuppliesComponent.c:217
~SCR_CampaignSuppliesComponent
void ~SCR_CampaignSuppliesComponent()
Definition: SCR_CampaignSuppliesComponent.c:333
SetSupplyUnloadingPlayer
void SetSupplyUnloadingPlayer(int playerID)
Definition: SCR_CampaignSuppliesComponent.c:100
GetSupplies
int GetSupplies()
Definition: SCR_CampaignSuppliesComponent.c:133
m_OnSuppliesTruckDeleted
ref ScriptInvoker m_OnSuppliesTruckDeleted
Definition: SCR_CampaignSuppliesComponent.c:26
GetLoadingPlayer
int GetLoadingPlayer(bool unloading=false)
Definition: SCR_CampaignSuppliesComponent.c:46
m_LastUnloadedAt
protected SCR_CampaignMilitaryBaseComponent m_LastUnloadedAt
Definition: SCR_CampaignSuppliesComponent.c:11
Obsolete
RespawnSystemComponentClass GameComponentClass Obsolete()] proto external GenericEntity DoSpawn(string prefab
RespawnSystemComponent should be attached to a gamemode to handle player spawning and respawning.
AddSupplies
void AddSupplies(int supplies, bool replicate=true)
Definition: SCR_CampaignSuppliesComponent.c:227
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180