calculatePath: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " *\| *([Cc]omments|COMMENTS|Game|[Gg]ame [Nn]ame|Game [Vv]ersion|Game Version \(number surrounded by NO SPACES\)|Multiplayer Arguments \("local" or "global"\)|Multiplayer Effects \("local" or "global"\)|Multiplayer Execution \("serv...)
m (Some wiki formatting)
(22 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Command
{{RV|type=command


| arma3
|game1= arma3
 
|version1= 1.94
|1.94
 
|eff=  |Multiplayer Effects=


|gr1= Object Manipulation
|gr1= Object Manipulation


| Spawns an agent that will execute an AI path calculation and fire the <tt>"PathCalculated"</tt> [[Arma_3:_Event_Handlers#PathCalculated | event handler]]. The vehicle type to simulate could be one of the following presets:
|descr= Spawns an agent that will execute an AI path calculation and fire the {{hl|"PathCalculated"}} [[Arma_3:_Event_Handlers#PathCalculated | event handler]]. The vehicle type to simulate could be one of the following presets:
* <tt>"man"</tt> (will use "C_man_1")
{{Columns|2|
* <tt>"car"</tt> (will use "C_Offroad_01_F")
* {{hl|"man"}} (will use "C_man_1")
* <tt>"tank"</tt> (will use "B_MBT_01_cannon_F")
* {{hl|"car"}} (will use "C_Offroad_01_F")
* <tt>"wheeled_APC"</tt> (will use "B_APC_Tracked_01_rcws_F")
* {{hl|"tank"}} (will use "B_MBT_01_cannon_F")
* <tt>"boat"</tt> (will use "C_Rubberboat")
* {{hl|"wheeled_APC"}} (will use "B_APC_Tracked_01_rcws_F")
* <tt>"plane"</tt> (will use "B_Plane_CAS_01_dynamicLoadout_F")
* {{hl|"boat"}} (will use "C_Rubberboat")
* <tt>"helicopter"</tt> (will use "B_Heli_Light_01_F")
* {{hl|"plane"}} (will use "B_Plane_CAS_01_dynamicLoadout_F")
* {{hl|"helicopter"}} (will use "B_Heli_Light_01_F")
|shrink= y
}}
If the given vehicle type is not one of the above presets, the exact given type is used.
If the given vehicle type is not one of the above presets, the exact given type is used.
{{Important | In order to guarantee that the event handler is added to the result of this command before the path is calculated, use [[isNil]] to run the code in an [[Scheduler#Unscheduled Environment|Unscheduled Environment]]:
{{Feature|important|
<code>[[isNil]] { [[calculatePath]] ["man", "safe", _startPos, _endPos] [[addEventHandler]] ["PathCalculated", { [[hint]] [[str]] [[_this]] }] };</code>}}
In order to guarantee that the event handler is added to the result of this command before the path is calculated, use [[isNil]] to run the code in an [[Scheduler#Unscheduled Environment|Unscheduled Environment]]:
<sqf>isNil { calculatePath ["man", "safe", _startPos, _endPos] addEventHandler ["PathCalculated", { hint str _this }] };</sqf>
}}


|pr= For some unknown reason, the "PathCalculated" Event Handler is fired twice, first with calculated path and second with array consisting of 2 elements, which are identical and are equal to the end point. See '''[[#Examples|Example 3 &amp; 4]]''' for a workaround. |Problems=
|pr= For some unknown reason, the "PathCalculated" Event Handler is fired twice, first with calculated path and second with array consisting of 2 elements, which are identical and are equal to the end point. See '''[[#Examples|Example 3 &amp; 4]]''' for a workaround.


| [[calculatePath]] [type, behaviour, from, to]
|s1= [[calculatePath]] [type, behaviour, from, to]


|p1= type: [[String]] - Vehicle type to simulate (see description)
|p1= type: [[String]] - Vehicle type to simulate (see description)
Line 33: Line 35:
|p4= to: [[Array]] - End position in format [x,y,z]
|p4= to: [[Array]] - End position in format [x,y,z]


| [[Object]] - The agent to [[addEventHandler|add]] the [[Arma 3: Event Handlers#PathCalculated|<tt>"PathCalculated"</tt> Event Handler]] to.
|r1= [[Object]] - The agent to [[addEventHandler|add]] the [[Arma 3: Event Handlers#PathCalculated|{{hl|"PathCalculated"}} Event Handler]] to.


|x1= <code>[[calculatePath]] ["car", "safe", [2150.67,5778.19,0], [2184.11,5802.28,0]]</code>
|x1= <sqf>calculatePath ["car", "safe", [2150.67,5778.19,0], [2184.11,5802.28,0]];</sqf>


|x2= Draws the path from South West to North East of Agia Marina:
|x2= Draws the path from South West to North East of Agia Marina:
<code>([[calculatePath]] ["man","safe",[2832.9,5927.79,0],[3107.46,6036.61,0]]) [[addEventHandler]] ["PathCalculated", {
<sqf>
(calculatePath ["man","safe",[2832.9,5927.79,0],[3107.46,6036.61,0]]) addEventHandler ["PathCalculated", {
{
{
[[private]] _marker = [[createMarker]] ["marker" + [[str]] [[_forEachIndex]], [[_x]]];
private _marker = createMarker ["marker" + str _forEachIndex, _x];
_marker [[setMarkerType]] "mil_dot";
_marker setMarkerType "mil_dot";
_marker [[setMarkerText]] [[str]] [[_forEachIndex]];
_marker setMarkerText str _forEachIndex;
} [[forEach]] ([[_this]] [[select]] 1);
} forEach (_this select 1);
}]</code>
}];
</sqf>


|x3= Alternative usage of [[calculatePath]] functionality that is free of double execution bug (and calculatePath command):
|x3= Alternative usage of [[calculatePath]] functionality that is free of double execution bug (and calculatePath command):
<code>[[private]] _agent = [[createAgent]] [<nowiki/>[[typeOf]] [[player]], [[position]] [[player]], [], 0, "NONE"];  
<sqf>
_agent [[addEventHandler]] ["PathCalculated",
private _agent = createAgent [typeOf player, position player, [], 0, "NONE"];
_agent addEventHandler ["PathCalculated",
{  
{  
{  
{  
[[private]] _marker = [[createMarker]] ["marker" + [[str]] [[_forEachIndex]], [[_x]]];  
private _marker = createMarker ["marker" + str _forEachIndex, _x];
_marker [[setMarkerType]] "mil_dot";  
_marker setMarkerType "mil_dot";
_marker [[setMarkerText]] [[str]] [[_forEachIndex]];  
_marker setMarkerText str _forEachIndex;
}  
}  
[[forEach]] ([[_this]] [[select]] 1);
forEach (_this select 1);
}];
}];
_agent [[setDestination]] [<nowiki/>[[player]] [[getRelPos]] [500, 0], "LEADER PLANNED", [[true]]];</code>
_agent setDestination [player getRelPos [500, 0], "LEADER PLANNED", true];
</sqf>


|x4= Same as above but for a vehicle: <code>[[private]] _agent = [[createAgent]] [<nowiki/>[[typeOf]] [[player]], [[position]] [[player]], [], 0, "NONE"];
|x4= Same as above but for a vehicle:
[[private]] _car = "B_Quadbike_01_F" [[createVehicle]] [[position]] [[player]];
<sqf>
_agent [[moveInDriver]] _car;
private _agent = createAgent [typeOf player, position player, [], 0, "NONE"];
_agent [[addEventHandler]] ["PathCalculated",
private _car = "B_Quadbike_01_F" createVehicle position player;
_agent moveInDriver _car;
_agent addEventHandler ["PathCalculated",
{  
{  
{  
{  
[[private]] _marker = [[createMarker]] ["marker" + [[str]] [[_forEachIndex]], [[_x]]];  
private _marker = createMarker ["marker" + str _forEachIndex, _x];
_marker [[setMarkerType]] "mil_dot";  
_marker setMarkerType "mil_dot";
_marker [[setMarkerText]] [[str]] [[_forEachIndex]];  
_marker setMarkerText str _forEachIndex;
}  
}  
[[forEach]] ([[_this]] [[select]] 1);
forEach (_this select 1);
}];
}];
_agent [[setDestination]] [<nowiki/>[[player]] [[getRelPos]] [500, 0], "LEADER PLANNED", [[true]]];</code>
_agent setDestination [player getRelPos [500, 0], "LEADER PLANNED", true];
</sqf>


| [[setDriveOnPath]], [[setDestination]]
|seealso= [[setDriveOnPath]] [[setDestination]]
}}
}}


<dl class="command_description">
{{Note
<!-- BEGIN Note Section -->
|user= Tankbuster
 
|timestamp= 20190606102800
<dd class="notedate">Posted on July 6, 2019 - 10:28 (UTC)</dd>
|text= When using this command to get the predicted path of vehicles driving and having them stay on roads (not go cross country) is important,
<dt class="note">[[User:Tankbuster|Tankbuster]]</dt>
<dd class="note">
When using this command to get the predicted path of vehicles driving and having them stay on roads (not go cross country) is important,
the best vehicle to use is "wheeled_APC" and careless [[behaviour]].
the best vehicle to use is "wheeled_APC" and careless [[behaviour]].
</dd>
}}
 
<!-- END Note Section -->
</dl>
 
<h3 style="display:none">Bottom Section</h3>

Revision as of 16:28, 3 May 2022

Hover & click on the images for description

Description

Description:
Spawns an agent that will execute an AI path calculation and fire the "PathCalculated" event handler. The vehicle type to simulate could be one of the following presets:
  • "man" (will use "C_man_1")
  • "car" (will use "C_Offroad_01_F")
  • "tank" (will use "B_MBT_01_cannon_F")
  • "wheeled_APC" (will use "B_APC_Tracked_01_rcws_F")
  • "boat" (will use "C_Rubberboat")
  • "plane" (will use "B_Plane_CAS_01_dynamicLoadout_F")
  • "helicopter" (will use "B_Heli_Light_01_F")

If the given vehicle type is not one of the above presets, the exact given type is used.

In order to guarantee that the event handler is added to the result of this command before the path is calculated, use isNil to run the code in an Unscheduled Environment:
isNil { calculatePath ["man", "safe", _startPos, _endPos] addEventHandler ["PathCalculated", { hint str _this }] };
Problems:
For some unknown reason, the "PathCalculated" Event Handler is fired twice, first with calculated path and second with array consisting of 2 elements, which are identical and are equal to the end point. See Example 3 & 4 for a workaround.
Groups:
Object Manipulation

Syntax

Syntax:
calculatePath [type, behaviour, from, to]
Parameters:
type: String - Vehicle type to simulate (see description)
behaviour: String - AI behaviour, one of "CARELESS", "SAFE", "AWARE", "COMBAT" or "STEALTH"
from: Array - Start position in format [x,y,z]
to: Array - End position in format [x,y,z]
Return Value:
Object - The agent to add the "PathCalculated" Event Handler to.

Examples

Example 1:
calculatePath ["car", "safe", [2150.67,5778.19,0], [2184.11,5802.28,0]];
Example 2:
Draws the path from South West to North East of Agia Marina:
(calculatePath ["man","safe",[2832.9,5927.79,0],[3107.46,6036.61,0]]) addEventHandler ["PathCalculated", { { private _marker = createMarker ["marker" + str _forEachIndex, _x]; _marker setMarkerType "mil_dot"; _marker setMarkerText str _forEachIndex; } forEach (_this select 1); }];
Example 3:
Alternative usage of calculatePath functionality that is free of double execution bug (and calculatePath command):
private _agent = createAgent [typeOf player, position player, [], 0, "NONE"]; _agent addEventHandler ["PathCalculated", { { private _marker = createMarker ["marker" + str _forEachIndex, _x]; _marker setMarkerType "mil_dot"; _marker setMarkerText str _forEachIndex; } forEach (_this select 1); }]; _agent setDestination [player getRelPos [500, 0], "LEADER PLANNED", true];
Example 4:
Same as above but for a vehicle:
private _agent = createAgent [typeOf player, position player, [], 0, "NONE"]; private _car = "B_Quadbike_01_F" createVehicle position player; _agent moveInDriver _car; _agent addEventHandler ["PathCalculated", { { private _marker = createMarker ["marker" + str _forEachIndex, _x]; _marker setMarkerType "mil_dot"; _marker setMarkerText str _forEachIndex; } forEach (_this select 1); }]; _agent setDestination [player getRelPos [500, 0], "LEADER PLANNED", true];

Additional Information

See also:
setDriveOnPath setDestination

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Tankbuster - c
Posted on Jun 06, 2019 - 10:28 (UTC)
When using this command to get the predicted path of vehicles driving and having them stay on roads (not go cross country) is important, the best vehicle to use is "wheeled_APC" and careless behaviour.