naught 6 Posted December 23, 2013 (edited) AI Caching and Distribution Script v1.0.2.4 - v1.0 RC 4 By Naught GitHub: https://github.com/dylanplecki/ArmaScripts/tree/master/Arma%202/Unit%20Caching Issues: https://github.com/dylanplecki/ArmaScripts/issues Download: https://github.com/dylanplecki/ArmaScripts/releases/tag/UCD_1_0_2_4 Orignal Thread: http://forums.unitedoperations.net/index.php/topic/21527-ai-caching-and-distribution-script/ Description An SQF script designed to dynamically cache and distribute AI units across machines for maximum performance. This script will be my first fully-autonomous script, meaning no setup required! This script is completely plug-and-play, with no dirty work required. It will cache all AI units and spawn them when players get close to them, and will automatically distribute AI across multiple headless clients. And the best part is is that you can still use your current method of AI spawning, whether it's through the editor or via a script. The only requirement is making a headless client slot, which is very simple and shown below. Now mission makers who have been too intimidated by the script knowledge needed to make headless client or cached/respawning AI missions can utilize all of the performance benefits that it brings with them! Even users who already have implemented headless client will benefit from the script immensely due to the pure efficiency of it's caching and distribution mechanisms, which are much better than most which are already implemented in missions. Features Fully plug-and-play, simply drag-and-drop the script into your mission and it autonomously works its magic. Works with nearly all AI spawning scripts on any machine. Caches AI units, meaning all units but a group's leader (configurable in config.sqf) are saved and deleted, and then respawned when players get close. Dynamically allocates units to headless clients, meaning that if headless client(s) are available, it will transfer AI to them. If any HC's are open, the server won't process any AI. And it does all of this automatically. Fully configurable caching settings in the config.sqf, including some experimental vehicle caching (not currently recommended). Built using my new Object-Oriented-Programming (OOP) framework for high-performance OOP code. Built for speed and performance. Headless Client If you choose to enable AI distribution (on by default), make sure you create a headless client unit like this: http://archive.plecki.net/img/hc_example.png (1042 kB) Requirements Arma 2 OA [1.62] Arma 3 [any version] CBA [any version] Known Issues AI unit caching may not be compatible with script which count AI, like end-scripts. An easy fix would be to end the mission on the absence of all AI, and not a percentage. AI unit caching doesn't work well with AI vs AI scenarios, and shouldn't be used unless players are always in close proximity to the action. Has a CBA dependency for the reliable CBA_fnc_players and the even better XEH. AI distribution may break scripts which modify AI behaviour (such as UPSMON). To fix this, an advanced user may use the "CACHE_UNIT_SPAWN_FNC" definition to define a function to load and process on every cached unit spawn, such as this (where "MY_fnc_unitSpawn" contains code with differentiates between vehicles and units and runs scripts accordingly): {_this call MY_fnc_unitSpawn;} // _this == _spawnedObject Changelog 1.0.2.4 [FIXED] Crewed vehicles retain their states over caching and distributions. [FIXED] Units now properly retain set positions if specified before caching/distribution. [FIXED] Vehicles are no longer distributed (needless operation). [FIXED] Setting of vehicleVarName should now propagate to all machines. [FIXED] Renamed array manipulation function to match syntax (minor edit). 1.0.2.2 [FIXED] AI no longer flee when their group is cached (work-around). [FIXED] Library linkages now correctly handle others' exceptions. [FIXED] 'No entry in CfgMagazines ...' error has been fixed (due to currentMagazine command). [FIXED] Rewrote the caching functions to check for all exceptions at the correct points. 1.0.1.8 [FIXED] 1.0.1.7 regression which caused caching checks to spin infinitely. 1.0.1.7 [FIXED] Units' volatile shifts to leadership are now accounted for while caching. [NOTE] SSD crashed, proceeding without testing (for now). 1.0.1.6 [FIXED] Possible error in config.sqf with wrong types. [FIXED] Enabled CBA caching of static files for release version. 1.0.1.5 [NEW] Initial public release. Edited January 28, 2014 by Naught Share this post Link to post Share on other sites
Guest Posted December 23, 2013 Thanks for sending us your release :cool: Release frontpaged on the Armaholic homepage. AI Caching and Distribution v1.0.1.5Community Base addons Share this post Link to post Share on other sites
das attorney 858 Posted December 23, 2013 Wow some really cool stuff in there Naught - been working on a similar system but having all sorts of problems so good to see it is possible :) Share this post Link to post Share on other sites
grillob3 11 Posted December 23, 2013 Nice!I am always looking for a better cache system!Thanks. What is the difference from this cB AI Unit Caching from Wolffy? Share this post Link to post Share on other sites
naught 6 Posted December 23, 2013 Nice!I am always looking for a better cache system!Thanks.What is the difference from this cB AI Unit Caching from Wolffy? Much better performance, easier to install/use, increased compatibility, automatic AI distribution to ALL connected headless clients, configurable options (ie. you can make all AI men spawn within 1000m of players, but make AI vehicle gunners spawn within 1500m, or make AI which are driving/flying vehicles and aircraft not cache, for obvious reasons), mostly coded in object-oriented style (this really just helps to increase performance and extensibility), also works with the ACE ruck system (for Arma 2) and saves much more data about each unit, allowing for better AI caching, and has experimental capability for caching AI vehicles and respawning them close to the leader when players are near. Share this post Link to post Share on other sites
SavageCDN 231 Posted December 23, 2013 ^ sounds freakin great!! thanks for releasing this Share this post Link to post Share on other sites
lkincheloe 12 Posted December 23, 2013 Does this work on a server-wide or a per-player basis? More specifically, if I have two AOs far apart and a group of players attacking each AO, would the caching of the opposite AO mess up anything for either group of players? Share this post Link to post Share on other sites
naught 6 Posted December 23, 2013 Does this work on a server-wide or a per-player basis? More specifically, if I have two AOs far apart and a group of players attacking each AO, would the caching of the opposite AO mess up anything for either group of players? Server-wide, the purpose of the script is to be as transparent as possible so you won't have to worry about things like this. For each group, it'll find the closest player, and if it is close enough it'll spawn the specified units. So yes, it'll work as long as players are near by, the only issue is with ai vs ai combat since no players are near and groups may not spawn. Share this post Link to post Share on other sites
giallustio 770 Posted December 24, 2013 Cached ai won't move on the map, am i right? Share this post Link to post Share on other sites
naught 6 Posted December 24, 2013 Cached ai won't move on the map, am i right? The caching system works by deleting all AI but the group leader, so the group continues to move about, but once players get close the entire force spawns in. It works as it would without the caching system with virtually no difference but increased performance. Share this post Link to post Share on other sites
grillob3 11 Posted December 24, 2013 Its not working on arma 3. I placed a unit player and a squad 1100 meters away and i can still see the whole squad. Is there a way to change the cache distance? Share this post Link to post Share on other sites
naught 6 Posted December 24, 2013 (edited) Its not working on arma 3. I placed a unit player and a squad 1100 meters away and i can still see the whole squad. Is there a way to change the cache distance? It's working correctly, you shouldn't notice anything different besides increases in performance with large amounts of AI, which is the point of the script, to remain transparent but functional. It automatically uses your viewdistance as the caching distance, and it can be changed in config.sqf as the "GLOBAL_SPAWN_DISTANCE" (use a low value such as (500) or (viewdistance - 500) to actually see the caching happen). Alternatively you can use some type of AI monitor (preferably marking AI on the map) to show what the AI are doing when they're out of your viewdistance, which is where all the magic happens. Edited December 24, 2013 by Naught Share this post Link to post Share on other sites
grillob3 11 Posted December 24, 2013 I wanna see AI caching just for testing. And i set it to a "GLOBAL_SPAWN_DISTANCE" and caches fine but when i kill the leader and move away so it caches again the group wont respawn anymore. I will do more tests tomorrow. Share this post Link to post Share on other sites
SavageCDN 231 Posted December 24, 2013 It automatically uses your viewdistance as the caching distance, and it can be changed in config.sqf as the "GLOBAL_SPAWN_DISTANCE" (use a low value such as (500) or (viewdistance - 500) to actually see the caching happen). Uh... that is awesome! Share this post Link to post Share on other sites
naught 6 Posted December 24, 2013 I wanna see AI caching just for testing. And i set it to a "GLOBAL_SPAWN_DISTANCE" and caches fine but when i kill the leader and move away so it caches again the group wont respawn anymore. I will do more tests tomorrow. If no units are present in the active group at any time no caching/respawning will take place (due to Arma garbage collection and the inherent lack-of group positioning), hence the "GLOBAL_SPAWN_DISTANCE" being set to slightly above the minimum value for you to start killing enemies. What you could do to see the whole caching system in action is use this code in the config.sqf: UCD_cachingDistance = 500; #define GLOBAL_SPAWN_DISTANCE (UCD_cachingDistance) // Meters And alter the "UCD_cachingDistance" while in-game (using the debug console) to smaller and larger than your current distance (ie. 1m and 90000m), waiting (at a maximum) "CACHE_MONITOR_DELAY" seconds (default 15 seconds) between each shift before any changes will occur. Then you can see the group caching/respawning. 1 Share this post Link to post Share on other sites
rowdied 44 Posted December 24, 2013 Would this be able to work for a mission like ZoneKillers Battlezone? Cache the units and have the headless client working as well? thanks Share this post Link to post Share on other sites
naught 6 Posted December 24, 2013 Would this be able to work for a mission like ZoneKillers Battlezone? Cache the units and have the headless client working as well? It may work, though it depends on the scripts the mission maker uses to control AI movement (AI distribution may cause these scripts to exit prematurely)... Easiest way would be to plug it in and test it out, looking for any AI which have stopped and won't move or are going to the wrong area. Share this post Link to post Share on other sites
naught 6 Posted December 24, 2013 (edited) Updated to 1.0.1.6 - v1.0 Beta 6 This is an incremental release, so it can be seen as a "hotfix" of sorts. It won't add anything major, but it does fix bugs which evaded the bug-testing phase. Download. Changelog 1.0.1.6 [FIXED] Possible error in config.sqf with wrong types. [FIXED] Enabled CBA caching of static files for release version. 1.0.1.5 [NEW] Initial public release. Edited December 24, 2013 by Naught Share this post Link to post Share on other sites
whiztler 137 Posted December 25, 2013 Wicked! Thanks mate, been waiting for this one! Share this post Link to post Share on other sites
grillob3 11 Posted December 25, 2013 (edited) Thanks. Edited December 26, 2013 by Grillob3 Share this post Link to post Share on other sites
Guest Posted December 25, 2013 New version frontpaged on the Armaholic homepage. AI Caching and Distribution v1.0.1.6Community Base addons Share this post Link to post Share on other sites
highhead 20 Posted December 25, 2013 Nice work, waypoints are copied but how do you get around losing fsms and scripts on locality change? Share this post Link to post Share on other sites
naught 6 Posted December 25, 2013 Nice work, waypoints are copied but how do you get around losing fsms and scripts on locality change? Waypoints are global to groups so there is no need to copy them (released this in the alpha stage after writing all the code for it :P) , FSMs and scripts re-adjust automatically due to the identical conditions, but since distribution usually happens during the beginning of the mission there's no need for special handling for groups which change locality, there's nothing to transfer anyways. But, if say a headless client JIPs mid-game, yes AI will lose their situational awareness momentarily, but it won't take long for their FSMs to catch-up. Scripts which manipulate AI groups should be unaffected by a change in locality, but scripts which monitor AI on a per-unit basis may break when distribution occurs, so I included a little option to run custom code in the config.sqf on AI spawning from cache/distribution for advanced users to remedy this issue. New version frontpaged on the Armaholic homepage. http://www.armaholic.com/datas/users/news_donwload_oa_4.pngAI Caching and Distribution v1.0.1.6http://www.armaholic.com/skins/Blaster07/img/required_addons.pngCommunity Base addons Thanks for all of your work Foxhound, it always amazes me how you run Armaholic so well while also doing these things like checking for our updates. You're invaluable to the Arma community, so have a happy holidays! :) Share this post Link to post Share on other sites
grillob3 11 Posted December 26, 2013 I did some more tests all in the same mission: The good: -arma 3 hide/show cache system i will get 160 fps - cB AI Unit Caching from Wolffy i will get 145 fps -Yours i will get 175 fps!Very nice! The bad: -If i put 10 groups of 10 soldiers each, i will have 100 soldiers! with your cache system i only have to kill the leaders (10 soldiers) instead of all the 100 soldiers! Because the cache only seems to work if the group leader is alive otherwise stop caching. Kill the leader and move away from spawn zone all the units will disappear and wont appear again. Share this post Link to post Share on other sites
naught 6 Posted December 26, 2013 I did some more tests all in the same mission: The good: -arma 3 hide/show cache system i will get 160 fps - cB AI Unit Caching from Wolffy i will get 145 fps -Yours i will get 175 fps!Very nice! The bad: -If i put 10 groups of 10 soldiers each, i will have 100 soldiers! with your cache system i only have to kill the leaders (10 soldiers) instead of all the 100 soldiers! Because the cache only seems to work if the group leader is alive otherwise stop caching. Kill the leader and move away from spawn zone all the units will disappear and wont appear again. You're absolutely right, that is not intended was at the fault of 1 misplaced line of code (go figure!). Updated to 1.0.1.7 - v1.0 Beta 7 This is an incremental release, so it can be seen as a "hotfix" of sorts. It won't add anything major, but it does fix bugs which evaded the bug-testing phase. Download. Changelog 1.0.1.7 [FIXED] Units' volatile shifts to leadership are now accounted for while caching. [NOTE] SSD crashed, proceeding without testing (for now). 1.0.1.6 [FIXED] Possible error in config.sqf with wrong types. [FIXED] Enabled CBA caching of static files for release version. 1.0.1.5 [NEW] Initial public release. Share this post Link to post Share on other sites