Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ScriptedUserAction.c
Go to the documentation of this file.
3
6{
7 [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")]
8 protected bool m_bLoopAction;
9
10 [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")]
12
13 [Attribute("0", desc: "Using this action should automatically lower player weapon")]
14 protected bool m_bLowerWeaponOnUse;
15
16 [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))]
17 protected EUserActionInVehicleState m_eShownInVehicleState;
18
19 [Attribute("1", desc: "Whether this action can only be performed by occupants of the same vehicle (if in vehicle)", uiwidget: UIWidgets.CheckBox)]
20 protected bool m_bSameVehicleOnly;
21
22 protected UserActionContext m_LastUserActionContext; //~ Last user action context when the action was selected. used for getting the action position
23
24 //~ Keeps track of action duration if LoopUpdate is used
25 protected float m_fLoopProgress;
27
28 //================================================== CAN SHOW ==================================================\\
29 override bool CanBeShownScript(IEntity user)
30 {
31 if (m_eShownInVehicleState == EUserActionInVehicleState.IGNORE)
32 return true;
33
34 //~ Only check when character
37 {
38 character = ChimeraCharacter.Cast(user);
39 if (!character)
40 return true;
41 }
42
43 //~ Only check when has compartment access
44 CompartmentAccessComponent compAccess = character.GetCompartmentAccessComponent();
46 return true;
47
48 //~ Never show when getting in or out vehicle
49 if (compAccess.IsGettingIn() || compAccess.IsGettingOut())
50 return false;
51
52 //~ Is character in vehicle?
53 bool isCharacterInVehicle = character.IsInVehicle();
54
55 //~ Check if correct state
57 {
58 //~ Character should not be in vehicle
59 case EUserActionInVehicleState.NOT_IN_VEHICLE :
60 {
62 return false;
63
64 break;
65 }
66 //~ Check if character is in current vehicle and is in any position
67 case EUserActionInVehicleState.IN_VEHICLE_ANY :
68 {
70 return false;
71
72 break;
73 }
74 //~ Check if character is in current vehicle and pilot
75 case EUserActionInVehicleState.IN_VEHICLE_PILOT :
76 {
77 if (!isCharacterInVehicle || compAccess.GetCompartment().GetType() != ECompartmentType.PILOT)
78 return false;
79
80 break;
81 }
82 //~ Check if character is in current vehicle and cargo
83 case EUserActionInVehicleState.IN_VEHICLE_CARGO :
84 {
85 if (!isCharacterInVehicle || compAccess.GetCompartment().GetType() != ECompartmentType.CARGO)
86 return false;
87
88 break;
89 }
90 //~ Check if character is in current vehicle and turret
91 case EUserActionInVehicleState.IN_VEHICLE_TURRET :
92 {
93 if (!isCharacterInVehicle || compAccess.GetCompartment().GetType() != ECompartmentType.TURRET)
94 return false;
95
96 break;
97 }
98 }
99
100 //~ 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)
103
104 //~ All passed so return true
105 return true;
106 }
107
108 //------------------------------------------------------------------------------------------------
109 protected bool IsSameVehicleOrNone(notnull IEntity user)
110 {
111
112 // See if user can even access compartments
113 CompartmentAccessComponent userCompAccess;
114
115 // Use cached getter for character, but don't hinder logic for non-character users
116 ChimeraCharacter userCharacter = ChimeraCharacter.Cast(user);
117 if (userCharacter)
118 userCompAccess = userCharacter.GetCompartmentAccessComponent();
119 else
120 userCompAccess = CompartmentAccessComponent.Cast(user.FindComponent(CompartmentAccessComponent));
121
122 if (!userCompAccess)
123 return true; // Not really relevant
124
125 IEntity owner = GetOwner();
126 CompartmentAccessComponent ownerAccess = CompartmentAccessComponent.Cast(owner.FindComponent(CompartmentAccessComponent));
127 if (!ownerAccess)
128 {
129 // If owner does not have comparment access, perhaps it is a vehicle itself?
130 Vehicle vehicle = Vehicle.Cast(owner);
131 if (!vehicle)
132 return true; // No access, not relevant either
133
134 IEntity userVehicle = userCompAccess.GetVehicleIn(user);
135 return userVehicle == vehicle; // Same vehicle
136 }
137
138 // If both can access compartments, see if they are within the same vehicle
139 IEntity userVehicle = userCompAccess.GetVehicleIn(user);
140 IEntity ownerVehicle = ownerAccess.GetVehicleIn(owner);
141 return userVehicle == ownerVehicle;
142 }
143
144 //================================================== GETTERS ==================================================\\
145
151 {
153 return vector.Zero;
154
155 return GetOwner().CoordToLocal(m_LastUserActionContext.GetOrigin());
156 }
157
158 //------------------------------------------------------------------------------------------------
165 {
167 return GetOwner().GetOrigin();
168
169 return m_LastUserActionContext.GetOrigin();
170 }
171
172 //------------------------------------------------------------------------------------------------
173 //~ Update for looping actions. Make sure duration is set to less than 0 and perform continues is true.
174 //~ Will return true if a loop was successfully completed
175 protected bool LoopActionUpdate(float timeSlice)
176 {
177 float lastLoopProgress = m_fLoopProgress;
178
179 m_fLoopProgress -= timeSlice;
180
181 bool bLoopDone = false;
182
183 //~ Is loop done ?
184 if (lastLoopProgress > 0 && m_fLoopProgress <= 0)
185 bLoopDone = true; // Loop Done
186
187 // Is hold duration done ?
189 {
190 // Hold duration (after loop done) is over.
192 }
193
194 return bLoopDone;
195 }
196
197 //------------------------------------------------------------------------------------------------
201 override float GetActionProgressScript(float fProgress, float timeSlice)
202 {
203 fProgress = fProgress + timeSlice;
204
205 if (!IsActionLooping())
206 return fProgress;
207
208 float actionDuration = Math.AbsFloat(GetActionDuration());
209 float totalDuration = actionDuration + m_fLoopActionHoldDuration;
210
211 fProgress = Math.Min(Math.Mod(fProgress, totalDuration), actionDuration); // updated every frame
212 float fTargetProgress = Math.Min(totalDuration - (m_fLoopProgress + m_fLoopActionHoldDuration), actionDuration); // update every fixed frame
213
214 return Math.SmoothCD(fProgress, fTargetProgress, m_fLoopProgressSmoothVelocity, 0.01, 1000, timeSlice);
215 }
216
217 //------------------------------------------------------------------------------------------------
222 {
224 }
225
226 //------------------------------------------------------------------------------------------------
234
235 //------------------------------------------------------------------------------------------------
236 protected override void OnActionSelected()
237 {
239 }
240
241 //------------------------------------------------------------------------------------------------
242 override void OnActionStart(IEntity pUserEntity)
243 {
245
246 //~ Used for looping actions
249
251 {
253 {
254 RplComponent rplComp = RplComponent.Cast(pUserEntity.FindComponent(RplComponent));
255 if (rplComp && !rplComp.IsOwner())
256 return;
257 }
258
259 ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
260 if (!character)
261 return;
262
263 CharacterControllerComponent contr = character.GetCharacterController();
264 if (!contr)
265 return;
266
267 if (contr.CanPartialLower() && !contr.IsPartiallyLowered())
268 contr.SetPartialLower(true);
269 }
270 }
271}
272
273//------------------------------------------------------------------------------------------------
274//~ When can the action be shown
275enum EUserActionInVehicleState
276{
283}
284
ECompartmentType
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ScriptedUserAction IN_VEHICLE_CARGO
SCR_ScriptedUserAction IN_VEHICLE_ANY
func UserActionEventListener
SCR_ScriptedUserAction IN_VEHICLE_TURRET
SCR_ScriptedUserAction IN_VEHICLE_PILOT
SCR_ScriptedUserAction NOT_IN_VEHICLE
proto external bool ShouldPerformPerFrame()
Should this action be performed every frame the input action is triggered?
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)
proto external vector GetOrigin()
proto external vector CoordToLocal(vector coord)
Definition Math.c:13
static IEntity GetLocalControlledEntity()
A scripted action class having optional logic to check if vehicle is valid.
CompartmentAccessComponent compAccess
bool LoopActionUpdate(float timeSlice)
UserActionContext m_LastUserActionContext
Get action local position Used for such things like playing audio at the correct location on action use return action local position *vector GetLocalPositionAction()
override void OnActionStart(IEntity pUserEntity)
bool IsSameVehicleOrNone(notnull IEntity user)
override float GetActionProgressScript(float fProgress, float timeSlice)
EUserActionInVehicleState m_eShownInVehicleState
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
SCR_FieldOfViewSettings Attribute
@ IGNORE
Ignore any parent and always create root record.
EUserActionEvent