Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FollowGroupCommand.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
4{
5 //------------------------------------------------------------------------------------------------
6 override bool Execute(IEntity cursorTarget, IEntity target, vector targetPosition, int playerID, bool isClient)
7 {
8 if (!m_sWaypointPrefab || !target || !targetPosition)
9 return false;
10
11 if (isClient)
12 {
13 //place to place a logic that would be executed for other players
14 return true;
15 }
16
17 SCR_AIGroup slaveGroup = SCR_AIGroup.Cast(target);
18 if (!slaveGroup)
19 return false;
20
21 Resource waypointPrefab = Resource.Load(GetWaypointPrefab());
22 if (!waypointPrefab.IsValid())
23 return false;
24
25 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerID);
26 if (!playerController)
27 return false;
28 IEntity controlledEntity = playerController.GetControlledEntity();
29 if (!controlledEntity)
30 return false;
31
33 params.TransformMode = ETransformMode.WORLD;
34 params.Transform[3] = controlledEntity.GetOrigin();
35
36 CheckPreviousWaypoints(slaveGroup);
37
38 // Hotfix: teleport group to leader, otherwise if group is very split up, bots will try to regroup somewhere in the middle, far away
39 vector targetTransform[4];
40 controlledEntity.GetTransform(targetTransform);
41 slaveGroup.SetTransform(targetTransform);
42 slaveGroup.Update();
43
44 // Crucial part about follow waypoint: we must set entity so it knows who to follow
45 // Also it is of SCR_EntityWaypoint class, not SCR_AIWaypoint.
46 SCR_EntityWaypoint wp = SCR_EntityWaypoint.Cast(GetGame().SpawnEntityPrefabLocal(waypointPrefab, null, params));
47 if (!wp)
48 return false;
49 wp.SetEntity(controlledEntity);
50
52 wp.SetPriorityLevel(SCR_AIActionBase.PRIORITY_LEVEL_PLAYER);
53 slaveGroup.AddWaypoint(wp);
54
55 AIGroupMovementComponent slaveGroupMovementComp = AIGroupMovementComponent.Cast(slaveGroup.FindComponent(AIGroupMovementComponent));
56 if (slaveGroupMovementComp)
57 slaveGroupMovementComp.SetFormationDisplacement(1);
58
59 return true;
60 }
61}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
proto external vector GetOrigin()
proto external void GetTransform(out vector mat[])
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void CheckPreviousWaypoints(SCR_AIGroup slaveGroup)
void EntitySpawnParams()
Definition gameLib.c:130