Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
WeaponLib.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
5 //------------------------------------------------------------------------------------------------
7 {
8  //-----------------------------------------------------------------------------------------------------------
10  static BaseWeaponComponent GetCurrentWeaponComponent(notnull ChimeraCharacter owner)
11  {
12  // Detect weapon manager
13  CharacterControllerComponent controller = owner.GetCharacterController();
14  if (!controller)
15  return null;
16 
17  BaseWeaponManagerComponent weaponManager = controller.GetWeaponManagerComponent();
18  if (!weaponManager)
19  return null;
20 
21  BaseWeaponComponent weapon = SCR_WeaponLib.GetCurrentWeaponComponent(weaponManager);
22 
23  return weapon;
24  }
25 
26  //-----------------------------------------------------------------------------------------------------------
28  static BaseWeaponComponent GetCurrentWeaponComponent(notnull BaseWeaponManagerComponent weaponManager)
29  {
30  // Get weapon OR weapon slot
31  BaseWeaponComponent weapon = weaponManager.GetCurrent();
32  if (!weapon)
33  return null;
34 
35  // Try casting to weapon slot to check if it's weapon slot OR weapon
36  WeaponSlotComponent weaponSlot = WeaponSlotComponent.Cast(weapon);
37 
38  // Weapon slot detected, retrieve weapon from it
39  if (weaponSlot)
40  {
41  IEntity weaponEntity = weaponSlot.GetWeaponEntity();
42  if (!weaponEntity)
43  return null;
44 
45  BaseWeaponComponent wpnComponent = BaseWeaponComponent.Cast(weaponEntity.FindComponent(BaseWeaponComponent));
46  if (!wpnComponent)
47  return null;
48 
49  weapon = wpnComponent;
50  }
51 
52  return weapon;
53  }
54 
55  //-----------------------------------------------------------------------------------------------------------
57  static bool CurrentWeaponHasComponent(notnull BaseWeaponManagerComponent weaponManager, typename component)
58  {
59  BaseWeaponComponent weapon = weaponManager.GetCurrent();
60  if (!weapon)
61  return false;
62 
63  // Try casting to weapon slot to check if it's weapon slot OR weapon
64  WeaponSlotComponent weaponSlot = WeaponSlotComponent.Cast(weapon);
65 
66  // Weapon slot detected, retrieve weapon from it
67  if (weaponSlot)
68  {
69  IEntity weaponEntity = weaponSlot.GetWeaponEntity();
70  if (weaponEntity && weaponEntity.FindComponent(component))
71  return true;
72  }
73 
74  return false;
75  }
76 
77  //------------------------------------------------------------------------------------------------
79  static int GetNextMuzzleID(notnull BaseWeaponComponent weapon)
80  {
81  array<BaseMuzzleComponent> muzzles = {};
82  weapon.GetMuzzlesList(muzzles);
83  if (muzzles.IsEmpty())
84  return -1;
85 
86  int currentMuzzleID = muzzles.Find(weapon.GetCurrentMuzzle());
87 
88  return (currentMuzzleID + 1) % muzzles.Count();
89  }
90 };
SCR_WeaponLib
Definition: WeaponLib.c:6
WeaponSlotComponent
Definition: WeaponSlotComponent.c:12
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12