Newby Switch 1 sensor on/off
Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command
Newby Switch 1 sensor on/off
As a newby I'm trying some stuff in LUA. With that some questions arise:
Would it be possible to switch just 1 radar on? This instead of EMCON radar active.
Would it be possible to have a condition where somthing happens when a specific radar is on?
If it are stupid questions please discard them. Thx
with regards
Would it be possible to switch just 1 radar on? This instead of EMCON radar active.
Would it be possible to have a condition where somthing happens when a specific radar is on?
If it are stupid questions please discard them. Thx
with regards
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Newby Switch 1 sensor on/off
These are not stupid questions.
Can you via LUA switch only a given sensor on? Nope, and it's a shame that the unitwrapper sensors data is read-only with no way to change a specific sensor's active state, that I know of anyway via LUA. I very much would like such a feature in LUA that the GUI offers.
Can you via LUA query the current state of a sensor\type (if it's on\off or operational) and act on that? Yes you can.
To do the latter you just want to enum through the sensors table and take whatever action you want.
One thing to note is the display of _isactive via a print(u.sensors) shows 'Yes'|'No' but the real value is a boolean.
The only way I've overcome the first thing you wanted to do (specific sensors on\off), is to have scripts that literally remove what I don't want active, set the emcon to active, and then have another that re-inserts all the stuff I removed later and or removes all and inserts whats needed at later time. I don't recommend it though, more trouble than it's worth 9/10 times. The one time I did that that didn't involve more code than it was worth was comms-jammer related where I didn't want it active just cause normal jammers were active, so i scripted the adding of the sensor when I wanted it (based upon location), and the removal of the sensor when I wanted it off (was out of an area). An alternative option is temporary 'damaging' the components you want off, and resetting the 'damage' later, but I always worried about possible side effects of damaging too many components maybe effecting other things - you can try it I guess.
Can you via LUA switch only a given sensor on? Nope, and it's a shame that the unitwrapper sensors data is read-only with no way to change a specific sensor's active state, that I know of anyway via LUA. I very much would like such a feature in LUA that the GUI offers.
Can you via LUA query the current state of a sensor\type (if it's on\off or operational) and act on that? Yes you can.
To do the latter you just want to enum through the sensors table and take whatever action you want.
Code: Select all
local u = ScenEdit_GetUnit({name='CVN 81 Doris Miller', guid='4FH7PU-0HLUV5M8KE9CG'})
--print(u.sensors) --if you want to see the table
for i,v in pairs(u.sensors) do
if (v.sensor_dbid==5981 and v.sensor_isactive == true) then
--DoSomething();
print('did something!')
end
end
u = nil
The only way I've overcome the first thing you wanted to do (specific sensors on\off), is to have scripts that literally remove what I don't want active, set the emcon to active, and then have another that re-inserts all the stuff I removed later and or removes all and inserts whats needed at later time. I don't recommend it though, more trouble than it's worth 9/10 times. The one time I did that that didn't involve more code than it was worth was comms-jammer related where I didn't want it active just cause normal jammers were active, so i scripted the adding of the sensor when I wanted it (based upon location), and the removal of the sensor when I wanted it off (was out of an area). An alternative option is temporary 'damaging' the components you want off, and resetting the 'damage' later, but I always worried about possible side effects of damaging too many components maybe effecting other things - you can try it I guess.
RE: Newby Switch 1 sensor on/off
Knighthawk75, thank you for youre time and answer. Gonna try this evening.
Another question and I think it isn't possible but just to be sure.
Could you change sensor parametrics? Like the Freqency band of an ES system, or it's SEI feature.
I think not all countries have the complete set, form manafacture date, on all there ships.
with regards
Another question and I think it isn't possible but just to be sure.
Could you change sensor parametrics? Like the Freqency band of an ES system, or it's SEI feature.
I think not all countries have the complete set, form manafacture date, on all there ships.
with regards
- michaelm75au
- Posts: 12463
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Newby Switch 1 sensor on/off
The values parameters of the sensor are as per the database; changing them could cause issues.
Two enhancements to come would be Lua options to set sensors active/passive, and also to change the 'obey EMCON' value on the unit. If it set to obey, it may not be able to turn on radars.
Two enhancements to come would be Lua options to set sensors active/passive, and also to change the 'obey EMCON' value on the unit. If it set to obey, it may not be able to turn on radars.
Michael
RE: Newby Switch 1 sensor on/off
oke, thx
RE: Newby Switch 1 sensor on/off
Like I said I'm new in this. I run this to get damage on a radar if that radar is shining:
local u = ScenEdit_GetUnit({name='TRMP', guid='50PVO4-0HLUVH90BEIED'})
--print(u.sensors) --if you want to see the table
for i,v in pairs(u.sensors) do
if (v.sensor_dbid==5981 and v.sensor_isactive == true) then
--DoSomething();
ScenEdit_SetUnitDamage({
side='Blue',
unitname='TRMP',
components={ {'SMART-L EWC [BMD Mod]', 'light'} } })
print('damage')
end
end
u = nil
Is this not very smart or did I forget something somewhere? It doesn't give an error but is isn't changing anything.
Hoping for advice
with regards
local u = ScenEdit_GetUnit({name='TRMP', guid='50PVO4-0HLUVH90BEIED'})
--print(u.sensors) --if you want to see the table
for i,v in pairs(u.sensors) do
if (v.sensor_dbid==5981 and v.sensor_isactive == true) then
--DoSomething();
ScenEdit_SetUnitDamage({
side='Blue',
unitname='TRMP',
components={ {'SMART-L EWC [BMD Mod]', 'light'} } })
print('damage')
end
end
u = nil
Is this not very smart or did I forget something somewhere? It doesn't give an error but is isn't changing anything.
Hoping for advice
with regards
- michaelm75au
- Posts: 12463
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Newby Switch 1 sensor on/off
ScenEdit_SetUnitDamage({name='AOE 421 Sagami', guid='004aa55d-d553-428d-a727-26853737c8f4',
components={ {'8aa88870-45ff-42a9-bf7f-8b8466bc9b5a','Medium'} }
})
You need to use the GUID in order to damage specific components.
components={ {'8aa88870-45ff-42a9-bf7f-8b8466bc9b5a','Medium'} }
})
You need to use the GUID in order to damage specific components.
Michael
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Newby Switch 1 sensor on/off
Assuming a an/spy-3 #5981 in on the unit then I think the SetUnitDamange() parameters may need to include the component id\guid of the specific sensor you want damaged. You can get that via u.components table though in this case I believe the comp_guid in that table and sensor_guid in sensor table are the same so you should already have the guid needed via v.sensor_guidORIGINAL: Parel803
Like I said I'm new in this. I run this to get damage on a radar if that radar is shining:
local u = ScenEdit_GetUnit({name='TRMP', guid='50PVO4-0HLUVH90BEIED'})
--print(u.sensors) --if you want to see the table
for i,v in pairs(u.sensors) do
if (v.sensor_dbid==5981 and v.sensor_isactive == true) then
--DoSomething();
ScenEdit_SetUnitDamage({
side='Blue',
unitname='TRMP',
components={ {'SMART-L EWC [BMD Mod]', 'light'} } })
print('damage')
end
end
u = nil
Is this not very smart or did I forget something somewhere? It doesn't give an error but is isn't changing anything.
Hoping for advice
with regards
There is an example michaelm75au provided in the past here:
https://www.matrixgames.com/forums/tm.a ... key=sensor&#
RE: Newby Switch 1 sensor on/off
Thx again all. gonna try.
regards
regards
RE: Newby Switch 1 sensor on/off
I'm sorry, still no change in my sensor under Damage Ctrl of the unit.
local u = ScenEdit_GetUnit({name='TRMP', guid='50PVO4-0HLUVOSEN0PJB'})
-- print(u.sensors) --if you want to see the table
for i,v in pairs(u.sensors) do
if (v.sensor_Guid==5981 and v.sensor_isactive == true) then
--DoSomething();
ScenEdit_SetUnitDamage ({name='TRMP', guid='50PVO4-0HLUVOSEN0PJB', components={ {'50PVO4-0HLUVOSEN0PJI', 'medium'} } } )
print('damage')
end
end
u = nil
No error, no print.
tried to be more extensive in the SetUnitDamage line cf other post, looked like the same result.
Hoping you can help again
with regards
local u = ScenEdit_GetUnit({name='TRMP', guid='50PVO4-0HLUVOSEN0PJB'})
-- print(u.sensors) --if you want to see the table
for i,v in pairs(u.sensors) do
if (v.sensor_Guid==5981 and v.sensor_isactive == true) then
--DoSomething();
ScenEdit_SetUnitDamage ({name='TRMP', guid='50PVO4-0HLUVOSEN0PJB', components={ {'50PVO4-0HLUVOSEN0PJI', 'medium'} } } )
print('damage')
end
end
u = nil
No error, no print.
tried to be more extensive in the SetUnitDamage line cf other post, looked like the same result.
Hoping you can help again
with regards
- michaelm75au
- Posts: 12463
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Newby Switch 1 sensor on/off
It may help to post a SCEN or SAVE file, and we can show you the specific commands. Bit hard this to-ing and fro-ing.[:D]
Michael
RE: Newby Switch 1 sensor on/off
Micheal,
Thx, both of you, helping me out. Next time I'll post the scenario earlier on. Do realize that it's starting to become a bit much.
Thx, both of you, helping me out. Next time I'll post the scenario earlier on. Do realize that it's starting to become a bit much.
- Attachments
-
- TestIfThen.zip
- (9.77 KiB) Downloaded 23 times
- michaelm75au
- Posts: 12463
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Newby Switch 1 sensor on/off
You were looking for a specific database id (dbid), but it was spelt wrong.
You could also damage the one you found, rather use a specific guid. That way if you have multiple devices of the same, you can disable first active one you find.
You could also damage the one you found, rather use a specific guid. That way if you have multiple devices of the same, you can disable first active one you find.
local u = ScenEdit_GetUnit({name='TRMP', guid='50PVO4-0HLV08MKPKCJL'})
print(u.sensors) --if you want to see the table
for i,v in pairs(u.sensors) do
if (v.sensor_dbid==5195 and v.sensor_isactive == true) then
--DoSomething();
ScenEdit_SetUnitDamage ({guid='50PVO4-0HLV08MKPKCJL', components={ {v.sensor_guid, 'medium'} } } )
print('damage')
end
end
u = nil
Michael
RE: Newby Switch 1 sensor on/off
Thank you.
A learning moment (more to follow, i'm afraid)
with regards
A learning moment (more to follow, i'm afraid)
with regards
Re: Newby Switch 1 sensor on/off
There actually is a way to turn an individual sensor on or off using Lua. The documentation for this feature in the Command Lua Docs is light but a method can be divined using the note provided in http://commandlua.github.io/#table_Sensor.
The method is to set the 'sensors' property of the unit to a table which contains the 'sensor_guid' and 'sensor_isactive' fields. An example is shown below.
unit = ScenEdit_GetUnit( { guid='GUIDOFMYUNIT' } )
sensorid = unit.sensors[ 1 ].sensor_guid -- get sensor guid for first sensor
unit.sensors = { sensor_guid=sensorid, sensor_isactive=false } -- turn off sensor
This method turns on/off a sensor regardless of the current EMCON doctrine. For example, it will ignore the "Unit obeys EMCON" checkmark and allow you to manually turn sensors on/off where in the user interface you would not be allowed to until you uncheck "Unit obeys EMCON".
The method is to set the 'sensors' property of the unit to a table which contains the 'sensor_guid' and 'sensor_isactive' fields. An example is shown below.
unit = ScenEdit_GetUnit( { guid='GUIDOFMYUNIT' } )
sensorid = unit.sensors[ 1 ].sensor_guid -- get sensor guid for first sensor
unit.sensors = { sensor_guid=sensorid, sensor_isactive=false } -- turn off sensor
This method turns on/off a sensor regardless of the current EMCON doctrine. For example, it will ignore the "Unit obeys EMCON" checkmark and allow you to manually turn sensors on/off where in the user interface you would not be allowed to until you uncheck "Unit obeys EMCON".
Re: Newby Switch 1 sensor on/off
Correction: Although you can set this and you can read that it changes, EMCON will overrule these setting as soon as the simulation starts. For this to work, it is necessary to uncheck "Unit obeys EMCON". I have not found a Lua command for accomplishing this yet.
Re: Newby Switch 1 sensor on/off
obeyEMCON is a property of a Unit. This can be set simply by setting the property as it appears to be read/write.
For example,
unit = ScenEdit_GetUnit( { guid='GUIDOFMYUNIT' } )
unit.obeyEMCON = false -- do not obey EMCON
For example,
unit = ScenEdit_GetUnit( { guid='GUIDOFMYUNIT' } )
unit.obeyEMCON = false -- do not obey EMCON
Re: Newby Switch 1 sensor on/off
Thx for the onfo, gonna read it this evening
best regards GJ
best regards GJ
- michaelm75au
- Posts: 12463
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
Re: Newby Switch 1 sensor on/off
To turn off unit EMCONProGenA wrote: Thu Aug 18, 2022 12:45 am Correction: Although you can set this and you can read that it changes, EMCON will overrule these setting as soon as the simulation starts. For this to work, it is necessary to uncheck "Unit obeys EMCON". I have not found a Lua command for accomplishing this yet.
.obeyEMCON = false
Michael
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
Re: Newby Switch 1 sensor on/off
----There actually is a way to turn an individual sensor on or off using Lua.
Yes, it was added to the game after the original thread was posted, you can disable individual sensors but please note, you still can't enable\disable them properly in 1.04.xxxx reliably because the damn ai overrides your settings at times depending what it deems are incoming threats and other settings you may have set (ie you could turn off FCR radars but they're gonna come on by default even if you do if certain things are happening). So the only truly effective way is to destroy\damage the individual sensor, keep track of that destruction, and then reverse that before turning it back on. Have not looked at recent betas but I suspect that same issue remains...where simply manually turning something off does not make it stay off in all cases.