Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PrefabDeleterEntity.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Utility", description: "Delete entities in a certain radius.")]
2class SCR_PrefabDeleterEntityClass : GenericEntityClass
3{
4}
5
10{
11 /*
12 Deletion
13 */
14
15 [Attribute(defvalue: "1", desc: "Delete player entities", category: "Deletion")]
16 protected bool m_bDeletePlayers;
17
18 [Attribute(defvalue: "0", desc: "Only delete entities with a VObjectComponent, e.g a model/particle/etc; otherwise delete everything", category: "Deletion")]
19 protected bool m_bOnlyDeleteVisibleEntities;
20
21 [Attribute(defvalue: "10", uiwidget: UIWidgets.Slider, desc: "Radius in which entities are deleted", params: "0 1000 1", category: "Deletion")]
22 protected float m_fRadius;
23
24 [Attribute(defvalue: "0", uiwidget: UIWidgets.Slider, desc: "[s] Delay before deletion", params: "0 10", precision: 1, category: "Deletion")]
25 protected float m_fDelay;
26
27 protected static ref array<IEntity> s_aFoundEntities = {};
28
29 //------------------------------------------------------------------------------------------------
30 override void EOnInit(IEntity owner)
31 {
32 // authority only
33 RplComponent rplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
34 if (rplComponent && !rplComponent.IsMaster())
35 return;
36
37 // CallLater: delete after first frame to not break init
38 GetGame().GetCallqueue().CallLater(PerformDeletion, m_fDelay * 1000, param1: owner);
39 }
40
41 //------------------------------------------------------------------------------------------------
42 protected void PerformDeletion(IEntity owner)
43 {
45 if (m_bOnlyDeleteVisibleEntities)
46 flags |= EQueryEntitiesFlags.WITH_OBJECT;
47
48 GetWorld().QueryEntitiesBySphere(owner.GetOrigin(), m_fRadius, PerformDeletion_QueryEntitiesCallback, null, flags);
49
50 foreach (IEntity entity : s_aFoundEntities)
51 {
52 if (!entity) // if one saw its parent already deleted
53 continue;
54
55 if (entity.Type() && entity.Type().IsInherited(SCR_PrefabDeleterEntity)) // avoid self and other deleters
56 continue;
57
58 if (vector.Distance(GetOrigin(), entity.GetOrigin()) > m_fRadius) // sphere query works with bboxes; here we get more accurate by origin
59 continue;
60
61 IEntity root = entity.GetRootParent();
62
63 if (!m_bDeletePlayers && EntityUtils.IsPlayer(root))
64 continue;
65
66 RplComponent.DeleteRplEntity(root, false);
67 }
68
69 s_aFoundEntities.Clear();
70
71 RplComponent.DeleteRplEntity(owner, false); // destroy self
72 }
73
74 //------------------------------------------------------------------------------------------------
76 {
77 s_aFoundEntities.Insert(e);
78 return true;
79 }
80
81 //------------------------------------------------------------------------------------------------
82 // constructor
86 {
87 if (m_fRadius <= 0 || !GetGame().InPlayMode())
88 return;
89
91 }
92
93#ifdef WORKBENCH
94
95 //------------------------------------------------------------------------------------------------
96 override int _WB_GetAfterWorldUpdateSpecs(IEntitySource src)
97 {
98 return EEntityFrameUpdateSpecs.CALL_WHEN_ENTITY_VISIBLE | EEntityFrameUpdateSpecs.CALL_WHEN_ENTITY_SELECTED;
99 }
100
101 //------------------------------------------------------------------------------------------------
102 override void _WB_AfterWorldUpdate(float timeSlice)
103 {
104 super._WB_AfterWorldUpdate(timeSlice);
105 if (m_fRadius > 0)
106 Shape.CreateSphere(0x44FFCC00, ShapeFlags.WIREFRAME | ShapeFlags.ONCE | ShapeFlags.TRANSP, GetOrigin(), m_fRadius);
107 }
108
109#endif
110
111}
SCR_EAIThreatSectorFlags flags
ArmaReforgerScripted GetGame()
Definition game.c:1398
params precision
vector GetOrigin()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
bool PerformDeletion_QueryEntitiesCallback(IEntity e)
void PerformDeletion(IEntity owner)
void SCR_PrefabDeleterEntity(IEntitySource src, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
event void _WB_AfterWorldUpdate(float timeSlice)
Called after updating world in Workbench. The entity must be visible in frustum, selected or named....
event int _WB_GetAfterWorldUpdateSpecs(IEntitySource src)
Called after _WB_OnInit or also later when editor needs to know whether _WB_AfterWorldUpdate needs to...
proto external EntityEvent SetEventMask(EntityEvent e)
proto external Managed FindComponent(typename typeName)
void EOnInit(IEntity owner)
proto external vector GetOrigin()
proto external BaseWorld GetWorld()
proto external IEntity GetRootParent()
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
Tuple param1
EQueryEntitiesFlags