Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIGetSidePosition.c
Go to the documentation of this file.
2{
3 static const string PORT_ENEMY = "Enemy";
4 static const string PORT_ENEMY_POSITION = "EnemyPosition";
5 static const string PORT_KEEP_SIDE = "KeepSide";
6 static const string PORT_POSITION = "PositionOut";
7
8
9 [Attribute("4", UIWidgets.EditBox, "Distance from origin")]
10 private float m_fDistance;
11
12 private int m_iSide = 0;
13 private IEntity m_OwnerEntity;
14
15 //------------------------------------------------------------------------------------------------
16 override void OnEnter(AIAgent owner)
17 {
18 if (GetVariableType(false, PORT_POSITION) != vector)
19 {
20 NodeError(this, owner, PORT_POSITION + " has to be vector");
21 }
22 m_OwnerEntity = owner.GetControlledEntity();
23 if (!m_OwnerEntity)
24 {
25 NodeError(this, owner, "Owner must be a character!");
26 }
27 }
28
29 //------------------------------------------------------------------------------------------------
30 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
31 {
32 vector direction, enemyPos, origin = m_OwnerEntity.GetOrigin();
34 bool keepSide;
35 if (!GetVariableIn(PORT_KEEP_SIDE, keepSide) || !keepSide) // if parameter keepSide == true, it will not change side from previous run
36 m_iSide = Math.RandomInt(0,2);
37 // get direction of enemy
38 if (GetVariableIn(PORT_ENEMY, enemy))
39 {
40 direction = vector.Direction(enemy.GetOrigin(), origin);
41 direction.Normalize();
42 }
43 else if (GetVariableIn(PORT_ENEMY_POSITION, enemyPos))
44 {
45 direction = vector.Direction(enemyPos, origin);
46 direction.Normalize();
47
48 }
49 else
50 direction = m_OwnerEntity.GetYawPitchRoll().AnglesToVector(); // gets normalized forward vector of m_OwnerEntity
51
52 // make perpendicular vector
53 if (m_iSide == 0)
54 {
55 float x = direction[0];
56 direction[0] = direction[2];
57 direction[2] = -x;
58 }
59 else
60 {
61 float x = direction[0];
62 direction[0] = -direction[2];
63 direction[2] = x;
64 }
65
66 origin += direction * m_fDistance;
67
68 SetVariableOut(PORT_POSITION, origin);
69
70 return ENodeResult.SUCCESS;
71 }
72
73 //------------------------------------------------------------------------------------------------
74 static override bool VisibleInPalette()
75 {
76 return true;
77 }
78
79 //------------------------------------------------------------------------------------------------
80 static override protected string GetOnHoverDescription()
81 {
82 return "Returns position from owner entity that is either on random side of the direction towards enemy pos or the keeps the same side as previously if KeepSide is true";
83 }
84
85 //------------------------------------------------------------------------------------------------
86 protected static ref TStringArray s_aVarsIn = {
87 PORT_ENEMY,
88 PORT_ENEMY_POSITION,
89 PORT_KEEP_SIDE
90 };
92 {
93 return s_aVarsIn;
94 }
95
96 //------------------------------------------------------------------------------------------------
97 protected static ref TStringArray s_aVarsOut = {
98 PORT_POSITION
99 };
101 {
102 return s_aVarsOut;
103 }
104};
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition NodeError.c:3
when task is activated by player or by killing enemy
vector direction
Definition Math.c:13
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
bool VisibleInPalette()
proto external GetVariableType(bool inputPort, string name)
override TStringArray GetVariablesOut()
static ref TStringArray s_aVarsIn
override TStringArray GetVariablesIn()
static ref TStringArray s_aVarsOut
ENodeResult
Definition ENodeResult.c:13
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385