Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AdjustSignalAction.c
Go to the documentation of this file.
2{
4 [Attribute(defvalue: "0.1", desc: "Adjustment step")]
5 protected float m_fAdjustmentStep;
6
8 [Attribute(desc: "If action should wait for player to use their scroll wheel in order to change value")]
9 protected bool m_bManualAdjustment;
10
12 [Attribute(desc: "Determines if this action will start from the begining when max value is reached - or from the other side if Adjustment Step is below 0")]
13 protected bool m_bLoopAction;
14
16 [Attribute(defvalue: "SelectAction", desc: "Input action for increase")]
17 protected string m_sActionIncrease;
18
20 [Attribute(desc: "Input action for decrease")]
21 protected string m_sActionDecrease;
22
24 [Attribute(desc: "Action start sound event name")]
25 protected string m_sActionStartSoundEvent;
26
28 [Attribute(desc: "Action canceled sound event name")]
30
32 [Attribute(desc: "Movement sound event name")]
33 protected string m_sMovementSoundEvent;
34
36 [Attribute(desc: "Movement stop sound event name")]
37 protected string m_sMovementStopSoundEvent;
38
40 [Attribute(desc: "Show this action only when a player is inside a vehicle")]
41 protected bool m_bOnlyInVehicle;
42
44 [Attribute(desc: "Enable if only the Pilot/Driver should see this action. OnlyInVehicle needs to be true for this to work!")]
45 protected bool m_bPilotOnly;
46
48 protected float m_fTargetValue;
49
51 protected bool m_bIsAdjustedByPlayer;
52
55
57 protected float m_fLerpLast;
58
61
62 //------------------------------------------------------------------------------------------------
65 {
67 }
68
69 //------------------------------------------------------------------------------------------------
70 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
71 {
73 if (GetActionDuration() != 0)
75
77 }
78
79 //------------------------------------------------------------------------------------------------
80 override bool CanBeShownScript(IEntity user)
81 {
83 {
85 return false;
86
88 return false;
89 }
90
91 // Check if player is inside a vehicle
93 return true;
94
95 // See if character is in vehicle
96 ChimeraCharacter character = ChimeraCharacter.Cast(user);
97 if (!character)
98 return false;
99
100 // We cannot be pilot nor interior, if we are not seated in vehicle at all.
101 if (!character.IsInVehicle())
102 return false;
103
104 // See if character is in "this" (owner) vehicle
105 CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
106 if (!compartmentAccess)
107 return false;
108
109 // Character is in compartment
110 // that belongs to owner of this action
111 BaseCompartmentSlot slot = compartmentAccess.GetCompartment();
112 if (!slot)
113 return false;
114
115 // Check pilot only condition
116 if (m_bPilotOnly)
117 {
118 if (!PilotCompartmentSlot.Cast(slot))
119 return false;
120
121 Vehicle vehicle = Vehicle.Cast(GetOwner().GetRootParent());
122 if (vehicle && vehicle.GetPilotCompartmentSlot() != slot)
123 return false;
124 }
125
126 // Check interior only condition
127 if (m_bOnlyInVehicle && slot.GetOwner().GetRootParent() != GetOwner().GetRootParent())
128 return false;
129
130 return true;
131 }
132
133 //------------------------------------------------------------------------------------------------
135 protected void ToggleActionBypass()
136 {
137 HandleAction(1);
138 }
139
140 //------------------------------------------------------------------------------------------------
141 override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
142 {
144 HandleAction(timeSlice);
145 }
146
147 //------------------------------------------------------------------------------------------------
148 override void OnActionStart(IEntity pUserEntity)
149 {
150 if (m_SoundComponent && m_sActionStartSoundEvent != string.Empty)
152
154
156 return;
157
160
161 if (!GetActionDuration())
163
165 return;
166
167 if (!m_sActionIncrease.IsEmpty())
168 GetGame().GetInputManager().AddActionListener(m_sActionIncrease, EActionTrigger.VALUE, HandleAction);
169
170 if (!m_sActionDecrease.IsEmpty())
171 GetGame().GetInputManager().AddActionListener(m_sActionDecrease, EActionTrigger.VALUE, HandleActionDecrease);
172 }
173
174 //------------------------------------------------------------------------------------------------
175 override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
176 {
177 // Play sound
178 if (m_SoundComponent && m_sActionCanceledSoundEvent != string.Empty)
180
182 return;
183
184 m_bIsAdjustedByPlayer = false;
185
187 return;
188
189 if (!m_sActionIncrease.IsEmpty())
190 GetGame().GetInputManager().RemoveActionListener(m_sActionIncrease, EActionTrigger.VALUE, HandleAction);
191
192 if (!m_sActionDecrease.IsEmpty())
193 GetGame().GetInputManager().RemoveActionListener(m_sActionDecrease, EActionTrigger.VALUE, HandleActionDecrease);
194 }
195
196 //------------------------------------------------------------------------------------------------
199 protected void HandleAction(float value)
200 {
201 if (value == 0)
202 return;
203
205 value /= Math.AbsFloat(value);
206
207 value *= m_fAdjustmentStep;
208
209 m_fTargetValue += value;
210 if (m_bLoopAction)
211 {
212 if (value > 0 && float.AlmostEqual(SCR_GetCurrentValue(), SCR_GetMaximumValue()))
214 else if (value < 0 && float.AlmostEqual(SCR_GetCurrentValue(), SCR_GetMinimumValue()))
216 }
217
218 // Round to adjustment step
220
221 // Limit to min/max value
223
224 if (!float.AlmostEqual(m_fTargetValue, SCR_GetCurrentValue()))
226 }
227
228 //------------------------------------------------------------------------------------------------
231 protected void HandleActionDecrease(float value)
232 {
233 HandleAction(-value);
234 }
235
236 //------------------------------------------------------------------------------------------------
238 protected float SCR_GetCurrentValue()
239 {
240 return GetCurrentValue();
241 }
242
243 //------------------------------------------------------------------------------------------------
245 protected float SCR_GetMinimumValue()
246 {
247 return GetMinimumValue();
248 }
249
250 //------------------------------------------------------------------------------------------------
252 protected float SCR_GetMaximumValue()
253 {
254 return GetMaximumValue();
255 }
256
257 //------------------------------------------------------------------------------------------------
259 protected void PlayMovementAndStopSound(float lerp)
260 {
261 if (!m_SoundComponent)
262 return;
263
264 if (m_fLerpLast == lerp)
265 return;
266
267 vector contextTransform[4];
268 GetActiveContext().GetTransformationModel(contextTransform);
269
270 if (float.AlmostEqual(lerp, 1))
271 {
272 if (!float.AlmostEqual(m_fLerpLast, 1))
273 {
275 if (m_sMovementStopSoundEvent != string.Empty)
276 m_SoundComponent.SoundEventOffset(m_sMovementStopSoundEvent, contextTransform[3])
277 }
278 }
279 else if (float.AlmostEqual(lerp, 0))
280 {
281 if (!float.AlmostEqual(m_fLerpLast, 0))
282 {
284 if (m_sMovementStopSoundEvent != string.Empty)
285 m_SoundComponent.SoundEventOffset(m_sMovementSoundEvent, contextTransform[3])
286 }
287 }
288 else
289 {
290 if (m_SoundComponent.IsFinishedPlaying(m_MovementAudioHandle) && m_sMovementSoundEvent != string.Empty)
291 m_SoundComponent.SoundEventOffset(m_sMovementSoundEvent, contextTransform[3])
292 }
293
294 m_fLerpLast = lerp;
295 }
296
297 //------------------------------------------------------------------------------------------------
300 {
301 return false;
302 }
303
304 //------------------------------------------------------------------------------------------------
306 override bool CanBroadcastScript()
307 {
308 return true;
309 }
310
311 //------------------------------------------------------------------------------------------------
314 override protected bool OnSaveActionData(ScriptBitWriter writer)
315 {
316 writer.WriteFloat(m_fTargetValue);
317 SetSignalValue(m_fTargetValue);
319
320 return true;
321 }
322
323 //------------------------------------------------------------------------------------------------
327 override protected bool OnLoadActionData(ScriptBitReader reader)
328 {
329 float targetValue;
330 reader.ReadFloat(targetValue);
331
333 return true;
334
335 m_fTargetValue = targetValue;
336 SetSignalValue(m_fTargetValue);
338
339 return true;
340 }
341
342 //------------------------------------------------------------------------------------------------
343 override float GetActionProgressScript(float fProgress, float timeSlice)
344 {
347
348 return fProgress + timeSlice;
349 }
350}
ArmaReforgerScripted GetGame()
Definition game.c:1398
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external void SetSendActionDataFlag()
Used to ask to send action data again during continuous action.
proto external UserActionContext GetActiveContext()
Getter for m_pActiveContext.
proto external float GetActionDuration()
Returns the duration of this action in seconds.
proto external IEntity GetOwner()
Returns the parent entity of this action.
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
override bool HasLocalEffectOnlyScript()
Is the script broadcast to the server?
float m_fTargetValue
Normalized current value.
override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
bool m_bManualAdjustment
Flag for enabling adjustment with scroll wheel.
override void OnActionStart(IEntity pUserEntity)
bool IsManuallyAdjusted()
Used to tell if this action is meant to be adjustable with usage of the scroll wheel.
override bool CanBroadcastScript()
If HasLocalEffectOnly() is true this method tells if the server is supposed to broadcast this action ...
float SCR_GetMinimumValue()
Scripted version of the GetMinimumValue that can be overriden for custom handling.
bool OnLoadActionData(ScriptBitReader reader)
override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
bool m_bIsAdjustedByPlayer
Interacted with by main entity. Allows reading input actions.
float m_fAdjustmentStep
Adjustment step of normalized value.
override float GetActionProgressScript(float fProgress, float timeSlice)
SoundComponent m_SoundComponent
Sound component on owner entity.
AudioHandle m_MovementAudioHandle
Movement sound AudioHandle.
override bool CanBeShownScript(IEntity user)
void HandleActionDecrease(float value)
string m_sActionStartSoundEvent
Action start sound event name.
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
string m_sMovementStopSoundEvent
Movement stop sound event name.
string m_sActionDecrease
Name of action to control the input.
bool m_bOnlyInVehicle
Should action only be Visible when player is inside the vehicle.
bool m_bPilotOnly
Should the action only be visible for the Pilot/Driver.
float m_fLerpLast
Last lerp value.
string m_sMovementSoundEvent
Movement sound event name.
float SCR_GetCurrentValue()
Scripted version of the GetCurrentValue that can be overriden for custom handling.
bool OnSaveActionData(ScriptBitWriter writer)
void ToggleActionBypass()
Temporary fix for an issue of SetSendActionDataFlag not working properly from PerformAction.
float SCR_GetMaximumValue()
Scripted version of the GetMaximumValue that can be overriden for custom handling.
string m_sActionCanceledSoundEvent
Action canceled sound event name.
void PlayMovementAndStopSound(float lerp)
Plays movement and stop movement sound events.
bool m_bLoopAction
Flag for restarting the process when end value is reached.
string m_sActionIncrease
Name of action to control the input.
static IEntity GetLocalControlledEntity()
This action will take care of the synchronization of the signal value.
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
SCR_FieldOfViewSettings Attribute
EActionTrigger