calculatePath: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(double execution bug)
(Some wiki formatting)
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Command|=
{{Command|Comments=
____________________________________________________________________________________________
____________________________________________________________________________________________


| arma3 |Game=
| arma3 |Game=


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


|arg=  |Multiplayer Arguments =("local" or "global")
|eff=  |Multiplayer Effects=
 
|eff=  |Multiplayer Effects =("local" or "global")
 
|exec=  |Multiplayer Execution =("server" or empty)
____________________________________________________________________________________________
____________________________________________________________________________________________


Line 22: Line 18:
* <tt>"helicopter"</tt> (will use "B_Heli_Light_01_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>
{{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]]:
{{Warning | 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 for a workaround. }} 
<code>[[isNil]] { [[calculatePath]] ["man", "safe", _startPos, _endPos] [[addEventHandler]] ["PathCalculated", { [[hint]] [[str]] [[_this]] }] };</code>}} |Description=
{{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:
 
  [[isNil]] { [[calculatePath]] ["man","safe",[2832.9,5927.79,0],[3107.46,6036.61,0]] [[addEventHandler]] ["PathCalculated", { [[hint]] [[str]] _this }] };  
|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=
}} |Description=
____________________________________________________________________________________________
____________________________________________________________________________________________


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


|p1= [type, behaviour, from, to]: [[Array]] |Parameter 1=
|p1= type: [[String]] - Vehicle type to simulate (see description) |Parameter 1=
|p2= type: [[String]] - Vehicle type to simulate (see description) |Parameter 2=


|p3= behavior: [[String]] - AI [[behaviour]], one of ("CARELESS", "SAFE", "AWARE", "COMBAT" and "STEALTH") |Parameter 3=
|p2= behaviour: [[String]] - AI [[behaviour]], one of "CARELESS", "SAFE", "AWARE", "COMBAT" or "STEALTH" |Parameter 2=


|p4= from: [[Array]] - Start position in format [x,y,z] |Parameter 4=
|p3= from: [[Array]] - Start position in format [x,y,z] |Parameter 3=


|p5= to: [[Array]] - End position in format [x,y,z] |Parameter 5=
|p4= to: [[Array]] - End position in format [x,y,z] |Parameter 4=


| [[Object]] - An agent to add the <tt>"PathCalculated"</tt> [[addEventHandler | event handler]] to. |Return Value=
| [[Object]] - The agent to [[addEventHandler|add]] the [[Arma 3: Event Handlers#PathCalculated|<tt>"PathCalculated"</tt> Event Handler]] to. |Return Value=
____________________________________________________________________________________________
____________________________________________________________________________________________


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


|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",{
|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", {
        _mrk = [[createMarker]] ["marker" + str _forEachIndex, _x];
{
        _mrk [[setMarkerType]] "mil_dot";
[[private]] _marker = [[createMarker]] ["marker" + [[str]] [[_forEachIndex]], [[_x]]];
        _mrk [[setMarkerText]] [[str]] _forEachIndex;
_marker [[setMarkerType]] "mil_dot";
    } [[forEach]] (_this#1);
_marker [[setMarkerText]] [[str]] [[_forEachIndex]];
} [[forEach]] ([[_this]] [[select]] 1);
}]</code> |Example 2=
}]</code> |Example 2=


|x3= Alternative usage of [[calculatePath]] functionality that is free of double execution bug (and calculatePath command): <code>[[private]] _agent = [[createAgent]] <nowiki>[</nowiki>[[typeOf]] [[player]], [[position]] [[player]], [], 0, "NONE"];  
|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"];  
_agent [[addEventHandler]] ["PathCalculated",
_agent [[addEventHandler]] ["PathCalculated",
{  
{  
    {  
{  
        [[private]] _mrk = [[createMarker]] ["marker" + [[str]] [[_forEachIndex]], [[_x]]];  
[[private]] _marker = [[createMarker]] ["marker" + [[str]] [[_forEachIndex]], [[_x]]];  
        _mrk [[setMarkerType]] "mil_dot";  
_marker [[setMarkerType]] "mil_dot";  
        _mrk [[setMarkerText]] [[str]] [[_forEachIndex]];  
_marker [[setMarkerText]] [[str]] [[_forEachIndex]];  
    }  
}  
    [[forEach]] [[_this]] [[hash|#]] 1;
[[forEach]] ([[_this]] [[select]] 1);
}];
}];
_agent [[setDestination]] <nowiki>[</nowiki>[[player]] [[getRelPos]] [500, 0], "LEADER PLANNED", [[true]]];</code> |Example 3=
_agent [[setDestination]] [<nowiki/>[[player]] [[getRelPos]] [500, 0], "LEADER PLANNED", [[true]]];</code> |Example 3=
 
|x4= Same as above but for a vehicle: <code>[[private]] _agent = [[createAgent]] [<nowiki/>[[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]] [<nowiki/>[[player]] [[getRelPos]] [500, 0], "LEADER PLANNED", [[true]]];</code> |Example 4=
____________________________________________________________________________________________
____________________________________________________________________________________________


|mp= - |Multiplayer Behaviour=
| [[setDriveOnPath]], [[setDestination]] |See Also=
 
| [[setDriveOnPath]], [[setDestination]] |See Also=
}}
}}


<dl class="command_description">
<dl class="command_description">
<!-- BEGIN Note Section -->
<!-- BEGIN Note Section -->
<!-- For example:
<dd class="notedate">Posted on Month Day, Year - Time (UTC)</dd>
<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>
-->
<!-- END Note Section -->
</dl>


<h3 style="display:none">Bottom Section</h3>
<!-- Appropriate categories go here -->
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on July 6, 2019 - 10:28 (UTC)</dd>
<dd class="notedate">Posted on July 6, 2019 - 10:28 (UTC)</dd>
<dt class="note">[[User:Tankbuster|Tankbuster]]</dt>
<dt class="note">[[User:Tankbuster|Tankbuster]]</dt>
<dd class="note">
<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 behaviour careless
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]].
</dd>
</dd>
<!-- END Note Section -->
</dl>
</dl>
<!-- DISCONTINUE Notes -->
 
<h3 style="display:none">Bottom Section</h3>

Revision as of 00:13, 18 June 2020

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:
Uncategorised

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:
setDriveOnPathsetDestination

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
Posted on July 6, 2019 - 10:28 (UTC)
Tankbuster
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.

Bottom Section