Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScriptedUserAction.c
Go to the documentation of this file.
3 {
4  [Attribute("1", desc: "If action is Continuous and duration is less than 0 than the UI process bar goes to 0 again if it reaches the perform action amount")]
5  protected bool m_bLoopAction;
6 
7  [Attribute("0.25", desc: "If action is looping this will be used to delay the action after it reaches 100% to prevent the action from instantly looping", params: "0 inf")]
8  protected float m_fLoopActionHoldDuration;
9 
10  [Attribute("0", desc: "Using this action should automatically lower player weapon")]
11  protected bool m_bLowerWeaponOnUse;
12 
13  [Attribute("0", desc: "When can the action be shown regarding the vehicle you are in. Note only checked for vehicle that the action is attached to. IGNORE will never check vehicle state", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(EUserActionInVehicleState))]
14  protected EUserActionInVehicleState m_eShownInVehicleState;
15 
16  [Attribute("1", desc: "Whether this action can only be performed by occupants of the same vehicle (if in vehicle)", uiwidget: UIWidgets.CheckBox)]
17  protected bool m_bSameVehicleOnly;
18 
19  protected UserActionContext m_LastUserActionContext; //~ Last user action context when the action was selected. used for getting the action position
20 
21  //~ Keeps track of action duration if LoopUpdate is used
22  protected float m_fLoopProgress;
23  protected float m_fLoopProgressSmoothVelocity;
24 
25  //================================================== CAN SHOW ==================================================\\
26  override bool CanBeShownScript(IEntity user)
27  {
28  if (m_eShownInVehicleState == EUserActionInVehicleState.IGNORE)
29  return true;
30 
31  //~ Only check when character
32  ChimeraCharacter character = ChimeraCharacter.Cast(GetOwner());
33  if (!character)
34  {
35  character = ChimeraCharacter.Cast(user);
36  if (!character)
37  return true;
38  }
39 
40  //~ Only check when has compartment access
41  CompartmentAccessComponent compAccess = character.GetCompartmentAccessComponent();
42  if (!compAccess)
43  return true;
44 
45  //~ Never show when getting in or out vehicle
46  if (compAccess.IsGettingIn() || compAccess.IsGettingOut())
47  return false;
48 
49  //~ Is character in vehicle?
50  bool isCharacterInVehicle = character.IsInVehicle();
51 
52  //~ Check if correct state
53  switch (m_eShownInVehicleState)
54  {
55  //~ Character should not be in vehicle
56  case EUserActionInVehicleState.NOT_IN_VEHICLE :
57  {
58  if (isCharacterInVehicle)
59  return false;
60 
61  break;
62  }
63  //~ Check if character is in current vehicle and is in any position
64  case EUserActionInVehicleState.IN_VEHICLE_ANY :
65  {
66  if (!isCharacterInVehicle)
67  return false;
68 
69  break;
70  }
71  //~ Check if character is in current vehicle and pilot
72  case EUserActionInVehicleState.IN_VEHICLE_PILOT :
73  {
74  if (!isCharacterInVehicle || compAccess.GetCompartment().GetType() != ECompartmentType.Pilot)
75  return false;
76 
77  break;
78  }
79  //~ Check if character is in current vehicle and cargo
80  case EUserActionInVehicleState.IN_VEHICLE_CARGO :
81  {
82  if (!isCharacterInVehicle || compAccess.GetCompartment().GetType() != ECompartmentType.Cargo)
83  return false;
84 
85  break;
86  }
87  //~ Check if character is in current vehicle and turret
88  case EUserActionInVehicleState.IN_VEHICLE_TURRET :
89  {
90  if (!isCharacterInVehicle || compAccess.GetCompartment().GetType() != ECompartmentType.Turret)
91  return false;
92 
93  break;
94  }
95  }
96 
97  //~ Disallow actions from being performed from the outside of a vehicle or the other way around, unless they are in the same vehicle (if set)
98  if (isCharacterInVehicle && m_bSameVehicleOnly)
99  return IsSameVehicleOrNone(character);
100 
101  //~ All passed so return true
102  return true;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  protected bool IsSameVehicleOrNone(notnull IEntity user)
107  {
108 
109  // See if user can even access compartments
110  CompartmentAccessComponent userCompAccess;
111 
112  // Use cached getter for character, but don't hinder logic for non-character users
113  ChimeraCharacter userCharacter = ChimeraCharacter.Cast(user);
114  if (userCharacter)
115  userCompAccess = userCharacter.GetCompartmentAccessComponent();
116  else
117  userCompAccess = CompartmentAccessComponent.Cast(user.FindComponent(CompartmentAccessComponent));
118 
119  if (!userCompAccess)
120  return true; // Not really relevant
121 
122  IEntity owner = GetOwner();
123  CompartmentAccessComponent ownerAccess = CompartmentAccessComponent.Cast(owner.FindComponent(CompartmentAccessComponent));
124  if (!ownerAccess)
125  {
126  // If owner does not have comparment access, perhaps it is a vehicle itself?
127  Vehicle vehicle = Vehicle.Cast(owner);
128  if (!vehicle)
129  return true; // No access, not relevant either
130 
131  IEntity userVehicle = userCompAccess.GetVehicleIn(user);
132  return userVehicle == vehicle; // Same vehicle
133  }
134 
135  // If both can access compartments, see if they are within the same vehicle
136  IEntity userVehicle = userCompAccess.GetVehicleIn(user);
137  IEntity ownerVehicle = ownerAccess.GetVehicleIn(owner);
138  return userVehicle == ownerVehicle;
139  }
140 
141  //================================================== GETTERS ==================================================\\
142 
147  vector GetLocalPositionAction()
148  {
149  if (!m_LastUserActionContext)
150  return vector.Zero;
151 
152  return GetOwner().CoordToLocal(m_LastUserActionContext.GetOrigin());
153  }
154 
155  //------------------------------------------------------------------------------------------------
161  vector GetWorldPositionAction()
162  {
163  if (!m_LastUserActionContext)
164  return GetOwner().GetOrigin();
165 
166  return m_LastUserActionContext.GetOrigin();
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  //~ Update for looping actions. Make sure duration is set to less than 0 and perform continues is true.
171  //~ Will return true if a loop was successfully completed
172  protected bool LoopActionUpdate(float timeSlice)
173  {
174  float lastLoopProgress = m_fLoopProgress;
175 
176  m_fLoopProgress -= timeSlice;
177 
178  bool bLoopDone = false;
179 
180  //~ Is loop done ?
181  if (lastLoopProgress > 0 && m_fLoopProgress <= 0)
182  bLoopDone = true; // Loop Done
183 
184  // Is hold duration done ?
185  if (m_fLoopProgress < -m_fLoopActionHoldDuration)
186  {
187  // Hold duration (after loop done) is over.
188  m_fLoopProgress = Math.AbsFloat(GetActionDuration()) + m_fLoopActionHoldDuration + m_fLoopProgress;
189  }
190 
191  return bLoopDone;
192  }
193 
194  //------------------------------------------------------------------------------------------------
198  float GetActionProgress(float fProgress, float timeSlice)
199  {
200  fProgress = fProgress + timeSlice;
201 
202  if (!IsActionLooping())
203  return fProgress;
204 
205  float actionDuration = Math.AbsFloat(GetActionDuration());
206  float totalDuration = actionDuration + m_fLoopActionHoldDuration;
207 
208  fProgress = Math.Min(Math.Mod(fProgress, totalDuration), actionDuration); // updated every frame
209  float fTargetProgress = Math.Min(totalDuration - (m_fLoopProgress + m_fLoopActionHoldDuration), actionDuration); // update every fixed frame
210 
211  return Math.SmoothCD(fProgress, fTargetProgress, m_fLoopProgressSmoothVelocity, 0.01, 1000, timeSlice);
212  }
213 
214  //------------------------------------------------------------------------------------------------
218  bool IsActionLooping()
219  {
220  return m_bLoopAction && ShouldPerformPerFrame() && GetActionDuration() < 0;
221  }
222 
223  //------------------------------------------------------------------------------------------------
227  float GetLoopActionHoldDuration()
228  {
229  return m_fLoopActionHoldDuration;
230  }
231 
232  //------------------------------------------------------------------------------------------------
233  protected override void OnActionSelected()
234  {
235  m_LastUserActionContext = GetActiveContext();
236  }
237 
238  //------------------------------------------------------------------------------------------------
239  override void OnActionStart(IEntity pUserEntity)
240  {
241  m_LastUserActionContext = GetActiveContext();
242 
243  //~ Used for looping actions
244  if (ShouldPerformPerFrame())
245  m_fLoopProgress = Math.AbsFloat(GetActionDuration());
246 
247  if (m_bLowerWeaponOnUse)
248  {
249  if (SCR_PlayerController.GetLocalControlledEntity() != pUserEntity)
250  {
251  RplComponent rplComp = RplComponent.Cast(pUserEntity.FindComponent(RplComponent));
252  if (rplComp && !rplComp.IsOwner())
253  return;
254  }
255 
256  ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
257  if (!character)
258  return;
259 
260  CharacterControllerComponent contr = character.GetCharacterController();
261  if (!contr)
262  return;
263 
264  if (contr.CanPartialLower() && !contr.IsPartiallyLowered())
265  contr.SetPartialLower(true);
266  }
267  }
268 }
269 
270 //------------------------------------------------------------------------------------------------
271 //~ When can the action be shown
272 enum EUserActionInVehicleState
273 {
274  IGNORE = 0,
275  NOT_IN_VEHICLE = 10,
276  IN_VEHICLE_ANY = 20,
277  IN_VEHICLE_PILOT = 30,
278  IN_VEHICLE_TURRET = 40,
279  IN_VEHICLE_CARGO = 50,
280 }
281 
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_ScriptedUserAction
A scripted action class having optional logic to check if vehicle is valid.
Definition: SCR_ScriptedUserAction.c:2
ScriptedUserAction
Definition: ScriptedUserAction.c:12
ECompartmentType
ECompartmentType
Definition: ECompartmentType.c:7
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
IN_VEHICLE_CARGO
SCR_ScriptedUserAction IN_VEHICLE_CARGO
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
NOT_IN_VEHICLE
SCR_ScriptedUserAction NOT_IN_VEHICLE
IN_VEHICLE_TURRET
SCR_ScriptedUserAction IN_VEHICLE_TURRET
IN_VEHICLE_ANY
SCR_ScriptedUserAction IN_VEHICLE_ANY
UserActionContext
Definition: UserActionContext.c:15
IGNORE
SCR_ScriptedUserAction IGNORE
IN_VEHICLE_PILOT
SCR_ScriptedUserAction IN_VEHICLE_PILOT