Mistermann Posted February 3 Posted February 3 I am no Lua wizard - far from it actually. I am able to stumble my way around other's code like an intoxicated coed at their first college party. That being said, I have randomly spawned groups on the map using MIST "mist.respawnInZone" functionality. I am using the random zone functionality of this feature meaning I can't predict where the group appears on the map. When a group dies, I want to cause an explosion in the group and put down a smoke effect. The code below is my first pass and I have it working: function I2J.smokeEffects(_randoGroup, _unitName) if Group.getByName(_randoGroup) then local _smokeDensity = 1 local _smokePreset = 6 -- 1 = small smoke and fire, 2 = medium smoke and fire, 3 = large smoke and fire, 4 = huge smoke and fire, 5 = small smoke, 6 = medium smoke , 7 = large smoke, 8 = huge smoke local _explosionPower = 50 local targetCoord = Unit.getByName(_unitName):getPoint() -- get coordinates of passed unit trigger.action.effectSmokeBig(targetCoord, _smokePreset, _smokeDensity) -- put down smoke effect on passed unit trigger.action.explosion(targetCoord, _explosionPower ) -- explosion effect over passed unit end end I would ideally like to just pass the group name and have the function figure out the first unit's name in order to get the position. I just can't seem to find any understandable examples for me to leverage. Anyone out there care to enlighten this old timer? Thanks. System Specs: Spoiler Callsign:Kandy Processor:13th Gen Intel(R) Core(TM) i9-13900K - RAM: 64GB - Video Card: NVIDIA RTX 4090 - Display: Pimax 8kx VR Headset - Accessories: VKB Gunfighter III MCG Ultimate, VKB STECS Standard, Thrustmaster TPR Pedals, Simshaker JetPad, Predator HOTAS Mounts, 3D Printed Flight Button Box Video Capture Software: Open Broadcaster Software (OBS), Video Editing Software: PowerDirector 365 Into The Jungle Apache Campaign - Griffins Kiowa Campaign - Assassins Thrustmaster TWCS Mod
Solution cfrag Posted February 4 Solution Posted February 4 16 hours ago, Mistermann said: When a group dies, I want to cause an explosion in the group and put down a smoke effect. I believe that the following question may lead you to the answer: Q: How do you known that a group died? A: when the last unit from that group dies. And that is the answer to your question: A group does not have a location, it has many units, and each of them has a their own location (in naval groups, they can be miles apart, as can be in aerial groups). So, the condition "when a group dies" could be better written as "when the last unit of a group dies". And that you can catch, by intercepting the unitLost or dead event. Now, be *very* careful when looking at dead events for ground units, because DCS can pull an undocumented fast one on you: it changes a ground unit into a static object that "cooks off". So what's the big deal? Well, a static objects has no group, and your script dies when it tries to access a static's group. So although what you are trying to do would usually be a simple thing, for people who aren't very comfortable in DCS mission scripting, it will become a very frustrating experience. What you need to do is some "threading the needle" stuff: when groups spawn, keep a table that links each unit's name back to it's group name. When you receive a dead or unit lost event, get the group name from the table (not from the object, it could be a static), get the number of remaining units in the group. If it's zero, the last unit died, and you can remove the group from your table, and place the explosion and smoke on the location of the object that just dies. It's going to be a lot of work for a simple thing. But it may be a learning experience, and even fun.
Mistermann Posted February 4 Author Posted February 4 In that case I think I'll stick with my hack of passing a unit name. I have a mission trigger looking for group death, so I run the function above as a do script. I just have to know a unit to get the position. Much easier than writing a bunch of code - inelegant as it is. Thank you, cfrag! System Specs: Spoiler Callsign:Kandy Processor:13th Gen Intel(R) Core(TM) i9-13900K - RAM: 64GB - Video Card: NVIDIA RTX 4090 - Display: Pimax 8kx VR Headset - Accessories: VKB Gunfighter III MCG Ultimate, VKB STECS Standard, Thrustmaster TPR Pedals, Simshaker JetPad, Predator HOTAS Mounts, 3D Printed Flight Button Box Video Capture Software: Open Broadcaster Software (OBS), Video Editing Software: PowerDirector 365 Into The Jungle Apache Campaign - Griffins Kiowa Campaign - Assassins Thrustmaster TWCS Mod
Recommended Posts