calculatePath: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) |
Lou Montana (talk | contribs) |
||
Line 19: | Line 19: | ||
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. | ||
{{Feature | 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 | 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]]: | ||
<code>[[isNil]] { [[calculatePath]] ["man", "safe", _startPos, _endPos] [[addEventHandler]] ["PathCalculated", { [[hint]] [[str]] [[_this]] }] };</code>}} | <code>[[isNil]] { [[calculatePath]] ["man", "safe", _startPos, _endPos] [[addEventHandler]] ["PathCalculated", { [[hint]] [[str]] [[Magic Variables#this|_this]] }] };</code>}} | ||
|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 & 4]]''' for a workaround. | |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 & 4]]''' for a workaround. | ||
Line 43: | Line 43: | ||
_marker [[setMarkerType]] "mil_dot"; | _marker [[setMarkerType]] "mil_dot"; | ||
_marker [[setMarkerText]] [[str]] [[_forEachIndex]]; | _marker [[setMarkerText]] [[str]] [[_forEachIndex]]; | ||
} [[forEach]] ([[_this]] [[select]] 1); | } [[forEach]] ([[Magic Variables#this|_this]] [[select]] 1); | ||
}]</code> | }]</code> | ||
Line 55: | Line 55: | ||
_marker [[setMarkerText]] [[str]] [[_forEachIndex]]; | _marker [[setMarkerText]] [[str]] [[_forEachIndex]]; | ||
} | } | ||
[[forEach]] ([[_this]] [[select]] 1); | [[forEach]] ([[Magic Variables#this|_this]] [[select]] 1); | ||
}]; | }]; | ||
_agent [[setDestination]] [<nowiki/>[[player]] [[getRelPos]] [500, 0], "LEADER PLANNED", [[true]]];</code> | _agent [[setDestination]] [<nowiki/>[[player]] [[getRelPos]] [500, 0], "LEADER PLANNED", [[true]]];</code> | ||
Line 69: | Line 69: | ||
_marker [[setMarkerText]] [[str]] [[_forEachIndex]]; | _marker [[setMarkerText]] [[str]] [[_forEachIndex]]; | ||
} | } | ||
[[forEach]] ([[_this]] [[select]] 1); | [[forEach]] ([[Magic Variables#this|_this]] [[select]] 1); | ||
}]; | }]; | ||
_agent [[setDestination]] [<nowiki/>[[player]] [[getRelPos]] [500, 0], "LEADER PLANNED", [[true]]];</code> | _agent [[setDestination]] [<nowiki/>[[player]] [[getRelPos]] [500, 0], "LEADER PLANNED", [[true]]];</code> |
Revision as of 13:18, 25 February 2021
Description
- Description:
- Description needed
- 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:
- Syntax needed
- 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:
- Return value needed
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.