Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlaceableItemComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Components", description: "")]
3{
4 [Attribute(uiwidget: UIWidgets.CheckBox, desc: "Can this entity be attached to dynamic objects.")]
6
7 [Attribute(defvalue: "0", desc: "Max Allowed Tilt\n0 = no tilt allowed\nvalue below 0 means that there will be no tilt validation", params: "-1 180 0.01")]
8 protected float m_fMaxAllowedTilt;
9
10 [Attribute(uiwidget: UIWidgets.Flags, desc: "Set of flags that will be used to ignore objects based on their physics layer.\nWARNING: To prevent players from attaching objects to weapons use Ignored Components list\nas checking weapon layer will make it impossible to attach the object to the armed vehicles!", enums: ParamEnumArray.FromEnum(EPhysicsLayerDefs))]
11 protected EPhysicsLayerDefs m_eIgnoredPhysicsLayers;
12
13 [Attribute(uiwidget: UIWidgets.Object, desc: "List of components that when present on target entity or its parent will make it impossible to attach placeable item to it")]
14 protected ref array<string> m_aIgnoredComponents;
15
16 [Attribute(SCR_ECharacterDistanceMeasurementMethod.FROM_EYES.ToString(), UIWidgets.ComboBox, "How the distance between player and placment position should be calculated", enums: ParamEnumArray.FromEnum(SCR_ECharacterDistanceMeasurementMethod))]
18
19 [Attribute(params: "xob")]
21
22 [Attribute("0.5084", desc: "Max placement distance in meters.")]
23 protected float m_fMaxPlacementDistance;
24
25 [Attribute(uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_EPlacementType))]
27
28 [Attribute(defvalue: "0", desc: "Should forward vector be facing away from the player when item is placed.")]
30
31 [Attribute(defvalue: "1", desc: "Should item be attached to the hierachy of the entity on which item is placed")]
33
34 [Attribute(defvalue: "0", desc: "Determines if player should be able to force game to place the item.\nWhen force placment is used, then game does not care about having enough space, but tilt is still evaluated")]
35 protected bool m_bCanBeForcedPlaced;
36
37 protected ref array<typename> m_aIgnoredComponentTypes = {};
38 protected bool m_bValidated;
39
40 //------------------------------------------------------------------------------------------------
46
47 //------------------------------------------------------------------------------------------------
50 {
51 return m_fMaxAllowedTilt;
52 }
53
54 //------------------------------------------------------------------------------------------------
56 EPhysicsLayerDefs GetIgnoredPhysicsLayers()
57 {
59 }
60
61 //------------------------------------------------------------------------------------------------
67
68 //------------------------------------------------------------------------------------------------
70 int GetIgnoredComponents(notnull out array<typename> outIgnoredComponents)
71 {
72 outIgnoredComponents.Clear();
73 foreach (typename comp : m_aIgnoredComponentTypes)
74 {
75 outIgnoredComponents.Insert(comp);
76 }
77
78 return outIgnoredComponents.Count();
79 }
80
81 //------------------------------------------------------------------------------------------------
86
87 //------------------------------------------------------------------------------------------------
92
93 //------------------------------------------------------------------------------------------------
98
99 //------------------------------------------------------------------------------------------------
104
105 //------------------------------------------------------------------------------------------------
110
111 //------------------------------------------------------------------------------------------------
113 {
115 }
116
117 //------------------------------------------------------------------------------------------------
120 {
122 return;
123
124 m_bValidated = true;
125 typename comp;
126 for (int i = m_aIgnoredComponents.Count() - 1; i >= 0; i--)
127 {
128 comp = m_aIgnoredComponents[i].ToType();
129
130 if (!comp.IsInherited(GenericComponent))
131 {
132#ifdef WORKBENCH
133 Print("WARNING! " + m_aIgnoredComponents[i] + " is not inherited from GenericComponent and thus will be removed from the list of ignored components!", LogLevel.ERROR);
134#endif
135 m_aIgnoredComponents.Remove(i);
136 }
137 else
138 {
139 m_aIgnoredComponentTypes.Insert(comp);
140 }
141 }
142 }
143}
144
145class SCR_PlaceableItemComponent : ScriptComponent
146{
147 //------------------------------------------------------------------------------------------------
150 {
152 if (!data)
153 return false;
155 return data.GetPlacementType();
156 }
158 //------------------------------------------------------------------------------------------------
161 {
163 if (!data)
164 return 0;
165
166 return data.GetMaxPlacementDistance();
167 }
168
169 //------------------------------------------------------------------------------------------------
174 if (!data)
175 return false;
176
177 return data.IsForwardFacingAwayFromPlayer();
179
180 //------------------------------------------------------------------------------------------------
185 if (!data)
186 return false;
187
188 return data.CanAttachToTheSurfaceEntity();
189 }
190
191 //------------------------------------------------------------------------------------------------
192
194 {
199 return data.CanBeForcePlaced();
200 }
201
202 //------------------------------------------------------------------------------------------------
204 float GetMaxAllowedTilt()
205 {
207 if (!data)
208 return -1;
210 return data.GetMaxAllowedTilt();
211 }
212
213 //------------------------------------------------------------------------------------------------
216 //! \param[out] cantPlaceReason
217 //! \return true if custom space validation was performed, otherwise false
218 bool OverrideIsSurfaceValid(notnull SCR_ItemPlacementComponent caller, out ENotification cantPlaceReason, IEntity surfaceEnt, vector worldPosition, vector surfaceNorm, int nodeIndex, int colliderIndex, SurfaceProperties surfaceProps, string surfaceMaterial, string colliderName);
219
220 //------------------------------------------------------------------------------------------------
226 bool OverrideSpaceValidation(notnull SCR_ItemPlacementComponent caller, inout vector transform[4], out ENotification cantPlaceReason);
227
228 //------------------------------------------------------------------------------------------------
232 void OverridePreviewTransform(notnull SCR_ItemPlacementComponent caller, inout vector transform[4]);
233
234 //------------------------------------------------------------------------------------------------
238
239 bool OverrideStartPlaceAction(notnull SCR_ItemPlacementComponent caller, out bool skipItemUsage = false);
240
241 //------------------------------------------------------------------------------------------------
247 //------------------------------------------------------------------------------------------------
250
252 //! \param[in] equipNext
253 void OverrideAfterItemPlaced(notnull SCR_ItemPlacementComponent caller, notnull IEntity item, bool success, bool equipNext);
254
255 //------------------------------------------------------------------------------------------------
256
258 //! \param[in] caller component which called this method
259 //! \param[in] placedItem
260 //! \param[in] autoEquipNext bool value representing player settings for automatic equipping of next place
261 //! \return true if default mechanism should not be used, otherwise false
262 bool OverrideAutoEquipMechanism(out ScriptedInventoryOperationCallback callBackHolder, notnull SCR_ItemPlacementComponent caller, IEntity placedItem, bool autoEquipNext);
263
264 //------------------------------------------------------------------------------------------------
265 //! \return
267 {
269 if (!data)
270 return GetOwner().GetVObject();
271
272 if (data.GetPreviewObjectResource().IsEmpty())
273 return GetOwner().GetVObject();
274
275 Resource resource = Resource.Load(data.GetPreviewObjectResource());
276 if (!resource.IsValid())
277 return GetOwner().GetVObject();
278
279 BaseResourceObject resourceObject = resource.GetResource();
280 if (!resourceObject)
281 return GetOwner().GetVObject();
282
283 return resourceObject.ToVObject();
284 }
285
286 //------------------------------------------------------------------------------------------------
289 {
290 SCR_PlaceableItemComponentClass data = SCR_PlaceableItemComponentClass.Cast(GetComponentData(GetOwner()));
291 if (!data)
292 return false;
293
294 return data.CanAttachToDynamicObject();
295 }
296
297 //------------------------------------------------------------------------------------------------
299 EPhysicsLayerDefs GetIgnoredPhysicsLayers()
300 {
301 SCR_PlaceableItemComponentClass data = SCR_PlaceableItemComponentClass.Cast(GetComponentData(GetOwner()));
302 if (!data)
303 return 0;
304
305 return data.GetIgnoredPhysicsLayers();
306 }
307
308 //------------------------------------------------------------------------------------------------
310 int GetIgnoredComponents(notnull out array<typename> outIgnoredComponents)
311 {
312 SCR_PlaceableItemComponentClass data = SCR_PlaceableItemComponentClass.Cast(GetComponentData(GetOwner()));
313 if (!data)
314 return 0;
315
316 return data.GetIgnoredComponents(outIgnoredComponents);
317 }
318
319 //------------------------------------------------------------------------------------------------
320 protected override void EOnInit(IEntity owner)
321 {
323 if (!data)
324 return;
325
326 data.ValidateIgnoredComponents();
327 }
328
329 //------------------------------------------------------------------------------------------------
330 override void OnPostInit(IEntity owner)
331 {
332 SetEventMask(owner, EntityEvent.INIT);
333 }
334
335 //------------------------------------------------------------------------------------------------
338 {
339 SCR_PlaceableItemComponentClass data = SCR_PlaceableItemComponentClass.Cast(GetComponentData(GetOwner()));
340 if (!data)
342
343 return data.GetDistanceMeasurementMethod();
344 }
345
346 //------------------------------------------------------------------------------------------------
351 static float GetDistanceFromCharacter(notnull ChimeraCharacter char, vector destination, SCR_ECharacterDistanceMeasurementMethod method = SCR_ECharacterDistanceMeasurementMethod.FROM_EYES)
352 {
353 vector pos;
354 switch (method)
355 {
357 {
358 pos = char.GetOrigin();
359 break;
360 }
361
362 case (SCR_ECharacterDistanceMeasurementMethod.FROM_CENTER_OF_MASS):
363 {
364 pos = char.AimingPosition(); //Physics cannot be used for characters
365 break;
366 }
367
368 default: //SCR_ECharacterDistanceMeasurementMethod.FROM_EYES
369 {
370 pos = char.EyePosition();
371 break;
372 }
373 }
374
375 return vector.Distance(pos, destination);
376 }
377
378 //------------------------------------------------------------------------------------------------
379 protected override bool RplSave(ScriptBitWriter writer)
380 {
381 RplId parentId = RplId.Invalid();
382 int nodeId = -1;
384 if (placeableIIC)
385 {
386 parentId = placeableIIC.GetParentRplId();
387 nodeId = placeableIIC.GetParentNodeId();
388 }
389 writer.WriteRplId(parentId);
390 if (parentId.IsValid())
391 writer.WriteInt(nodeId);
392
393 return super.RplSave(writer);
394 }
395
396 //------------------------------------------------------------------------------------------------
397 protected override bool RplLoad(ScriptBitReader reader)
398 {
399 RplId parentId = RplId.Invalid();
400 reader.ReadRplId(parentId);
401 if (parentId.IsValid())
402 {
403 int nodeId = -1;
404 reader.ReadInt(nodeId);
405
407 if (placeableIIC)
408 placeableIIC.SetNewParent(parentId, nodeId);
409 }
410
411 return super.RplLoad(reader);
412 }
413}
ENotification
void OverridePreviewTransform(notnull SCR_ItemPlacementComponent caller, inout vector transform[4])
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
override bool OverrideIsSurfaceValid(notnull SCR_ItemPlacementComponent caller, out ENotification cantPlaceReason, IEntity surfaceEnt, vector worldPosition, vector surfaceNorm, int nodeIndex, int colliderIndex, SurfaceProperties surfaceProps, string surfaceMaterial, string colliderName)
override bool OverrideAutoEquipMechanism(out ScriptedInventoryOperationCallback callBackHolder, notnull SCR_ItemPlacementComponent caller, IEntity placedItem, bool autoEquipNext)
override bool OverrideSpaceValidation(notnull SCR_ItemPlacementComponent caller, inout vector transform[4], out ENotification cantPlaceReason)
override bool OverrideStartPlaceAction(notnull SCR_ItemPlacementComponent caller, out bool skipItemUsage=false)
override bool OverrideOnPlacingEnded(notnull SCR_ItemPlacementComponent caller)
override bool GetForwardAwayFromPlayer()
override void OverrideAfterItemPlaced(notnull SCR_ItemPlacementComponent caller, notnull IEntity item, bool success, bool equipNext)
SCR_EPlacementType
Get all prefabs that have the spawner data
void SCR_ItemPlacementComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_ECharacterDistanceMeasurementMethod GetDistanceMeasurementMethod()
Returns preferred Measurement method.
SCR_PlaceableItemComponentClass ScriptComponentClass GetPlacementType()
bool GetAttachPlacedItemToTheSurfaceEntity()
bool CanAttachToDynamicObject()
Returns true if it should be possible to attach this object to dynamic object like f....
EPhysicsLayerDefs GetIgnoredPhysicsLayers()
Returns physics layer mask that can be used to determin which layers should be ignored.
VObject GetPreviewVobject()
bool GetCanBeForcedPlaced()
float GetMaxPlacementDistance()
int GetIgnoredComponents(notnull out array< typename > outIgnoredComponents)
Returns physics layer mask that can be used to determin which layers should be ignored.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external GenericComponent FindComponent(typename typeName)
proto external VObject GetVObject()
Returns visual object set to this Entity. No reference is added.
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Replication item identifier.
Definition RplId.c:14
void SetNewParent(RplId parentId=RplId.Invalid(), int nodeId=-1)
bool CanAttachToDynamicObject()
Returns true if it should be possible to attach this object to dynamic object like f....
int GetIgnoredComponents(notnull out array< typename > outIgnoredComponents)
Returns physics layer mask that can be used to determin which layers should be ignored.
SCR_ECharacterDistanceMeasurementMethod m_eMeasurementMethod
void ValidateIgnoredComponents()
Removes unwanted types from ignored components list.
EPhysicsLayerDefs GetIgnoredPhysicsLayers()
Returns physics layer mask that can be used to determin which layers should be ignored.
SCR_ECharacterDistanceMeasurementMethod GetDistanceMeasurementMethod()
Returns preferred Measurement method.
proto external GenericEntity GetOwner()
Get owner entity.
void EOnInit(IEntity owner)
bool RplLoad(ScriptBitReader reader)
bool RplSave(ScriptBitWriter writer)
Visual object.
Definition VObject.c:14
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14