Query if unit is a helicopter?
Posted: Mon Jun 01, 2020 5:15 am
I have script that just wants to see if say a US helicopter is within distance of some other unit.
All the related code to run threw the units and check distance is fine, except can't seem to find a good way to tell if something is generically a helicopter or tilt wing category of aircraft. The people being rescued are 'listening' for that sweet sound of a chopper closing in on them while they're on the run.
On the Side Wrapper there is unitsBy which I use constantly but it doesn't take helicopters it takes the core type Aircraft. Unit.subtype is very helpful usually, but in this case the sub-type(s) can apply to things other than helicopters or tilt-wing, and for example asw coded units can have troop or cargo loadouts that I want to include in the scan so I can't very reliably use subtype.
Is there no way to get the base category 2003? I noticed this is an issue with the detection triggers as well. I though of using QueryDB but last I checked aircraft had not been implemented yet. At present my solution is just check for all the different dbid's of the choppers and tilt-wings that said target side has in the scenario. Functional but very specific to the scenario and easy to forget to update as things change during development but it fits better then filtering on unit.subtype for this particular use case. Other ideas?
If I'm not missing something, I wonder if we can add category to the Unit wrapper (even if it's just in the fields) preferably as a number but the enum string works also, that would solve this in the future, and for those wanting to use detection triggers they could at least then use 'aircraft' and then farm out the rest to a lua script to do sub filtering for helo's or whatever it may be. It also solves this beyond just aircraft, I ran into similar with ships and facilities in the past.
I guess it's a bit more involved but maybe also add optional category to Side:unitsBy('type') so maybe it's Side:unitsBy('type',['categoryvalue']) since the game doing that filtering is more efficient then proxying it via lua for large sides. But that's more a wishlist list for marginal performance\QOL gain thing than a need.
All the related code to run threw the units and check distance is fine, except can't seem to find a good way to tell if something is generically a helicopter or tilt wing category of aircraft. The people being rescued are 'listening' for that sweet sound of a chopper closing in on them while they're on the run.
On the Side Wrapper there is unitsBy which I use constantly but it doesn't take helicopters it takes the core type Aircraft. Unit.subtype is very helpful usually, but in this case the sub-type(s) can apply to things other than helicopters or tilt-wing, and for example asw coded units can have troop or cargo loadouts that I want to include in the scan so I can't very reliably use subtype.
Is there no way to get the base category 2003? I noticed this is an issue with the detection triggers as well. I though of using QueryDB but last I checked aircraft had not been implemented yet. At present my solution is just check for all the different dbid's of the choppers and tilt-wings that said target side has in the scenario. Functional but very specific to the scenario and easy to forget to update as things change during development but it fits better then filtering on unit.subtype for this particular use case. Other ideas?
If I'm not missing something, I wonder if we can add category to the Unit wrapper (even if it's just in the fields) preferably as a number but the enum string works also, that would solve this in the future, and for those wanting to use detection triggers they could at least then use 'aircraft' and then farm out the rest to a lua script to do sub filtering for helo's or whatever it may be. It also solves this beyond just aircraft, I ran into similar with ships and facilities in the past.
I guess it's a bit more involved but maybe also add optional category to Side:unitsBy('type') so maybe it's Side:unitsBy('type',['categoryvalue']) since the game doing that filtering is more efficient then proxying it via lua for large sides. But that's more a wishlist list for marginal performance\QOL gain thing than a need.
