ESAc_matador Posted December 27, 2016 Posted December 27, 2016 Hello guys. I am working in a script, and I want to make a table of red units with radars. My code is as simple as this. To make sure the list is completed, i call the mist.utils.tableshow() function. SamList = {} function getRadars() local redunits = mist.makeUnitTable({'[red][vehicle]'}) for k, v in pairs (redunits) do local Sam = redunits[k] -- trigger.action.outText(Sam,20) local Samobject = Unit.getByName(Sam) Samname = Samobject:getName() local Sam_sensors = Samobject:getSensors() if Sam_sensors ~= nil then if Samobject:hasSensors(Unit.SensorType.RADAR, Unit.RadarType.AS) then SamList[#SamList +1] = Samname end [color="Blue"][i][b]trigger.action.outText(mist.utils.tableShow(SamList),20)[/b][/i][/color] end end end getRadars() ANd it works, BUT. If I want to use the table SamList outside in other function... nothing happens for instance, this does not work. function getRadars() SamList = {} local redunits = mist.makeUnitTable({'[red][vehicle]'}) for k, v in pairs (redunits) do local Sam = redunits[k] -- trigger.action.outText(Sam,20) local Samobject = Unit.getByName(Sam) Samname = Samobject:getName() local Sam_sensors = Samobject:getSensors() if Sam_sensors ~= nil then if Samobject:hasSensors(Unit.SensorType.RADAR, Unit.RadarType.AS) then SamList[#SamList +1] = Samname end end end end getRadars() [color="blue"][i][b]trigger.action.outText(mist.utils.tableShow(SamList),20)[/b][/i][/color] any idea why??
0xDEADBEEF Posted December 27, 2016 Posted December 27, 2016 in the second example you are defining a global inside a function (SamList = {}). afaik it should still be a global, but that's the only thing I can think of. If you define SamList outside of the getRadars funciton (which you should do anyway, because you wanna access that gobally anyway I guess. this would work: SamList = {} function getRadars() local redunits = mist.makeUnitTable({'[red][vehicle]'}) for k, v in pairs (redunits) do local Sam = redunits[k] -- trigger.action.outText(Sam,20) local Samobject = Unit.getByName(Sam) Samname = Samobject:getName() local Sam_sensors = Samobject:getSensors() if Sam_sensors ~= nil then if Samobject:hasSensors(Unit.SensorType.RADAR, Unit.RadarType.AS) then SamList[#SamList +1] = Samname end end end end getRadars() trigger.action.outText(mist.utils.tableShow(SamList),20)
ESAc_matador Posted December 27, 2016 Author Posted December 27, 2016 in the second example you are defining a global inside a function (SamList = {}). afaik it should still be a global, but that's the only thing I can think of. If you define SamList outside of the getRadars funciton (which you should do anyway, because you wanna access that gobally anyway I guess. this would work: SamList = {} function getRadars() local redunits = mist.makeUnitTable({'[red][vehicle]'}) for k, v in pairs (redunits) do local Sam = redunits[k] -- trigger.action.outText(Sam,20) local Samobject = Unit.getByName(Sam) Samname = Samobject:getName() local Sam_sensors = Samobject:getSensors() if Sam_sensors ~= nil then if Samobject:hasSensors(Unit.SensorType.RADAR, Unit.RadarType.AS) then SamList[#SamList +1] = Samname end end end end getRadars() trigger.action.outText(mist.utils.tableShow(SamList),20) Thanks, i think, i tryed that already but I ll let you know. I have done many tabkes like this and this is the firat time this happens. Let see
ESAc_matador Posted December 28, 2016 Author Posted December 28, 2016 No way. It does not work... Grrrr!
0xDEADBEEF Posted December 28, 2016 Posted December 28, 2016 I've cleaned it up a little bit (Samobject:getName() is unnecessary, because you start with the name in the first place after all). Also there is one caveat, mist.makeUnitTable does not only return numbered indexes, but also has one index named "processed" which you wanna skip. That may have been the reason why it did not work. Also the "for in pairs" loop can be used more efficiently as you can see. env.info() just puts a line in the log which can be helpful to actually understand what your code is doing. This works fine: SamList = {} function getRadars() local redUnits = mist.makeUnitTable({'[red][vehicle]'}) env.info(mist.utils.tableShow(redUnits)) for i, unitName in pairs (redUnits) do if type(i) == "number" then -- makeUnitTable also has a ["processed"] = time index which does not represent a unit local samUnit = Unit.getByName(unitName) local samSensors = samUnit:getSensors() if samSensors then env.info("unit '"..unitName.."' has sensors") if samUnit:hasSensors(Unit.SensorType.RADAR, Unit.RadarType.AS) then env.info(" - also has Radar") table.insert(SamList, unitName) end end end end end getRadars() trigger.action.outText(mist.utils.tableShow(SamList),20) hope this helps.
ESAc_matador Posted December 29, 2016 Author Posted December 29, 2016 Just wanted to report, it works, perfect!
ESAc_matador Posted January 9, 2017 Author Posted January 9, 2017 it is curious... the above script is the initial step to collect all red units with Radar SAM... well. It works, only for the SA15 Tor, but it does not work for any other unit belonging to a SAM battery. Not even the SR or TR unit types. also this, does not work. It seems that getRadar does not work too in the following script. I want to make a script where aircrafts without EWR receive a warning sound. It works with SA15 Tor but not with full batteries as mentioned. function checkEWR(samunit) local UnitObject = Unit.getByName(samunit) if UnitObject ~= nil then local status, target = UnitObject:getRadar() if status == true then -- to see if the Radar is working if target ~= nil then -- to see if it is engaging local targetname = target:getName() for k, v in pairs(sabres) do local sabrename = sabres[k] if targetname == sabrename then -- to see if the tracked aircraft is the one on the list. sabrename = {} local targetID = target:getGroup():getID() trigger.action.outSoundForGroup(targetID, "alert.wav") trigger.action.outTextForGroup(targetID, "ALERT SAM!",20) end end end end end end
ESAc_matador Posted June 13, 2017 Author Posted June 13, 2017 (edited) So, I have been working hard looking for alternatives, but I also have the same problem. Only TORs are recognized. So this function does not work as it should. I would like to collect ALL RED UNITS WITH RADAR CAPABILITIES. Seems that hasSensors: and hasAtributes: does not work properly, I only get info from Tors... radarList = {} function getRadars() local redUnits = mist.makeUnitTable({'[red][vehicle]'}) for i, unitName in pairs (redUnits) do if type(i) == "number" then local samUnit = Unit.getByName(unitName) local samSensors = samUnit:getSensors() if samSensors then if samUnit:hasSensors(Unit.SensorType.RADAR, Unit.RadarType.AS) or samUnit:hasAttribute("SAM SR") or samUnit:hasAttribute("SAM TR") then env.info(" - also has Radar") table.insert(radarList, unitName) end end end end end getRadars() trigger.action.outText(mist.utils.tableShow(radarList),20) EDIT: Again... when I am done of trying something, i ask for a solution in the forums... and voilá!!! I found out the problem. This! caused the problem.... If I take it out, it works. gegrgrgrgrgrgrgrgr:cry::cry::cry::cry::cry::D:D:D:D radarList = {} function getRadars() local redUnits = mist.makeUnitTable({'[red][vehicle]'}) for i, unitName in pairs (redUnits) do if type(i) == "number" then local samUnit = Unit.getByName(unitName) local samSensors = samUnit:getSensors() [color="Red"]if samSensors then[/color] if samUnit:hasSensors(Unit.SensorType.RADAR, Unit.RadarType.AS) or samUnit:hasAttribute("SAM SR") or samUnit:hasAttribute("SAM TR") then env.info(" - also has Radar") table.insert(radarList, unitName) end [color="red"]end[/color] end end end getRadars() trigger.action.outText(mist.utils.tableShow(radarList),20) Edited June 13, 2017 by ESAc_matador
Grimes Posted June 13, 2017 Posted June 13, 2017 So, I have been working hard looking for alternatives, but I also have the same problem. Only TORs are recognized. So this function does not work as it should. I would like to collect ALL RED UNITS WITH RADAR CAPABILITIES. Seems that hasSensors: and hasAtributes: does not work properly, I only get info from Tors... Well I know there is a bug with getSensors() only returning the first unit in a ground group. Is that the case with your mission? I've used the function in my script to export all that stuff for the objectDB and it appears to be working aside for that bug. You doing this on 1.5 or 2.1? 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
ESAc_matador Posted June 15, 2017 Author Posted June 15, 2017 Well I know there is a bug with getSensors() only returning the first unit in a ground group. Is that the case with your mission? I've used the function in my script to export all that stuff for the objectDB and it appears to be working aside for that bug. You doing this on 1.5 or 2.1? Caucasus.... but I caught only Tors, more than one. Now I removed and works great. My jamming script is Nice!!!! Now I can do missions with both, standoff jamming and defensive jamming (based on your trinity misiles.... i created a bubble with diferente distances to specific aircraft, so you can protect your friendlies if they fly close to you!!!). The Offensive jamming, or standoff works with target detected.... and uses up to 6 different parameters to determine the probability of jamming the sam. Altitude of the target and the jammer (, distance between the Saam, the target and the jammer, everything related, position between the target, jammer and sam too simulating the lobe, pitch and bank of the jammer etc. Now I need to tweak the distance.... now is very simple, but I want to make a function.... to get more geometric relation to distance. Really worth it flying over a good IADS (and it's fully compatible with your IADS script. I use ROE off and State of Alarm off. Would be great to be able to remove a posible target from the SAM list. Is it possible?
Recommended Posts