Stonehouse Posted August 22, 2016 Posted August 22, 2016 Just wondering what is the best way to end up with the unit deemed as being the leader of a group of vehicles or ships? I know you can do a Group:getController but that returns a class of Controller not Unit and while it logically is representative of the group leader I don't think it equates to Unit from a script point of view. Is there an easy way of going from knowing the controller to getting the unit leading the group (which I believe changes according to units in the group being destroyed) ? Any other approach people use? Thanks, Stonehouse
nomdeplume Posted August 22, 2016 Posted August 22, 2016 Pretty sure the leader of a ground/naval group is always the first active unit in the group. So if you kill unit #1, #2 will become leader, etc. So you can just get the list of all units and select the first one. <code>group:getUnits()[1]</code> or similar. For robustness, you'd want to make sure the group actually still has at least one unit before doing that.
Stonehouse Posted August 22, 2016 Author Posted August 22, 2016 (edited) Ok thanks. I was of that impression too but wondered if there was a short cut built into the various DCS functions so you could link directly from controller to the unit it was associated with. If no-one can offer alternatives then I will go ahead using the method you suggest. Thanks again. Cheers, Stonehouse <edit> PS is it always group:getUnits()[1] ? ie is the table rearranged after the original unit at index 1 is destroyed? or does the table stay static and [2] become controller? Edited August 22, 2016 by Stonehouse
ESAc_matador Posted August 22, 2016 Posted August 22, 2016 As mentioned... there is no leader. The group obeys as groop. Leader just the first in the cue
Stonehouse Posted August 22, 2016 Author Posted August 22, 2016 Did some more searching and came across http://forums.eagle.ru/showpost.php?p=2017253&postcount=491 This implies that the table returned by getUnits is actually static and that index =1 may start out as the leader but if it dies then index =2 inherits his command and so on. Don't know if the comments are still true or not being about 2 years ago.
Grimes Posted August 22, 2016 Posted August 22, 2016 Its not static. The size will change depending on what is alive. Units will inherit the lead as units ahead of them in the group die. Group.getUnits() returns a table of each unit object within the group indexed numerically. Group.getUnit(x) returns a specific unit at index x. Group.getUnits()[x] would effectively be the same thing. Controllers with relation to group and unit tasking can get a little confusing. If you assign a given task to the whole group then they will all follow it as a group. However individual units can also be given orders. An order given to the unit controller of the lead will result in that one unit doing whatever assigned task. However it is possible that the other units in the group will still physically follow the lead without participating in the tasking. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Stonehouse Posted August 22, 2016 Author Posted August 22, 2016 Thanks for the confirmation Grimes. Lucky for me I am only really looking for the unit that is leading the group so I can use it to check for enemy units in a moving zone around the group (assuming that the individual units will be relatively close together as compared to the radius of the zone which is 8000m). Ok cool I can just do Group.getUnits()[1] then by the sounds of it as the other guys suggested. Cheers, Stonehouse
Stonehouse Posted August 22, 2016 Author Posted August 22, 2016 Doing some rewrites of the flak script to hopefully improve performance in MP and also remove the need for M-E triggers for each flak site. It's been very on and off as I only have time in between helping with Markindel's mods. It is getting somewhere though which is good, no ETA I'm sorry as getting time for it is very unpredictable.
FlightControl Posted August 26, 2016 Posted August 26, 2016 MOOSE does not require you to use Controller anymore. It is hidden within the framework. GROUP, UNIT, CLIENT all derive froma CONTROLLABLE class, which implements the Controllable DCS object to steer AI. Have a look at the framework ... [TABLE][sIGPIC][/sIGPIC]| Join MOOSE community on: DISCORD :thumbup: Website of the MOOSE LUA Framework. MOOSE framework Downloads. Check out Example Missions to try out and learn. MOOSE YouTube Channel for live demonstrations and tutorials. [/TABLE]
Recommended Posts