Lorenz94 6 Posted January 12, 2018 Hello, I premise that before posting this I did some research, and apparently there's not so much out there to put together (at least at my level of knownledge). I'm working on a script to pass to headless clients all the AIs found, on each frame. I kindly need your help finding out if I'm writing down the script correctly or not, since currently I can not test by myself on a dedicated. Thank you in advance. Spoiler if (!isDedicated) exitWith {}; _HCs = []; if !(isNil "HC1") then { _HC1 = "HC1"; _HCs = _HCs + _HC1; }; if !(isNil "HC2") then { _HC2 = "HC2"; _HCs = _HCs + _HC2; }; if !(isNil "HC3") then { _HC1 = "HC3"; _HCs = _HCs + _HC3; }; ["AI_to_HC", "onEachFrame", { //HCs are all on the same machine, so I think is ok to use the first HC if (owner _x isEqualto owner _HC1) exitWith {}; //If the AI has not the variable if !(_x getVariable "alreadyOnHC") then { { //Sort HCs from less to highest load _sortHCs = [_HCs, [], {count units group _x}, "ASCEND"] call BIS_fnc_sortBy; //Set the less loaded HC as owner _x setGroupOwner _sortHCs select 0; _x setVariable ["alreadyOnHC", true]; //"Debug" hintSilent format ["HC1: %1\nHC2: %2\nHC3: %3", count units group _HC1, count units group _HC2, count units group _HC3]; } forEach allUnits select {!isPlayer _x}; }; } ] call BIS_fnc_addStackedEventHandler; Share this post Link to post Share on other sites
engima 327 Posted January 13, 2018 Is that a good idea? Maybe if you can make the assumpsion that all AI units are not controlled by any other script. Can you? If AI units are controlled by scripts than the script must be executed on the HC too, so best if they are on the HC from mission start. Share this post Link to post Share on other sites
Lorenz94 6 Posted January 14, 2018 On 13/1/2018 at 12:15 PM, engima said: Is that a good idea? Maybe if you can make the assumpsion that all AI units are not controlled by any other script. Can you? If AI units are controlled by scripts than the script must be executed on the HC too, so best if they are on the HC from mission start. the onEachFrame EH should check for new AIs indeed..! Share this post Link to post Share on other sites
pierremgi 4739 Posted January 14, 2018 3 hours ago, Lorenz94 said: the onEachFrame EH should check for new AIs indeed..! Your loop runs for every ais, again and again. You should write: forEach { (allUnits - allPlayers) select {!(_x getVariable ["alreadyOnHC",false]) } }; instead of if then condition. You give to _hc1 variable(s) a string "hc1", not an object hc1 (headless unit). You are no more in isNil syntax. You try to add this string to an array. See pushBack command or arrays addition. Anyway, you should have a look here and follow the guide (link to werthles' guide) If I remember, the check for a headless presence is done with isNull rather than isNil. Share this post Link to post Share on other sites
Lorenz94 6 Posted January 17, 2018 On 14/1/2018 at 5:20 PM, pierremgi said: Your loop runs for every ais, again and again. You should write: forEach { (allUnits - allPlayers) select {!(_x getVariable ["alreadyOnHC",false]) } }; instead of if then condition. You give to _hc1 variable(s) a string "hc1", not an object hc1 (headless unit). You are no more in isNil syntax. You try to add this string to an array. See pushBack command or arrays addition. Anyway, you should have a look here and follow the guide (link to werthles' guide) If I remember, the check for a headless presence is done with isNull rather than isNil. Thank you, will have a look soon on the code. Regarding Werthles' HC, is his script still reliable? It hasn't been updated for a year or so! Share this post Link to post Share on other sites
Imperator[TFD] 444 Posted January 18, 2018 6 hours ago, Lorenz94 said: Thank you, will have a look soon on the code. Regarding Werthles' HC, is his script still reliable? It hasn't been updated for a year or so! It certainly is still reliable in script form. My group uses it 2 a week. Share this post Link to post Share on other sites