ShaunX Posted July 10, 2021 Posted July 10, 2021 I have a requirement as part of a project to programatically insert a trigger into a mission (.miz file). I've no experience of this but it looks like I'd just need to unzip the file in code and then edit its "mission" file to insert the trigger ("trig") block and any other required code. So my plan would be to create a mission in ME and add the trigger in the usual way, then open the mission file and copy the code that the ME had inserted for the trigger which I could then use in my program. Can anyone with experience of doing this confirm please ? or am I missing something and there is another way do do this ? Thanks in advance RYZEN 5900X | 32GB | ASUS Strix RTX3090 | 500GB NVMe OS 1000GB NVMe DCS | Warthog HOTAS | HP Reverb G2 | VA & ViacomPRO My DCS Apps: Radio KAOS for DCS KB Quick - Quick and Easy Kneeboards
cfrag Posted July 10, 2021 Posted July 10, 2021 Missions are written in pretty standard xml, and the reside inside the 'mission' file inside a .miz archive, just like you indicated. You can simply read, add and remove triggers provided you don't mess up the xml context. This is especially important since the mission file seems to construct triggers from snippets of pseudo code for each action and conditions (see 'actions', 'func' and other tags defined within) that are referenced from the 'trig' tag contents. Try the following: Create a mission with a single trigger (for example activate a unit 10 seconds after some flag was set), and save away the mission xml. Then, using ME, add another trigger, for example set a flag when a unit is inside a trigger zone, and again extract the xml. Then run a diff on the two mission xml versions to see just what you are up against. Then have a cold one to calm down. Since what you seem to be doing happens outside the time that the mission is actually running, methinks that unless you are writing a pre-processor or mission generator similar to the great 'Liberation' dynamic campaign, it would be much easier to simply use ME. Structurally, triggers look like a big hack to me, so IMHO you'd be much better off writing straight lua. 1
Grimes Posted July 10, 2021 Posted July 10, 2021 If you know the format and all the required entries for a trigger sure, it can be done. Its just a big lua table. Most I've done was extract the mission and update the coordinates for a specific unit. But there are scripts out there that inject real time weather and time of day into missions. 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
ShaunX Posted July 11, 2021 Author Posted July 11, 2021 17 hours ago, cfrag said: Missions are written in pretty standard xml, and the reside inside the 'mission' file inside a .miz archive, just like you indicated. You can simply read, add and remove triggers provided you don't mess up the xml context. This is especially important since the mission file seems to construct triggers from snippets of pseudo code for each action and conditions (see 'actions', 'func' and other tags defined within) that are referenced from the 'trig' tag contents. Try the following: Create a mission with a single trigger (for example activate a unit 10 seconds after some flag was set), and save away the mission xml. Then, using ME, add another trigger, for example set a flag when a unit is inside a trigger zone, and again extract the xml. Then run a diff on the two mission xml versions to see just what you are up against. Then have a cold one to calm down. Since what you seem to be doing happens outside the time that the mission is actually running, methinks that unless you are writing a pre-processor or mission generator similar to the great 'Liberation' dynamic campaign, it would be much easier to simply use ME. Structurally, triggers look like a big hack to me, so IMHO you'd be much better off writing straight lua. Thanks, this is really useful and I will certainly take your advice and run some diffs before anything else. You're correct in that the app I'm planning is a standalone which, in order to function, needs to be able to insert a very simple, generic trigger task into any mission file (and potentially update it or remove it again as required by the user). That's the extent of its interaction with DCS components. RYZEN 5900X | 32GB | ASUS Strix RTX3090 | 500GB NVMe OS 1000GB NVMe DCS | Warthog HOTAS | HP Reverb G2 | VA & ViacomPRO My DCS Apps: Radio KAOS for DCS KB Quick - Quick and Easy Kneeboards
ShaunX Posted July 11, 2021 Author Posted July 11, 2021 41 minutes ago, ShaunX said: Thanks, this is really useful and I will certainly take your advice and run some diffs before anything else. You're correct in that the app I'm planning is a standalone which, in order to function, needs to be able to insert a very simple, generic trigger task into any mission file (and potentially update it or remove it again as required by the user). That's the extent of its interaction with DCS components. Ah right, took your advice and ran some diffs. I'd have that cold one now if it wasn't 07:00 So I guess it's a tad trickier than I'd hoped RYZEN 5900X | 32GB | ASUS Strix RTX3090 | 500GB NVMe OS 1000GB NVMe DCS | Warthog HOTAS | HP Reverb G2 | VA & ViacomPRO My DCS Apps: Radio KAOS for DCS KB Quick - Quick and Easy Kneeboards
ShaunX Posted July 12, 2021 Author Posted July 12, 2021 Ok so I think I've worked out format and entries that need to be added to insert a trigger. Anyone know how the "currentKey" field in the mission file is calculated ? It's certainly increased following an addition but not obvious by how much. Maybe just a case of adding my generic trigger to various missions of different complexity in the ME and see if it always increments by the same amount I guess RYZEN 5900X | 32GB | ASUS Strix RTX3090 | 500GB NVMe OS 1000GB NVMe DCS | Warthog HOTAS | HP Reverb G2 | VA & ViacomPRO My DCS Apps: Radio KAOS for DCS KB Quick - Quick and Easy Kneeboards
Recommended Posts