calculatePath: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(stable)
m (Text replacement - "(\|[pr][0-9]+ *= *[^- ]*) *- *V([a-z ])" to "$1 - v$2")
 
(47 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Command|=
{{RV|type=command
____________________________________________________________________________________________


| arma3 |Game=
|game1= arma3
|version1= 1.94


|1.94|Game Version =(number surrounded by NO SPACES)
|gr1= Object Manipulation


|arg= |Multiplayer Arguments =("local" or "global")
|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:
|eff=  |Multiplayer Effects =("local" or "global")
{{Columns|2|
 
* {{hl|"man"}} (will use "C_man_1")
|exec=  |Multiplayer Execution =("server" or empty)
* {{hl|"car"}} (will use "C_Offroad_01_F")
____________________________________________________________________________________________
* {{hl|"tank"}} (will use "B_MBT_01_cannon_F")
* {{hl|"wheeled_APC"}} (will use "B_APC_Tracked_01_rcws_F")
* {{hl|"boat"}} (will use "C_Rubberboat")
* {{hl|"plane"}} (will use "B_Plane_CAS_01_dynamicLoadout_F")
* {{hl|"helicopter"}} (will use "B_Heli_Light_01_F")
}}


| 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:
* <tt>"man"</tt> (will use "C_man_1")
* <tt>"car"</tt> (will use "C_Offroad_01_F")
* <tt>"tank"</tt> (will use "B_MBT_01_cannon_F")
* <tt>"wheeled_APC"</tt> (will use "B_APC_Tracked_01_rcws_F")
* <tt>"boat"</tt> (will use "C_Rubberboat")
* <tt>"plane"</tt> (will use "B_Plane_CAS_01_dynamicLoadout_F")
* <tt>"helicopter"</tt> (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.
If the given vehicle type is not one of the above presets, the exact given type is used.
<br><br>
{{Feature|important|
{{Important | In order to guarantee that the event handler is added to the result of this command before the path is calculated, use [[isNil]] workaround:
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]]:
  [[isNil]] { [[calculatePath]] ["man","safe",[2832.9,5927.79,0],[3107.46,6036.61,0]] [[addEventHandler]] ["PathCalculated", { [[hint]] [[str]] _this }] };  
<sqf>isNil { calculatePath ["man", "safe", _startPos, _endPos] addEventHandler ["PathCalculated", { hint str _this }] };</sqf>
}} |Description=
}}
____________________________________________________________________________________________


| [[calculatePath]] [type, behaviour, from, to] |Syntax=
{{Feature|informative|
If an exact path is desired, it is recommended to avoid this command and simply use the [[Arma_3:_Event_Handlers#PathCalculated|PathCalculated]] event handler.
Paths to long distances are typically calculated in segments. This command only gives the first calculated segment.
}}


|p1= [type, behaviour, from, to]: [[Array]] |Parameter 1=
|pr= For some unknown reason, the "PathCalculated" Event Handler is fired twice, first with the calculated path and second with an array consisting of 2 elements, which are identical and are equal to the end point.
|p2= type: [[String]] - Vehicle type to simulate (see description) |Parameter 2=
See '''{{Link|#Examples|Example 3 &amp; 4}}''' for a workaround.


|p3= behavior: [[String]] - AI [[behaviour]], one of ("CARELESS", "SAFE", "AWARE", "COMBAT" and "STEALTH") |Parameter 3=
|s1= [[calculatePath]] [type, behaviour, from, to]


|p4= from: [[Array]] - Start position in format [x,y,z] |Parameter 4=
|p1= type: [[String]] - vehicle type to simulate (see description)


|p5= to: [[Array]] - End position in format [x,y,z] |Parameter 5=
|p2= behaviour: [[String]] - AI [[behaviour]], one of "CARELESS", "SAFE", "AWARE", "COMBAT" or "STEALTH"


| [[Object]] - An agent to add the <tt>"PathCalculated"</tt> [[addEventHandler | event handler]] to. |Return Value=
|p3= from: [[Array]] - start position in format [x,y,z]
____________________________________________________________________________________________


|x1= <code>[[calculatePath]] ["car","safe",[2150.67,5778.19,0],[2184.11,5802.28,0]]</code> |Example 1=
|p4= to: [[Array]] - end position in format [x,y,z]


|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",{
|r1= [[Object]] - the agent to [[addEventHandler|add]] the [[Arma 3: Event Handlers#PathCalculated|{{hl|"PathCalculated"}} Event Handler]] to.
    {
        _mrk = [[createMarker]] ["marker" + str _forEachIndex, _x];
        _mrk [[setMarkerType]] "mil_dot";
        _mrk [[setMarkerText]] [[str]] _forEachIndex;
    } [[forEach]] (_this#1);
}]</code> |Example 2=
____________________________________________________________________________________________


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


| [[setDriveOnPath]] |See Also=
|x2= Draws the path from South West to North East of Agia Marina:
}}
<sqf>
(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);
}];
</sqf>


<dl class="command_description">
|x3= Alternative usage of [[calculatePath]] functionality that is free of the double execution bug (and calculatePath command):
<!-- BEGIN Note Section -->
<sqf>
<!-- For example:
private _agent = createAgent [typeOf player, position player, [], 0, "NONE"];
<dd class="notedate">Posted on Month Day, Year - Time (UTC)</dd>
_agent addEventHandler ["PathCalculated",
<dt class="note">'''[[User:User Name|User Name]]'''</dt>
{
<dd class="note">This is an example note. It is true and verifiable, and contains a little code snippet.
{
<code>[[if]] ([[_this]] == anExample) [[then]] { [[hint]] "Leave it here for others to read"; };</code></dd>
private _marker = createMarker ["marker" + str _forEachIndex, _x];
-->
_marker setMarkerType "mil_dot";
<!-- END Note Section -->
_marker setMarkerText str _forEachIndex;
</dl>
}
forEach (_this select 1);
}];
_agent setDestination [player getRelPos [500, 0], "LEADER PLANNED", true];
</sqf>


<h3 style="display:none">Bottom Section</h3>
|x4= Same as above but for a vehicle:
<!-- Appropriate categories go here -->
<sqf>
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];
</sqf>


[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
|seealso= [[setDriveOnPath]] [[setDestination]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
}}


<!-- CONTINUE Notes -->
{{Note
<dl class="command_description">
|user= Tankbuster
<dd class="notedate">Posted on July 6, 2019 - 10:28 (UTC)</dd>
|timestamp= 20190606102800
<dt class="note">[[User:Tankbuster|Tankbuster]]</dt>
|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,
<dd class="note">
the best vehicle to use is "wheeled_APC" and careless [[behaviour]].
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 behaviour careless
}}
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 15:53, 8 November 2023

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 }] };
If an exact path is desired, it is recommended to avoid this command and simply use the PathCalculated event handler. Paths to long distances are typically calculated in segments. This command only gives the first calculated segment.
Problems:
For some unknown reason, the "PathCalculated" Event Handler is fired twice, first with the calculated path and second with an 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 the 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.