Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDropWeapon.c
Go to the documentation of this file.
1 // Script File
2 class SCR_AIDropWeapon: AITaskScripted
3 {
4  private GenericEntity m_Controlled = null;
5  private BaseWeaponManagerComponent m_WpnManager = null;
6  private SCR_CharacterControllerComponent m_Controller = null;
7  private SCR_InventoryStorageManagerComponent m_Inventory;
8 
9  //------------------------------------------------------------------------------------------------
10  override void OnInit(AIAgent owner)
11  {
12  m_Controlled = null;
13  }
14 
15  //------------------------------------------------------------------------------------------------
16  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
17  {
18  IEntity contr = owner.GetControlledEntity();
19  if (m_Controlled != contr)
20  {
21  m_Controlled = GenericEntity.Cast(contr);
22  if (m_Controlled)
23  {
24  m_WpnManager = BaseWeaponManagerComponent.Cast(m_Controlled.FindComponent(BaseWeaponManagerComponent));
26  m_Inventory = SCR_InventoryStorageManagerComponent.Cast(m_Controlled.FindComponent(SCR_InventoryStorageManagerComponent));
27  }
28  }
29 
30  if (!m_Controlled || !m_WpnManager || !m_Controller || !m_Inventory)
31  return NodeError(this, owner, "Missing components.");
32 
33  WeaponSlotComponent slot = WeaponSlotComponent.Cast(m_WpnManager.GetCurrentSlot());
34  if (!slot)
35  return ENodeResult.FAIL;
36  IEntity weaponEntity = slot.GetWeaponEntity();
37  if (!weaponEntity)
38  return ENodeResult.FAIL;
39  InventoryItemComponent pInvComp = InventoryItemComponent.Cast( weaponEntity.FindComponent( InventoryItemComponent ) );
40  if (!pInvComp)
41  return ENodeResult.FAIL;
42  InventoryStorageSlot parentSlot = pInvComp.GetParentSlot();
43  if (!parentSlot)
44  return ENodeResult.FAIL;
45  bool removed = m_Inventory.TryRemoveItemFromStorage(weaponEntity, parentSlot.GetStorage());
46  if (removed)
47  return ENodeResult.SUCCESS;
48  else
49  return ENodeResult.FAIL;
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  override bool VisibleInPalette()
54  {
55  return true;
56  }
57 
58 };
SCR_AIDropWeapon
Definition: SCR_AIDropWeapon.c:2
m_Controller
protected CompartmentControllerComponent m_Controller
Definition: SCR_VehicleDamageManagerComponent.c:197
InventoryStorageSlot
Definition: InventoryStorageSlot.c:12
WeaponSlotComponent
Definition: WeaponSlotComponent.c:12
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
NodeError
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition: NodeError.c:3
InventoryItemComponent
Definition: InventoryItemComponent.c:12