Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MineAddFlagAction.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  [Attribute("0 0 0.19")]
5  protected vector m_vFlagOffset;
6 
7  //------------------------------------------------------------------------------------------------
8  IEntity FindFlagInInventory(IEntity user)
9  {
11  if (!storageManager)
12  return null;
13 
14  array<typename> components = {};
15  components.Insert(SCR_MineFlagComponent);
16  return storageManager.FindItemWithComponents(components, EStoragePurpose.PURPOSE_ANY);
17  }
18 
19  //------------------------------------------------------------------------------------------------
20  void PlaceFlag(IEntity user, IEntity owner)
21  {
22  RplComponent userRplComponent = RplComponent.Cast(user.FindComponent(RplComponent));
23  if (!userRplComponent)
24  return;
25 
27  if (!storageManager)
28  return;
29 
30  SCR_CharacterInventoryStorageComponent storage = SCR_CharacterInventoryStorageComponent.Cast(user.FindComponent(SCR_CharacterInventoryStorageComponent));
31  if (!storage)
32  return;
33 
34  IEntity flag = FindFlagInInventory(user);
35 
36  if (!flag)
37  return;
38 
39  SCR_PlaceableInventoryItemComponent itemComponent = SCR_PlaceableInventoryItemComponent.Cast(flag.FindComponent(SCR_PlaceableInventoryItemComponent));
40 
41  RplComponent rplComponent = RplComponent.Cast(flag.FindComponent(RplComponent));
42  if (rplComponent && !rplComponent.IsProxy())
43  {
44  vector mat[4];
45  owner.GetTransform(mat);
46  itemComponent.PlaceItem(mat[0], mat[1], mat[2], mat[3] + m_vFlagOffset);
47  }
48 
49  SCR_SoundManagerEntity soundManagerEntity = GetGame().GetSoundManagerEntity();
50  if (soundManagerEntity)
51  soundManagerEntity.CreateAndPlayAudioSource(flag, "SOUND_MINEFLAG_PLACE");
52 
53  if (userRplComponent.IsOwner())
54  storageManager.TryRemoveItemFromStorage(flag, itemComponent.GetParentSlot().GetStorage());
55 
56  SCR_MineWeaponComponent mine = SCR_MineWeaponComponent.Cast(owner.FindComponent(SCR_MineWeaponComponent));
57  if (mine)
58  mine.SetFlag(flag);
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  override event void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
63  {
64  PlaceFlag(pUserEntity, pOwnerEntity);
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  override bool CanBeShownScript(IEntity user)
69  {
70  SCR_MineWeaponComponent mine = SCR_MineWeaponComponent.Cast(GetOwner().FindComponent(SCR_MineWeaponComponent));
71  if (!mine || mine.IsFlagged())
72  return false;
73 
74  SCR_PressureTriggerComponent mineTriggerComponent = SCR_PressureTriggerComponent.Cast(GetOwner().FindComponent(SCR_PressureTriggerComponent));
75  if (!mineTriggerComponent || !mineTriggerComponent.IsActivated())
76  return false;
77 
78  SCR_MineAwarenessComponent mineAwarenessComponent = SCR_MineAwarenessComponent.GetLocalInstance();
79  if (!mineAwarenessComponent)
80  return super.CanBeShownScript(user);
81 
82  if (!mineAwarenessComponent.IsDetected(GetOwner()) || !FindFlagInInventory(user))
83  return false;
84 
85  return super.CanBeShownScript(user);
86  }
87 
88 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ScriptedUserAction
Definition: ScriptedUserAction.c:12
SCR_SoundManagerEntity
Definition: SCR_SoundManagerEntity.c:17
SCR_MineAddFlagAction
Definition: SCR_MineAddFlagAction.c:2
InventoryStorageManagerComponent
Definition: InventoryStorageManagerComponent.c:12
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_MineAwarenessComponent
Definition: SCR_MineAwarenessComponent.c:12
EStoragePurpose
EStoragePurpose
Definition: EStoragePurpose.c:12