Snacko Posted October 11, 2023 Posted October 11, 2023 (edited) I've been playing with setting up Triggers in a Mission to flip switches, etc.. in the FA-18 Cockpit. I've got a few working. But I also want to be able to use the script/Triggers in other missions. So, I'd rather make a Script, than use Triggers. I see a lot of posts about this, but no 'complete' mission script files. I've see commands like push_start_command() and push_stop_command() and in my mission the Triggers use ie. [7] = "a_cockpit_perform_clickable_action(23, 3002, 1, \"\"); mission.trig.func[7]=nil;", Are there any 'examples' out there that show the basic format for doing this in a Script? Like what other code do I need to set the script up? ie Do I need to declare any vars or functions in my script? Thanks. Edited October 11, 2023 by Snacko Snack Officer Intel I9-10850K (OC @ 5.0ghz) │ 64GB (4x16GB) DDR4 3200 │Gigabyte RTX 4090 Gaming OC 24gb - ҉ - Blackshark Cockpit Trainer - ҉ - ♣ Thread | ♥ Download
Solution cfrag Posted October 12, 2023 Solution Posted October 12, 2023 (edited) 19 hours ago, Snacko said: Are there any 'examples' out there that show the basic format for doing this in a Script? Currently, there are multiple issue, and have been since DCS's inception that need to be overcome: There isn't an official, formalized API to access cockpit instruments from LUA script (MSE - mission scripting environment) that can be used to pass commands to the currently running cockpit/module. All these 'perform_clickable_action()' use unofficial and undocumented, well, hacks (for lack of a better word, even if vendor-supplied) that are specific to the model that the player is currently flying (rather: the aircraft that the mission was originally designed for). They are therefore not multiplayer-compatible and do not work across multiple aircraft and aren't portable to other missions It will be a fine day indeed if and when ED release a cross-module, fully functioning cockpit API that would allow missions to script something along the lines of unit:setControl("Throttle", 1, 0.5) - which would set that unit's throttle 1 (if it exists) to 50%. Alas, today we can merely dream. 19 hours ago, Snacko said: Do I need to declare any vars or functions in my script? Even if you don't, I strongly recommend to stay away from trying this. You might succeed in getting some of those hacks to work, but you won't know for how long, will spend a lot of time tracking those down, usually don't know why they work at all, and each time there is an update you run the 'will it still work' fun lottery. Not to mention that it probably will not work for any other plane type, and definitely not in multiplayer (I'm a multi-plane, multiplayer guy, so I tend to eschew single-type, single-player scripts; you may not be deterred by that) If you truly want to start your hunt for those triggers, set up a mission that uses a cockpit trigger, then analyse the "mission" file's code inside the .miz archive. Look for ["trig"] = end make the best out of it that you can. Those are the trigger definitions, set up as a mission-wide table. I myself did not find that a particularly fun task, but maybe you are more stubborn than I Edited October 12, 2023 by cfrag 1 1
Snacko Posted October 12, 2023 Author Posted October 12, 2023 (edited) Thanks for that awesome explanation! I am pretty stubborn... But from what you said here, I think I can just make a bunch of triggers in the mission builder, and then copy them into other .miz files for that aircraft. And also put a condition in for that trigger that only works for that aircraft type. I guess that will be my focus on how to handle this for now. Thanks for the great info again! Edited October 12, 2023 by Snacko Snack Officer Intel I9-10850K (OC @ 5.0ghz) │ 64GB (4x16GB) DDR4 3200 │Gigabyte RTX 4090 Gaming OC 24gb - ҉ - Blackshark Cockpit Trainer - ҉ - ♣ Thread | ♥ Download
cfrag Posted October 13, 2023 Posted October 13, 2023 (edited) 17 hours ago, Snacko said: I think I can just make a bunch of triggers in the mission builder, and then copy them into other .miz Theoretically yes. Note that each mission sets up a table with the actions that you have set up in ME with absolute numbers. I have attached a simple mission that uses actions to set active pause after 2 seconds, and full pause after 13. When you look at the trigger action definitions in the mission file, note that they are defined thusly: ["trig"] = { ["actions"] = { [1] = "a_set_command(816); mission.trig.func[1]=nil;", [2] = "a_set_command_with_value(52, -1); mission.trig.func[2]=nil;", }, -- end of ["actions"] and their conditions ["conditions"] = { [1] = "return(c_time_after(2) )", [2] = "return(c_time_after(13) )", }, -- end of ["conditions"] Since ME uses static numbers for assigning table elements, take very good care when you copy your own set over to an existing mission or you will overwrite existing actions/commands, creating very, very difficult-to-detect and trouble-shoot bugs (not to mention head-ache while designing your code to set up unique indices for each action/condition 17 hours ago, Snacko said: And also put a condition in for that trigger that only works for that aircraft type. Ah, and here comes the next fun bit: try to determine which aircraft you (the player) are currently flying. If your mission only allows one type of aircraft, that information is implicit with the mission, and you are home. If you allow your player to fly multiple different aircraft (as I like to do) in the same mission, you will quickly find out that there is no concept of "I" or "me" in client scripts (there's actually a good reason for this, but it is explained nowhere in DCS documentation. The reason for this is so that the same MSE script can run on any client in multiplayer, and it is a smart concept. I'll digress here except noting the result: no concept of "I" or "me" for any client script). Therefore, if you try and code the part where you want to decide if you should allow a trigger or not, you will find out that you have no viable condition that can decide which plane you are flying. One possible work-around is to make a mission single-player only (with multiple plane choices), and then home in on the 'birth' event for the player aircraft. Look at that aircraft and then set your type-dependent trigger enablers. This will not work in multiplayer. Yes, it will be tedious, but when you get some progress, enjoy that sweet, sweet feeling of accomplishment and success cockpit command tester.miz Edited October 13, 2023 by cfrag 1
Snacko Posted October 13, 2023 Author Posted October 13, 2023 (edited) Awesome!! Thanks so much for your help cfrag!! I was able to set the aircraft type by just putting a zone below each aircraft (F18 & F16) and that worked fine. And I do understand about the arrays all matching their indices.. I'm a retired programmer, so I understand these concepts. And since I don't want to get into managing the dictionary, I will manually add messages in the Mission Editor after I have added these triggers into the mission file. I started this all just to have a mission setup for anyone that I show my rig to, and let fly. They all immediatly want to blow sh1t up, and I want it setup and ready to go when they spawn in.. And sometimes I'll use that as well. Thanks again for your help!! Cheers mate!! Edited October 13, 2023 by Snacko Snack Officer Intel I9-10850K (OC @ 5.0ghz) │ 64GB (4x16GB) DDR4 3200 │Gigabyte RTX 4090 Gaming OC 24gb - ҉ - Blackshark Cockpit Trainer - ҉ - ♣ Thread | ♥ Download
Recommended Posts