Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PatrolGroupCommand.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
4{
5 static const ResourceName cycleWPResource = "{35BD6541CBB8AC08}Prefabs/AI/Waypoints/AIWaypoint_Cycle.et";
6
7 //------------------------------------------------------------------------------------------------
8 override bool Execute(IEntity cursorTarget, IEntity target, vector targetPosition, int playerID, bool isClient)
9 {
10 if (isClient && playerID == SCR_PlayerController.GetLocalPlayerId())
11 return true;
12
13 if (!target || !targetPosition)
14 return false;
15
16 return Patrol(target, targetPosition, playerID);
17 }
18
19 //------------------------------------------------------------------------------------------------
20 bool Patrol(IEntity target, vector targetPosition, int playerID)
21 {
22 SCR_AIGroup slaveGroup = SCR_AIGroup.Cast(target);
23 if (!slaveGroup)
24 return false;
25
26 Resource waypointPrefab = Resource.Load(GetWaypointPrefab());
27 if (!waypointPrefab.IsValid())
28 return false;
29
30 Resource cycleWPPrefab = Resource.Load(cycleWPResource);
31 if (!cycleWPPrefab.IsValid())
32 return false;
33
34 SCR_PlayerController orderingPlayerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(playerID));
35 if (!orderingPlayerController)
36 return false;
37
38 IEntity playerEntity = orderingPlayerController.GetControlledEntity();
39 if (!playerEntity)
40 return false;
41
42 CheckPreviousWaypoints(slaveGroup);
43
45 params.TransformMode = ETransformMode.WORLD;
46 params.Transform[3] = playerEntity.GetOrigin();
47
48 array<AIWaypoint> waypoints = {};
49
50 PlayerController controller = GetGame().GetPlayerManager().GetPlayerController(playerID);
51 if (!controller)
52 return false;
53
54 SCR_PlayerControllerCommandingComponent commandingComp = SCR_PlayerControllerCommandingComponent.Cast(controller.FindComponent(SCR_PlayerControllerCommandingComponent));
55 if (!commandingComp)
56 return false;
57
58 waypoints.Insert(SCR_AIWaypoint.Cast(GetGame().SpawnEntityPrefabLocal(waypointPrefab, null, params)));
59 waypoints[0].SetCompletionRadius(m_fCompletionRadius);
60 commandingComp.DrawWaypointVisualization(playerEntity.GetOrigin(), m_fCompletionRadius);
61
62 params.Transform[3] = targetPosition;
63 waypoints.Insert(SCR_AIWaypoint.Cast(GetGame().SpawnEntityPrefabLocal(waypointPrefab, null, params)));
64 waypoints[1].SetCompletionRadius(m_fCompletionRadius);
65 commandingComp.DrawWaypointVisualization(targetPosition, m_fCompletionRadius, false);
66
67 AIWaypointCycle waypointCycle = AIWaypointCycle.Cast(GetGame().SpawnEntityPrefabLocal(cycleWPPrefab, null, params));
68
69 if (!waypointCycle)
70 return false;
71
72 waypointCycle.SetWaypoints(waypoints);
73
74 slaveGroup.AddWaypoint(waypointCycle);
75
76 return true;
77 }
78}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
proto external vector GetOrigin()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
void CheckPreviousWaypoints(SCR_AIGroup slaveGroup)
void EntitySpawnParams()
Definition gameLib.c:130
proto external PlayerController GetPlayerController()