This script will allow you to have a unit patrol a house, randomly.
All you need to do is place a unit close to a building and init the script on it. The script will then check how many available building positions there are in the closest building of the unit, and place him randomly at one. Then he will start patrolling the building.
Every time the unit reaches it's waypoint inside the house it will stay and wait for a short while, before moving to the next point. The amount of time the unit waits is random. So you'll never really
know how long the unit will stand still.
It works in Multiplayer as well as Singleplayer.
Put this in the init field of a unit and put it next to or on a house
guard = [this] execVM "HousePatrol.sqf"
You may also set the behaviour of the unit by putting the preferred behavior in the array.
guard = [this,"COMBAT"] execVM "HousePatrol.sqf"
You may put any of these five:
* There is also an option to set the maximum amount of time (in seconds) that the unit will wait before moving to the next waypoint.
To use this option the behaviour option must be set too.
guard = [this,"SAFE",50] execVM "HousePatrol.sqf"
If you don't put anything the default value of 30 will be set. Use 0 as value if you want the guard to patrol continuously.
Sometimes ArmA2 has some problems with pathfinding and getting units to report if they have finished or failed a task. To get around any such problems the guard will be given a new command if it takes more than 90 seconds to finish the last command. Some houses seem to be more difficult for the AI to sort out.
* Optimized the code for better performance and no error codes.
* Added a workaround for a game bug where some buildings are missing data.
Tags: No tags