Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ToggleSafetyUserAction.c
Go to the documentation of this file.
2 {
3  [Attribute("0", UIWidgets.ComboBox, "", "", ParamEnumArray.FromEnum(EMuzzleType))]
4  protected EMuzzleType m_eMuzzleType;
5 
6  protected WeaponAttachmentsStorageComponent m_AttachmentStorage;
7 
8  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
9  {
10  CharacterControllerComponent charComp = CharacterControllerComponent.Cast(pUserEntity.FindComponent(CharacterControllerComponent));
11  charComp.SetSafety(!IsSafetyOn(), false);
12  }
13 
14  override bool CanBeShownScript(IEntity user)
15  {
16  if (!m_WeaponComponent)
17  {
18  if (m_AttachmentStorage)
19  {
20  InventoryStorageSlot slot = m_AttachmentStorage.GetParentSlot();
21  if (!slot)
22  return false;
23 
24  IEntity weapon = m_AttachmentStorage.GetParentSlot().GetOwner();
25  if (weapon)
26  m_WeaponComponent = WeaponComponent.Cast(weapon.FindComponent(WeaponComponent));
27  }
28 
29  return false;
30  }
31 
32  if (m_WeaponComponent.GetCurrentMuzzle().GetMuzzleType() != m_eMuzzleType)
33  return false;
34 
35  CharacterControllerComponent charComp = CharacterControllerComponent.Cast(user.FindComponent(CharacterControllerComponent));
36  return (charComp && charComp.GetInspect());
37  }
38 
39  bool IsSafetyOn()
40  {
41  BaseMuzzleComponent muzzle = m_WeaponComponent.GetCurrentMuzzle();
42  return (muzzle.GetCurrentFireMode().GetFiremodeType() == EWeaponFiremodeType.Safety);
43  }
44 
45  override bool GetActionNameScript(out string outName)
46  {
47  if (IsSafetyOn())
48  {
49  outName = WidgetManager.Translate("#AR-Keybind_WeaponSafety (%1)", "#AR-UserAction_State_On-UC");
50  }
51  else
52  {
53  outName = WidgetManager.Translate("#AR-Keybind_WeaponSafety (%1)", "#AR-UserAction_State_Off-UC");
54  }
55  return true;
56  }
57 
58  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
59  {
60  if (m_eMuzzleType == EMuzzleType.MT_BaseMuzzle)
61  {
62  m_WeaponComponent = WeaponComponent.Cast(pOwnerEntity.FindComponent(WeaponComponent));
63  }
64  else if (m_eMuzzleType == EMuzzleType.MT_UGLMuzzle)
65  {
66  // not ideal, but we cannot get parent slot in init and have to retrieve it later
67  m_AttachmentStorage = WeaponAttachmentsStorageComponent.Cast(pOwnerEntity.FindComponent(WeaponAttachmentsStorageComponent));
68  }
69  }
70 };
InventoryStorageSlot
Definition: InventoryStorageSlot.c:12
EWeaponFiremodeType
EWeaponFiremodeType
Definition: EWeaponFiremodeType.c:12
SCR_ToggleSafetyUserAction
Definition: SCR_ToggleSafetyUserAction.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_InspectionUserAction
Definition: SCR_InspectionUserAction.c:1
EMuzzleType
EMuzzleType
Definition: EMuzzleType.c:12
BaseMuzzleComponent
Definition: BaseMuzzleComponent.c:12