Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ActivateMineUserAction.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  [Attribute("30", "Arming delay in seconds.")]
5  protected float m_fArmingDelay;
6 
7  [Attribute("10", "How long the user action will be shown as inactive after starting arming.")]
8  protected float m_fArmingProtectionTime;
9 
10  protected InventoryItemComponent m_Item;
11 
12  protected bool m_bCanArm = true;
13 
14  //------------------------------------------------------------------------------------------------
15  void OrientToForward(vector forward, vector mat[4])
16  {
17  vector origin = mat[3];
18  vector basis[4];
19  forward = -forward;
20  Math3D.AnglesToMatrix(Vector(forward.VectorToAngles()[0], 0, 0), basis);
21  Math3D.MatrixMultiply3(mat, basis, mat);
22  mat[3] = origin;
23  }
24 
25  //------------------------------------------------------------------------------------------------
26  void AllowArming()
27  {
28  m_bCanArm = true;
29  }
30 
31  //------------------------------------------------------------------------------------------------
32  vector GetGroundNormal(notnull IEntity owner)
33  {
34  vector pos = owner.GetOrigin();
35  vector normal = SCR_TerrainHelper.GetTerrainNormal(pos, owner.GetWorld());
36  if (normal != vector.Zero)
37  return normal;
38  else
39  return vector.Up;
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  protected bool CheckAngle(vector up)
44  {
45  if (vector.Dot(up, vector.Up) < 0.5) // Rject based on the angle of placement (the maximum should be dictated by item settings)
46  return false;
47 
48  return true;
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  protected void SnapToGround(IEntity user, out vector normal)
53  {
54  IEntity owner = GetOwner();
55  vector mat[4];
56  owner.GetTransform(mat);
57 
58  SCR_PlaceableInventoryItemComponent item = SCR_PlaceableInventoryItemComponent.Cast(owner.FindComponent(SCR_PlaceableInventoryItemComponent));
59  if (item)
60  item.SnapToGround(normal, {user}, startOffset: mat[1] * 0.1, direction: -mat[1]);
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  override event void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
65  {
66  m_bCanArm = false;
67  GetGame().GetCallqueue().CallLater(AllowArming, 1000 * m_fArmingProtectionTime);
68 
69  vector matUser[4], mat[4];
70  pUserEntity.GetTransform(matUser);
71 
72  vector normal = vector.Zero;
73  SnapToGround(pUserEntity, normal);
74 
75  pOwnerEntity.GetTransform(mat);
76  SCR_EntityHelper.OrientUpToVector(normal, mat);
77  OrientToForward(matUser[2], mat);
78  pOwnerEntity.SetTransform(mat);
79 
80  ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
81 
82  if (!character)
83  {
84  Print("Non-ChimeraCharacter user tried using SCR_ActivateMineUserAction!", LogLevel.WARNING);
85  return;
86  }
87 
88  SCR_PressureTriggerComponent pressureTrigger = SCR_PressureTriggerComponent.Cast(pOwnerEntity.FindComponent(SCR_PressureTriggerComponent));
89  if (!pressureTrigger)
90  return;
91 
92  pressureTrigger.SetUser(pUserEntity);
93 
94  CharacterControllerComponent charController = character.GetCharacterController();
95  if (charController)
96  {
97  CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
98  int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
99  vector charWorldMat[4];
100  pUserEntity.GetWorldTransform(charWorldMat);
101  charWorldMat[3] = pOwnerEntity.GetOrigin();
102  PointInfo ptWS = new PointInfo();
103  ptWS.Set(null, "", charWorldMat);
104 
106  params.SetEntity(pOwnerEntity);
107  params.SetAllowMovementDuringAction(false);
108  params.SetKeepInHandAfterSuccess(true);
109  params.SetCommandID(itemActionId);
110  params.SetCommandIntArg(3);
111  params.SetCommandFloatArg(0.0);
112  params.SetMaxAnimLength(15.0);
113  params.SetAlignmentPoint(ptWS);
114 
115  charController.TryUseItemOverrideParams(params);
116  }
117 
118  pOwnerEntity.GetTransform(mat);
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  protected bool IsUnderWater()
123  {
124  return SCR_WorldTools.IsObjectUnderwater(GetOwner());
125  }
126 
127  //------------------------------------------------------------------------------------------------
128  override bool CanBePerformedScript(IEntity user)
129  {
130  vector mat[4];
131  GetOwner().GetTransform(mat);
132 
133  if (IsUnderWater() || !CheckAngle(mat[1]))
134  return false;
135 
136  if (Math.AbsFloat(mat[3][1] - user.GetOrigin()[1]) > 0.4)
137  return false;
138 
139  return m_bCanArm;
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
144  {
145  m_Item = InventoryItemComponent.Cast(pOwnerEntity.FindComponent(InventoryItemComponent));
146  }
147 
148  //------------------------------------------------------------------------------------------------
149  override bool CanBeShownScript(IEntity user)
150  {
151  if (m_Item == null || m_Item.GetParentSlot() != null || m_Item.IsLocked())
152  return false;
153 
154  SCR_PressureTriggerComponent mineTriggerComponent = SCR_PressureTriggerComponent.Cast(GetOwner().FindComponent(SCR_PressureTriggerComponent));
155  if (!mineTriggerComponent)
156  return false;
157 
158  if (mineTriggerComponent.IsActivated())
159  return false;
160 
161  return super.CanBeShownScript(user);
162  }
163 };
SCR_TerrainHelper
Definition: SCR_TerrainHelper.c:1
direction
vector direction
Definition: SCR_DestructibleTreeV2.c:31
SCR_EntityHelper
Definition: SCR_EntityHelper.c:1
m_Item
NewsFeedItem m_Item
Definition: SCR_NewsSubMenu.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ItemUseParameters
Definition: ItemUseParameters.c:15
ScriptedUserAction
Definition: ScriptedUserAction.c:12
SCR_WorldTools
Definition: SCR_WorldTools.c:1
SCR_ActivateMineUserAction
Definition: SCR_ActivateMineUserAction.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
InventoryItemComponent
Definition: InventoryItemComponent.c:12
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24