Here's a random patrol script for boats. It should work well for ambient boats. It is currently not geared for combat boats, as combat AI would compete with the scripted move commands. However it could be easily modified for a boat to exit this script if their behaviour changes to COMBAT. The screenshots below show the random paths that 5 boats took during various time frames. The last one ran 4 hours, so I think the script is pretty well tested now.
1. Boats would run into the ground if move to pos too close to shore. Solved by insuring moveTo pos had enough water in front and 90 degrees right, and 90 degrees left to execute a turn.
2. Boats still occasionally run aground or into a deep water piling or pier. Solved by flipping boat 180 degrees when this occurs. This is bad for immersion but better than a stuck boat. May replace this someday with a slow rotation of boat 180 degrees that looks better.
3. AI simply stops responding to commandMove commands. Sovled by deleting AI and replacing with new fresh AI driver if not responding for 30 seconds or more. Downside, is new unit does not have same gear as unit replaced. This is ok for ambient boats, but ultimately replacement units should be loaded with all same gear as unit being replaced. Feel free to plug in your favorite gear replacement script here (send me a an integrated solution and I will credit you...but I'm not into doing this myself).
4. Scripts would die after awhile giving no error, and no longer logging diag_log messages per loop execution. Solved by ending script, and spawning new script on same boat after 500 loop evolutions.
Installation / Usage:
For usage instructions and information of how to use the JBOY Boat Random Patrol please refer to the included documentation and/or example mission.
In the editor, put this in a boat's init box:
dummy = [this, "ColorBlue",true,2000] execVM "Scripts\JBOY_boatRandomPatrol.sqf";
The parameters are:
color of marker to track boat path
show markers boolean (true to show markers, false to not show markers)
Radius: Calculated positions to move must be within this radius, where center of radius is boat's starting position. This prevents boats from cruising a zillion kilometers away from the island.
Credits & Thanks:
Hat tip to @fn_Quiksilver for suggesting the getTerrainHeightASL for getting water depth.
- BI forums