Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIPickMagazines.c
Go to the documentation of this file.
1 class SCR_AIPickMagazines : AITaskScripted
2 {
3  static const string PORT_MAGAZINE_WELL = "MagazineWell";
4 
5  [Attribute("", UIWidgets.EditBox, "Name of magazine well" )]
6  protected string m_sMagazineWellType;
7 
8  private IEntity m_OwnerEntity;
9  private SCR_InventoryStorageManagerComponent m_Inventory;
10  private typename m_oMagazineWell;
11 
12  protected static ref TStringArray s_aVarsIn = {
13  PORT_MAGAZINE_WELL
14  };
15  override TStringArray GetVariablesIn()
16  {
17  return s_aVarsIn;
18  }
19 
20  override void OnInit(AIAgent owner)
21  {
22  m_OwnerEntity = owner.GetControlledEntity();
23  if (!m_OwnerEntity)
24  Debug.Error("Owner must be a character!");
25  m_Inventory = SCR_InventoryStorageManagerComponent.Cast(m_OwnerEntity.FindComponent(SCR_InventoryStorageManagerComponent));
26  }
27 
28  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
29  {
30  if (!m_Inventory)
31  ENodeResult.FAIL;
32 
33  if (!GetVariableIn(PORT_MAGAZINE_WELL,m_oMagazineWell))
34  m_oMagazineWell = m_sMagazineWellType.ToType();
35 
36  CharacterVicinityComponent vicinity = CharacterVicinityComponent.Cast(m_OwnerEntity.FindComponent(CharacterVicinityComponent));
37  if (vicinity)
38  {
39  array<IEntity> items = {};
40  vicinity.GetAvailableItems(items);
41 
42  foreach (IEntity item : items)
43  {
44  MagazineComponent magComp = MagazineComponent.Cast(item.FindComponent(MagazineComponent));
45  if (!magComp)
46  continue;
47  if (magComp.GetMagazineWell().Type() == m_oMagazineWell && !m_Inventory.TryInsertItem(item,EStoragePurpose.PURPOSE_DEPOSIT))
48  {
49  CharacterControllerComponent charCtrlComp = CharacterControllerComponent.Cast(ChimeraCharacter.Cast(m_OwnerEntity).GetCharacterController());
50  charCtrlComp.ReloadWeaponWith(item);
51  }
52  }
53 
54  if (items.Count() == 0)
55  {
56  PrintFormat("No items found to pick up by %1!",m_OwnerEntity);
57  return ENodeResult.FAIL;
58  }
59  else
60  return ENodeResult.SUCCESS;
61  }
62  return ENodeResult.FAIL;
63  }
64 
65  protected override bool VisibleInPalette()
66  {
67  return true;
68  }
69 
70  protected override string GetOnHoverDescription()
71  {
72  return "AI task that picks up all magazines of provided MagazineWell type in the vicinity of its inventory.";
73  }
74 };
Attribute
typedef Attribute
Post-process effect of scripted camera.
EStoragePurpose
EStoragePurpose
Definition: EStoragePurpose.c:12
SCR_AIPickMagazines
Definition: SCR_AIPickMagazines.c:1
m_OwnerEntity
SCR_AIUtilityComponentClass m_OwnerEntity