hmleao Posted October 31, 2021 Posted October 31, 2021 Hello, guys. I'm doing some experimentation with scripting just for the fun of it and got stuck on a problem that I can't see an elegant solution. It's about updating the destiny point of an infrared pointer. I noticed the origin of the beam gets updated if you move the vehicle, but the end point does not. I was guessing to use trigger repetitive is a bad idea, so how I'd set up this? To keep things as simple as possible, I'll pass the reference from hoggit. Thanks for any directions. local jtac = Unit.getByName('jtacBob') local target = Unit.getByName('BMPAirDefenseSystemGroup1_unit1'):getPoint() local ray = Spot.createInfraRed(jtac, {x = 0, y = 1, z = 0}, target)
cfrag Posted October 31, 2021 Posted October 31, 2021 What you need to do is (after you created the spot) update the spot's (ray in your code) target coordinates regularly (say every half second or so) with the target's point by invoking ray:setPoint() 1
hmleao Posted October 31, 2021 Author Posted October 31, 2021 That's great, man. And how can I do that? like create a function and call it on a repetitive trigger or there's a better way?
toutenglisse Posted October 31, 2021 Posted October 31, 2021 1 hour ago, hmleao said: That's great, man. And how can I do that? like create a function and call it on a repetitive trigger or there's a better way? It is the way to do of the JTAC autolase script, available standalone or as part of CTLD ( all made by @Ciribob ). You can see inside this script how it is done (or use it !). (CTLD thread is just above in "sticky threads" list) 1
Grimes Posted November 1, 2021 Posted November 1, 2021 3 hours ago, hmleao said: That's great, man. And how can I do that? like create a function and call it on a repetitive trigger or there's a better way? https://wiki.hoggitworld.com/view/DCS_func_setPoint 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
hmleao Posted November 1, 2021 Author Posted November 1, 2021 That's great, exactly what I was looking for. Thank you so much.
Sedlo Posted November 2, 2021 Posted November 2, 2021 On 10/31/2021 at 5:46 PM, Grimes said: https://wiki.hoggitworld.com/view/DCS_func_setPoint Hey Grimes! I tried that script on the wiki local jtac = Unit.getByName('jtacBob') local target = Unit.getByName('BMPAirDefenseSystemGroup1_unit1') local ray = Spot.createLaser(jtac, {x = 0, y = 1, z = 0}, target:getPoint(), 1337) local function updateRay() if target:getLife() > 0 then ray:setPoint(target:getPoint()) timer.scheduleFunction(updateRay, {}, timer.getTime() + 0.5) else ray:destroy() end end timer.scheduleFunction(updateRay, {}, timer.getTime() + 0.5) , and once the target gets killed I get a mission script error: SCRIPTING: Mission script error: [string " local jtac = Unit.getByName('jtacBob')..."]:5: Unit doesn't exist stack traceback: [C]: ? [C]: in function 'getLife' [string " local jtac = Unit.getByName('jtacBob')..."]:5: in function <[string " local jtac = Unit.getByName('jtacBob')..."]:4> jtacBob is still up there, the target (BMPAirDefenseSystemGroup1_unit1) is the one destroyed. Not sure what's going on here, mabye getLife is weird? My Youtube Channel MY DCS MISSIONS
Grimes Posted November 2, 2021 Posted November 2, 2021 Forgot that it tends to not like it if you do a deadObject:function. Changed it slightly to Object.isExist(target) which should get the desired results. Was actually a little curious to see if LST/LSS works and sure enough it does. Can even guide weapons via it fairly reliably. 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
Sedlo Posted November 2, 2021 Posted November 2, 2021 6 hours ago, Grimes said: Forgot that it tends to not like it if you do a deadObject:function. Changed it slightly to Object.isExist(target) which should get the desired results. Was actually a little curious to see if LST/LSS works and sure enough it does. Can even guide weapons via it fairly reliably. That did the trick! Thanks! My Youtube Channel MY DCS MISSIONS
hmleao Posted November 3, 2021 Author Posted November 3, 2021 (edited) Since we're talking about some weird behavior of some stuff, maybe Grimes could be so kind as to explain why some times you get some 'nil' units from detectedTargets(). I've made a script with your tip from before that auto marks targets and all is cool, but sometimes when killing some units this error show up. I could solve it without many problems just doing an "if target ~= nil". It's not a big deal, but I wonder if I've made some mistake because I wouldn't think that function would get me "nil" table units. My question is if this is normal or I may have made some mistake. The script only gets the detected targets and uses a for loop to do some stuff, and here and there when killing some of them I get the "nils". Thanks for any tips. Edited November 3, 2021 by hmleao
Grimes Posted November 3, 2021 Posted November 3, 2021 A code example or the types of targets might help to clarify. Just a few thoughts though: If you are calling getDetectedTargets once to build a table and then iterate over that table or getDetectedTargets is returning nil values on each run. If it is the latter then that is where knowing the targets matters. I believe there have been changes made where "dead" objects register at different times. Part of this is if using events you may see a unit_lost event before the unit is fully destroyed. It isn't the worst thing in the world to verify your object is still accessible before running code on it simply to avoid errors or extra processing. In your example if target then ought to be enough. If I wrote it differently on the wiki the "test" could just have been if Unit.getByName('BMPAirDefenseSystemGroup1_unit1') then as part of the function that gets called. Honestly don't know if one is faster than another because it takes microseconds to do, but technically stuff like that can add up. Either is fine for most use cases anyway. Through a quick and dumb test that some functions can still work on a "dead" unit while others will error. Initially I thought it could be a difference between unit:getLife() and Unit.getLife(unit), but that doesn't seem to be the case. I would need to spend more time on this to get a thorough answer for which functions can still return something on dead objects and possible add that info to the wiki. At the basics isExist can be relied upon, but other than that I don't know. 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
hmleao Posted November 3, 2021 Author Posted November 3, 2021 Sorry, I should have posted the function where I got this error. The targets are one group of trucks, one of IFVs, one of BMPs and one of tanks. just a mission quickly assembled in ME to test it. What I was doing is saving some group information in a table so I could smoke some unit of that group again after a set time. -- adds unique detected groups to memory local function addGroupsMemory (detectedTargets) for _, target in pairs(detectedTargets) do if target then local inMemory = false target = target.object local targetGroupName = target:getGroup():getName() for _, markedGroup in pairs(MARKED_GROUPS) do if markedGroup.name == targetGroupName then inMemory = true break end end if not inMemory then local groupInfo = {} groupInfo.name = targetGroupName groupInfo.timeMarked = timer.getTime() table.insert(MARKED_GROUPS, groupInfo) end end end end the detected targets parameter there is just called in another function, no other processing with it local detectedTargets = Controller.getDetectedTargets(jtac) addGroupsMemory (detectedTargets) But you answered my question already. The function might give me some nil tables, so just verify with if target then before running the rest of the script. Looked like a good idea, but actually a group can be pretty scattered xD. I'll try to come up with something to solve this. Thanks again, Grimes
Recommended Posts