Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseDeployableInventoryItemComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/DeployableItems", description: "")]
3{
4 // Setup
5 [Attribute(uiwidget: UIWidgets.ResourcePickerThumbnail, desc: "Prefab which will be spawned when this item is deployed", params: "et", category: "Setup")]
7
8 [Attribute(defvalue: "1", category: "General")]
9 protected bool m_bEnableSounds;
10
11 [Attribute(desc: "Should this entity be deleted when replacement prefab is destroyed.")]
12 protected bool m_bDeleteWhenDestroyed;
13
14 //------------------------------------------------------------------------------------------------
16 {
18 }
19
20 //------------------------------------------------------------------------------------------------
22 {
24 }
25
26 //------------------------------------------------------------------------------------------------
31}
32
35typedef ScriptInvokerBase<DeployableStateChanged> SCR_DeployableItemState;
36
39{
40 [RplProp(onRplName: "OnRplDeployed")]
41 protected bool m_bIsDeployed;
42
45
46 protected RplComponent m_RplComponent;
47
48 protected bool m_bIsDeploying;
49
50 [RplProp()]
51 protected int m_iItemOwnerID;
52
54
55 protected bool m_bWasDeployed;
57
58 //------------------------------------------------------------------------------------------------
59 void SetDeploying(bool isDeploying)
60 {
61 m_bIsDeploying = isDeploying;
62 }
63
64 //------------------------------------------------------------------------------------------------
66 {
67 return m_bIsDeploying;
68 }
69
70 //------------------------------------------------------------------------------------------------
78
79 //------------------------------------------------------------------------------------------------
82 {
83 Dismantle(instigator);
84
86 if (!data)
87 return;
88
89 if (data.IsDeletedWhenDestroyed())//delay entity deltion to ensure that rpc calls will be able to complete
90 GetGame().GetCallqueue().CallLater(RplComponent.DeleteRplEntity, param1: GetOwner(), param2: false);
91 }
92
93 //------------------------------------------------------------------------------------------------
94 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
95 protected void RPC_SetTransformBroadcast(vector transform[4])
96 {
97 GetOwner().SetTransform(transform);
98 GetOwner().Update(); // force update to ensure that bounding box covers this entity even after it was transformed
99 }
100
101 //------------------------------------------------------------------------------------------------
102 [RplRpc(RplChannel.Unreliable, RplRcver.Broadcast)]
103 protected void RPC_PlaySoundOnDeployBroadcast(bool deploy)
104 {
105 const IEntity owner = GetOwner();
106
108 if (soundComp)
109 {
110 if (deploy)
111 soundComp.SoundEvent(SCR_SoundEvent.SOUND_DEPLOY);
112 else
113 soundComp.SoundEvent(SCR_SoundEvent.SOUND_UNDEPLOY);
114
115 return;
116 }
117
118 if (deploy)
119 SCR_SoundManagerModule.CreateAndPlayAudioSource(owner, SCR_SoundEvent.SOUND_DEPLOY);
120 else
121 SCR_SoundManagerModule.CreateAndPlayAudioSource(owner, SCR_SoundEvent.SOUND_UNDEPLOY);
122 }
123
124 //------------------------------------------------------------------------------------------------
127 void Deploy(IEntity userEntity = null, bool reload = false)
128 {
129 if (!m_RplComponent || m_RplComponent.IsProxy())
130 return;
131
132 if (m_bIsDeployed)
133 return;
134
135 // transform containing information about the position where replacement entity is going to be spawned
136 vector transform[4];
137 const IEntity owner = GetOwner();
138 const World world = owner.GetWorld();
139 const TraceParam param = new TraceParam();
140 const array<IEntity> ignoredEntities = {owner, userEntity};
141 param.ExcludeArray = ignoredEntities;
142 param.LayerMask = EPhysicsLayerPresets.Projectile; // to prevent entites from being deployed on leaves
143
144 // +10cm buffer to prevent it from being deployed inside other objects
145 SCR_TerrainHelper.GetTerrainBasis(owner.GetOrigin() + vector.Up * 0.1, transform, world, false, param);
146
148
150 params.Transform = transform;
151 params.TransformMode = ETransformMode.WORLD;
152
154 if (!data)
155 return;
156
157 Resource resource = Resource.Load(data.GetReplacementPrefab());
158 if (!resource.IsValid())
159 return;
160
161 m_ReplacementEntity = GetGame().SpawnEntityPrefab(resource, world, params);
163 return;
164
166 if (!replacementComp)
167 return;
168
169 vector compositionTransform[4], combinedTransform[4];
170 replacementComp.GetItemTransform(compositionTransform);
171 Math3D.MatrixMultiply4(transform, compositionTransform, combinedTransform);
172
173 RPC_SetTransformBroadcast(combinedTransform);
174 Rpc(RPC_SetTransformBroadcast, combinedTransform);
175
176 replacementComp.GetOnCompositionDestroyed().Insert(OnCompositionDestroyed);
177
178 m_bIsDeployed = true;
179 SetItemOwner(GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(userEntity));
180 Replication.BumpMe();
181
182 if (data.IsSoundEnabled() && !reload)
183 {
186 }
187
189 if (garbageSystem)
190 garbageSystem.Withdraw(owner);
191
194 }
195
196 //------------------------------------------------------------------------------------------------
199 void Dismantle(IEntity userEntity = null, bool reload = false)
200 {
201 if (!m_RplComponent || m_RplComponent.IsProxy())
202 return;
203
204 if (!m_bIsDeployed)
205 return;
206
208 {
209 RplComponent rplComp = RplComponent.Cast(m_ReplacementEntity.FindComponent(RplComponent));
210 if (!rplComp)
211 return;
212
213 rplComp.DeleteRplEntity(m_ReplacementEntity, false);
214 }
215
218
219 m_bIsDeployed = false;
220 m_iItemOwnerID = 0;
221 Replication.BumpMe();
222
224 if (data && data.IsSoundEnabled() && !reload)
225 {
228 }
229
231 if (garbageSystem)
232 garbageSystem.Insert(GetOwner());
233
236 }
237
238 //------------------------------------------------------------------------------------------------
239 void SetItemOwner(int playerId)
240 {
241 m_iItemOwnerID = playerId;
242 }
243
244 //------------------------------------------------------------------------------------------------
246 void Reload()
247 {
248 if (!m_RplComponent || m_RplComponent.IsProxy())
249 return;
250
251 if (!m_bIsDeployed)
252 return;
253
254 IEntity ownerEntity = GetGame().GetPlayerManager().GetPlayerControlledEntity(m_iItemOwnerID);
255 Dismantle(null, true);
256 Deploy(ownerEntity, true);
257 }
258
259 //------------------------------------------------------------------------------------------------
261 protected void OnRplDeployed();
262
263 //------------------------------------------------------------------------------------------------
267 bool CanDeployBeShown(notnull IEntity userEntity)
268 {
269 return !m_bIsDeployed;
270 }
271
272 //------------------------------------------------------------------------------------------------
276 bool CanDismantleBeShown(notnull IEntity userEntity)
277 {
278 return m_bIsDeployed;
279 }
280
281 //------------------------------------------------------------------------------------------------
285 {
286 return m_bIsDeployed;
287 }
288
289 //------------------------------------------------------------------------------------------------
292 {
293 return m_iItemOwnerID;
294 }
295
296 //------------------------------------------------------------------------------------------------
297 override void OnPostInit(IEntity owner)
298 {
299 super.OnPostInit(owner);
301 m_RplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
302 }
303
304 //------------------------------------------------------------------------------------------------
305 override void OnDelete(IEntity owner)
306 {
307 super.OnDelete(owner);
308
310 m_OnDeployedStateChanged.Invoke(false, this);
311
312 if (!m_bIsDeployed || !m_RplComponent || m_RplComponent.IsProxy())
313 return;
314
315 if (!m_ReplacementEntity || m_ReplacementEntity.IsDeleted())
316 return;
317
318 RplComponent rplComp = RplComponent.Cast(m_ReplacementEntity.FindComponent(RplComponent));
319 if (!rplComp)
320 return;
321
322 rplComp.DeleteRplEntity(m_ReplacementEntity, false);
323 }
324}
ArmaReforgerScripted GetGame()
Definition game.c:1398
ResourceName m_sReplacementPrefab
ScriptInvokerBase< DeployableStateChanged > SCR_DeployableItemState
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Get all prefabs that have the spawner data
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external GenericComponent FindComponent(typename typeName)
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external int Update()
proto external BaseWorld GetWorld()
proto external bool SetTransform(vector mat[4])
Main replication API.
Definition Replication.c:14
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Base class which all deployable inventory items inherit from.
void OnCompositionDestroyed(IEntity instigator)
Callback method that is triggered when composition is destroyed.
void Deploy(IEntity userEntity=null, bool reload=false)
void Dismantle(IEntity userEntity=null, bool reload=false)
void Reload()
Dismantle and redeploy to update settings.
Holds Position of where the deployable item will be attached to.
Script entry for garbage system modding.
static SCR_GarbageSystem GetByEntityWorld(IEntity entity)
static bool GetTerrainBasis(vector pos, out vector result[4], BaseWorld world=null, bool noUnderwater=false, TraceParam trace=null)
proto external GenericEntity GetOwner()
Get owner entity.
Definition World.c:16
void EntitySpawnParams()
Definition gameLib.c:130
EPhysicsLayerPresets
Enum is filled by C++ by data in project config PhysicsSettings.LayerPresets.
Definition gameLib.c:19
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
T2 param2
Definition tuple.c:92
Tuple param1