Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AISetPosition.c
Go to the documentation of this file.
1 class SCR_AISetPosition : AITaskScripted
2 {
3  protected static const string TARGET_INFO_PORT = "TargetInfo";
4 
5  protected static const string ENTITY_PORT = "EntitytIn";
6  protected static const string AGENT_PORT = "AgentIn";
7  protected static const string TARGET_PORT = "DestinationIn";
8 
9  protected ref TStringArray s_aVarsIn = {
10  ENTITY_PORT,
11  AGENT_PORT,
12  TARGET_PORT,
13  };
14 
15  CharacterControllerComponent m_charContr;
16 
17  //------------------------------------------------------------------------------------------------------------------------
18  override TStringArray GetVariablesIn() { return s_aVarsIn; }
19 
20  //------------------------------------------------------------------------------------------------------------------------
21  override bool VisibleInPalette() { return true; }
22 
23  //------------------------------------------------------------------------------------------------------------------------
24  override string GetOnHoverDescription() { return "Sets (teleports) entity to target, that can be vector, smartAction or vehicle compartment"; };
25 
26  //------------------------------------------------------------------------------------------------------------------------
27  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
28  {
29  IEntity entityToTeleport;
30  vector positionToTeleport;
31 
32  if(!GetVariableIn(ENTITY_PORT, entityToTeleport))
33  {
34  AIAgent agent;
35 
36  if (!GetVariableIn(AGENT_PORT, agent))
37  return NodeError(this, owner, "Did not provided entity to teleport!");
38  entityToTeleport = agent.GetControlledEntity();
39  }
40 
41  if (!entityToTeleport)
42  return NodeError(this, owner, "Entity is null!");
43 
44  if (GetVariableType(true,TARGET_PORT) == vector)
45  {
46  GetVariableIn(TARGET_PORT, positionToTeleport);
47  }
48  else if (GetVariableType(true,TARGET_PORT) == SCR_AISmartActionComponent)
49  {
50  SCR_AISmartActionComponent SAComponent;
51  vector originOfObject;
52 
53  GetVariableIn(TARGET_PORT, SAComponent);
54  originOfObject = SAComponent.GetOwner().GetOrigin();
55  positionToTeleport = originOfObject + SAComponent.GetActionOffset();
56  }
57  else if (GetVariableType(true,TARGET_PORT).IsInherited(BaseCompartmentSlot))
58  {
59  BaseCompartmentSlot compartmentSlot;
60  CompartmentAccessComponent CAComponent = CompartmentAccessComponent.Cast(entityToTeleport.FindComponent(CompartmentAccessComponent));
61  IEntity vehicle;
62 
63  GetVariableIn(TARGET_PORT, compartmentSlot);
64  vehicle = compartmentSlot.GetOwner();
65  if (!CAComponent || !vehicle)
66  return NodeError(this, owner, "Enity to teleport does not have CompartmentAccessComponent or target is not an Entity!");
67  if (!CAComponent.MoveInVehicle(vehicle, compartmentSlot))
68  {
69 #ifdef AI_DEBUG
70  Print("Teleport to vehicle was not successful!", LogLevel.VERBOSE);
71 #endif
72  if (!m_charContr)
73  {
74  m_charContr = CharacterControllerComponent.Cast(entityToTeleport.FindComponent(CharacterControllerComponent));
75  if (!m_charContr)
76  return NodeError(this, owner, "Enity to teleport does not have CharacterControllerComponent!");
77  }
78 
79  if (m_charContr.IsSwimming())
80  return ENodeResult.FAIL;
81  else if (m_charContr.IsFalling())
82  return ENodeResult.RUNNING;
83  else
84  return ENodeResult.FAIL;
85  }
86  return ENodeResult.SUCCESS;
87  }
88 
89  BaseGameEntity gEntity = BaseGameEntity.Cast(entityToTeleport);
90  vector mat[4];
91  Math3D.MatrixIdentity4(mat);
92  mat[3] = positionToTeleport;
93 
94  gEntity.Teleport(mat); // teleporting entity
95  return ENodeResult.SUCCESS;
96  }
97 
98  //------------------------------------------------------------------------------------------------------------------------
99  override bool CanReturnRunning()
100  {
101  return true;
102  }
103 }
SCR_AISmartActionComponent
Definition: SCR_AISmartActionComponent.c:9
NodeError
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition: NodeError.c:3
IsInherited
bool IsInherited(string factionKey)
Definition: SCR_Faction.c:227
SCR_AISetPosition
Definition: SCR_AISetPosition.c:1