Checking Sensor Arcs

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
Struan76
Posts: 38
Joined: Tue Sep 03, 2019 7:38 am

Checking Sensor Arcs

Post by Struan76 »

Is there a way to check the arcs for a sensor through the console? If I am changing multiple units default sensor arcs I like do to a quick 'idiot check' to ensure I've added a new sensor correctly. For example if I add an ALQ-99 to an EA-6B with custom arcs using Sensors -> Add Sensor through the GUI, I haven't found a way to go back and check what I have done at a later time.

The best I can get for sensor description through the console is, example again:

Code: Select all

local u = ScenEdit_GetUnit({name='EA-18G Growler', guid='ActualUnitGUID'})
 print( u.sensors[8] )
this returns:

Code: Select all

{ sensor_isactive = 'Yes', sensor_name = 'AN/ALQ-99F-V [EA-18G C2W]', 
 sensor_guid = 'ActualSensorGUID', sensor_status = 'Operational', sensor_role = 4001, 
 sensor_maxrange = 0, sensor_type = 3002, sensor_dbid = 1901 }
User avatar
Struan76
Posts: 38
Joined: Tue Sep 03, 2019 7:38 am

RE: Checking Sensor Arcs

Post by Struan76 »

Here's how I'm adding a test OECM sensor:

Code: Select all

-- setup Growler arcs
 local u = ScenEdit_GetUnit({name='EA-18G Growler', guid='ActualUnitGUID'})
 ScenEdit_UpdateUnit({guid=u.guid,mode='remove_sensor',dbid=1901,sensorId=u.sensors[8].sensor_guid}) 
 -- need to work out how to remove default loadout sensor for above
 ScenEdit_UpdateUnit({guid=u.guid,mode='add_sensor',dbid=1901,arc_detect={'PB1','PB2','SB1','SB2'},arc_track={'PB1','PB2','SB1','SB2'}}) -- this is frontal 45deg sector only
 -- don't know yet how to check the above arcs are active
 u.obeyEMCON = false;    --Unit will not use emcon setting [required].
 local s = {sensor_guid=u.sensors[8].sensor_guid, sensor_isactive=true, sensor_status='Operational'};
 u.sensors = s;    --Apply changes for that specific sensor (turn on in this case)
 print( u.sensors[8])
(thanks to KnightHawk75 for second half of above code)
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Checking Sensor Arcs

Post by KnightHawk75 »

I don't know if you 'get' the arcs per-say, but since you're adding a sensor with specific ones, i'm not sure what you mean by check if the above arcs are active. I guess you mean if you say added several, and wanted to only activate certain ones it would be helpful if sensor object had sensor_arctrack sensor_arcdetect fields so you could maybe delineate between several otherwise duplicative entries.

That said as is, nope. I've always in cases of same sensor entries had to relay on index in the sensor table, which in my experience has been consistent in the .sensors returns, but then I have to remember in code index#Y is 0-30d and index#Z is 30-60 etc. You can determine index (or sensor_guid) and save it via say getting sensors by for instance only by specific dbid's into a new table adding an additional field called realindex and tacking the real overall index onto it. Then re-get the same for the sensors table after the successful updateunit() call and then you can find the difference between the tables to find the newly added entry and it's realindex(or sensor_guid), and then store that for later use in a global table you have for storing extra data per unit that you care about.
Yeah it's way more involved then it should be but it works.

Can provide some pseudo\example code for all that if need be.
User avatar
Struan76
Posts: 38
Joined: Tue Sep 03, 2019 7:38 am

RE: Checking Sensor Arcs

Post by Struan76 »

Thanks KH, if you are able to put up some sample code that would be great. IDK how to access the index in the sensor table..
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Checking Sensor Arcs

Post by KnightHawk75 »

IDK how to access the index in the sensor table
I bet you do, probably just over thinking what I mean.
local u = SE_GetUnit({guid=someguid}) --get unit.
u.sensors[1] -- access the first index\key in the sensors table. assuming there is at least 1
u.sensors[2] -- access the second index\key in the sensors table assuming there is at least 2
u.sensors[#u.sensors] --access the last index\key in the sensors table assuming there is at least 1.
-- sensors can change position as you remove odd ones, add new ones etc.

So I went little further that just some code, here is working scene example uses mainly sensor guid tracking more than indexes anyway (though the index can be handy at times so it saves that too).[:)]

Load the Individual_Sensor_Addressing.scen in the editor. You will be on side Blue, there are no units.
Load up your \Logs\LuaHistory ... you should see a bunch of successfully loaded xxxx.lua messages. If you don't we got problems. Then set your map settings to show all unit radars.
Press special action button. Press the 'Add USS KH2'. Now is good time to re-open that log and see what it just did. Press play. Wait at least 5 seconds. Watch the pretty radars flicker and change ever 5 seconds. Amazing what's so special about that? [8|]

Well it's that it's being done not by randomly picking a entry, but by randomly selecting based on extra data, in this case an arctype code, and finding the sensor with that arc on that unit. Part of the process after unit creation runs through the unit, removes the 3 spy radars that are there by default, and replaces them with 4 6051's variants. During each one of those add's is when the 'magic' happens in that we associate an arctype with each guid and new index and we store that for later use. In a nutshell that's really it.

People often ask for the code in text file form, with that in mind I implemented things such that that everything loads from the \Lua folder inside the included scene folder. This makes editing with external editors very simple while keeping things organized, the only thing embedded in the .scen is what has to be, the bootstrap code to load the scripts, and 1/2 a dozen lines total between the events and the special action.


Attached is SensorAddressingScene.zip it contains
Individual_Sensor_Addr_InstallationNotes.txt - just tells you to drag\drop SensorAddressingScene in anywhere under main Scenarios folder. It's important.
\SensorAddressingScene Folder - The folder containing the scene
\SensorAddressingScene\Individual_Sensor_Addressing.scen - The Scene file.
\SensorAddressingScene\Lua - Critical sub-folder containing 99% of the code.
\SensorAddressingScene\Lua\gKH.lua -- Couple of lines (stripped bare for this scene)
\SensorAddressingScene\Lua\gKH_base.lua - Couple dozen lines. (stripped bare for this scene)
\SensorAddressingScene\Lua\State.lua - Coupe hundred lines (but you can almost completely ignore it)
\SensorAddressingScene\Lua\SensorTracking_5064771.lua - The meat ~600 lines.

Don't freak out, of the total ~900 lines involved, 50% are comments another 25% probably error\parameter checking code.

SensorTracking_5064771.lua has a lot of information in comments as to what is going on and explicitly calls out the 3 main functions that relate to 'grabbing' the data you need, which may be all you are really interested in or need. ALL the rest is really just related to storing, and managing that data as well as "putting it to use" in the form of the radar flipper. I hope it's at least remotely similar to how you may be trying to use it. It does other stuff too like handle saving that "storage" and re-loading it on startup if you create a save file from it after you've added the unit etc.. again stuff you may not need, but a full-working example is better imho then just 3 functions thrown at you.

Scene Requires: DB3k 489, build 1.03.1147.29+
Attachments
SensorAddr..ingScene.zip
(29.17 KiB) Downloaded 27 times
User avatar
Struan76
Posts: 38
Joined: Tue Sep 03, 2019 7:38 am

RE: Checking Sensor Arcs

Post by Struan76 »

This is quite awesome...

Will take me a few days to work through this and understand it all!
Post Reply

Return to “Lua Legion”