Author: Zenophon
Author Website:

Requirements: No addons required

Version: 7/21/15

Short description: This script teleports AI units into the nearest building at appropriate window positions.

Date: 2015-07-21 23:38


Comments: (3)
Rating:



 



Infantry Occupy House Script

by
Zenophon


Description:
This script teleports AI units into nearby buildings at appropriate window positions. Units will stand and face the window so they can fire out of it. Units are moved to random windows every time. If there are enough units, every possible window will be covered; otherwise, you won't know where they are watching. When there are multiple possible windows to face, units will face one at random. Units will not face a windows more than 5 meters away, and the windows will have a reasonable field of view.

By using this script, you no longer have to manually place units at windows and struggle with the 2d editor. This script allows you to easily simulate the AI occupying buildings and defending their position realistically. It works for just a few units to surprise players, and on a large scale to put dozens of enemies into defensive positions all across a city.

The function is carefully optimized for almost no performance impact, allowing it to dynamically examine each position for the best possible results. There is no debug, argument checking, or defensive code, to make it as simple and fast as possible, so make sure the arguments are correct.


Installation / Usage:
Place the script somewhere in your mission folder.
Function parameters:
Array, the building(s) nearest this position is used
Array of objects, the units that will garrison the building(s)
Scalar, radius in which to fill building(s), -1 for only nearest building
Boolean, true to put units on the roof, false for only inside
Boolean, true to fill all buildings in radius evenly, false for one by one

The complete documentation is also commented at the top of the file. You can run it from anywhere with execVM:
0 = [getPosATL player, units group X, -1, true, false] execVM "Zen_OccupyHouse.sqf";
You can also compile it into a function if you plan on using it many times:
Zen_OccupyHouse = compileFinal preprocessFileLineNumbers "Zen_OccupyHouse.sqf";
_units = [(getMarkerPos "mkHouse"), [X, Y, Z], 50, false, true] call Zen_OccupyHouse;
When using the compile and call method, the function returns the array of units that did not fit in the building.


Known issues:
Sometimes units may initially face the 'wrong' window, i.e. a different one then the one they are standing next to. The unit can still see out of a window and turn to face enemy that they know about.


Notes:
If you liked/disliked it or have any suggestions for improvement, I would like to hear your thoughts. Either this thread, PM, or email is fine.


License:
This software is released under Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).
http://creativecommons.org/licenses/by-nc/4.0/


Changelog:
7/21/15
Added: Error reporting for invalid position and unit array arguments
Added: Error report if no buildings are found
Improved: Parameters 3, 4, and 5 are now optional and check for the correct type
Improved: Parameters 6 and 7 check for the correct type
Improved: AI should now stay in place better (thanks to JohnnyBoy)

7/6/15
Added: AI now take cover when fired upon (credit to JohnnyBoy)
Added: Parameter to order the AI to move to their position
Improved: The order of buildings filled is now random
Improved: A few minor optimizations

6/30/15
Added: Parameter to fill buildings from top to bottom
Improved: Optimized

7/31/14
- Added: Parameter to cycle through each building in the radius, giving units to each one
- Improved: Units on roof are only placed at the edge, and face the edge
- Improved: Optimized roof check
- Improved: General script cleanup

7/28/14
- Fixed: Units facing the wrong window
- Added: Parameter for distance to select multiple buildings
- Added: Parameter for units being on a roof
- Improved: Now checks that unit has a good FOV from the windows
- Improved: Units can no longer face a windows greater than 5 meters away
- Improved: Units on a roof now crouch
- Tweaked: Height of human eye to the exact value in ArmA

7/24/14
- Initial Release


Forum topic:
- BI forums




Enable javascript to be able to download from Armaholic please!



Tags: Teleport,   Ai,   House