Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
TestAimModifier.c
Go to the documentation of this file.
2 {
3  //------------------------------------------------------------------------------------------------
4  private void Register(SCR_DebugMenuID id, string name, bool angles = false)
5  {
6  const string angleLimits = "-180, 180, 0, 0.01";
7  const string linearLimits = "-10, 10, 0, 0.0001";
8 
9  if (angles)
10  DiagMenu.RegisterRange(id, "", name, "TestAimModifier", angleLimits);
11  else
12  DiagMenu.RegisterRange(id, "", name, "TestAimModifier", linearLimits);
13  }
14 
15  //------------------------------------------------------------------------------------------------
16  protected override void OnInit(IEntity weaponEnt)
17  {
18  // Reg menu
19  DiagMenu.RegisterMenu(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_MENU, "TestAimModifier","Weapons");
20 
21  // Linear
22  {
23  Register(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_LIN_X, "Linear X");
24  Register(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_LIN_Y, "Linear Y");
25  Register(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_LIN_Z, "Linear Z");
26  }
27  // Angular
28  {
29  Register(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_ANG_X, "Angular X", true);
30  Register(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_ANG_Y, "Angular Y", true);
31  Register(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_ANG_Z, "Angular Z", true);
32  }
33  // Turn
34  {
35  Register(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_TURN_X, "Turn X", true);
36  Register(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_TURN_Y, "Turn Y", true);
37  }
38 
39  // Reset
40  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_RESET, "", "Reset aim mod", "TestAimModifier");
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  private void SetLinear(vector v)
45  {
46  DiagMenu.SetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_LIN_X, v[0]);
47  DiagMenu.SetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_LIN_Y, v[1]);
48  DiagMenu.SetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_LIN_Z, v[2]);
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  private vector GetLinear()
53  {
54  return Vector(
55  DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_LIN_X),
56  DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_LIN_Y),
57  DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_LIN_Z)
58  );
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  private void SetAngular(vector v)
63  {
64  DiagMenu.SetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_ANG_X, v[0]);
65  DiagMenu.SetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_ANG_Y, v[1]);
66  DiagMenu.SetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_ANG_Z, v[2]);
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  private vector GetAngular()
71  {
72  return Vector(
73  DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_ANG_X),
74  DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_ANG_Y),
75  DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_ANG_Z)
76  );
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  private void SetTurn(vector v)
81  {
82  DiagMenu.SetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_TURN_X, v[0]);
83  DiagMenu.SetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_TURN_Y, v[1]);
84  }
85 
86  //------------------------------------------------------------------------------------------------
87  private vector GetTurn()
88  {
89  return Vector(
90  DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_TURN_X),
91  DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_TURN_Y),
92  0
93  );
94  }
95  //------------------------------------------------------------------------------------------------
96  // called every frame after aim offset is calculated
97  protected override void OnCalculate(IEntity owner, WeaponAimModifierContext context, float timeSlice, out vector translation, out vector rotation, out vector turnOffset)
98  {
99  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_RESET))
100  {
101  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_AIMMODIFIER_RESET, 0);
102  SetLinear(vector.Zero);
103  SetAngular(vector.Zero);
104  SetTurn(vector.Zero);
105  }
106 
107  translation = GetLinear();
108  rotation = GetAngular();
109  turnOffset = GetTurn();
110 
111  if (m_weaponManagerComponent)
112  {
113  BaseWeaponComponent weaponComponent = m_weaponManagerComponent.GetCurrentWeapon();
114  if (weaponComponent)
115  {
116  BaseSightsComponent bsc = weaponComponent.GetSights();
117  if (bsc)
118  {
119  bsc.ForceSightsZeroValue(translation, rotation, turnOffset);
120  }
121  }
122  }
123  }
124  //------------------------------------------------------------------------------------------------
125  // called when weapon is fired
126  protected override void OnWeaponFired()
127  {
128  }
129 
130 
131  //------------------------------------------------------------------------------------------------
132  // called when weapon is activated
133  protected override void OnActivated(IEntity weaponOwner)
134  {
135  m_weaponManagerComponent = BaseWeaponManagerComponent.Cast(weaponOwner.FindComponent(BaseWeaponManagerComponent));
136  }
137 
138  protected BaseWeaponManagerComponent m_weaponManagerComponent;
139 };
ScriptedWeaponAimModifier
Definition: ScriptedWeaponAimModifier.c:12
WeaponAimModifierContext
Definition: WeaponAimModifierContext.c:16
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
rotation
RespawnSystemComponentClass GameComponentClass vector vector rotation
Definition: RespawnSystemComponent.c:23
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
TestAimModifier
Definition: TestAimModifier.c:1