VR Flight Guy in PJ Pants Posted April 21, 2022 Posted April 21, 2022 I am using the same set of scripts across different maps, and there are quite a lot of triggers and each of them is rather long. Should I use LUA scripts instead? If so, how to I start? Example: 1 I Fly, Therefore I Am. One cannot go around not saying "Thank you" every time these days, can't you? YouTube: https://www.youtube.com/channel/UCc9BDi-STaqgWsjNiHbW0fA
fargo007 Posted April 21, 2022 Posted April 21, 2022 1 Have fun. Don't suck. Kill bad guys. https://discord.gg/blacksharkden/
VR Flight Guy in PJ Pants Posted April 21, 2022 Author Posted April 21, 2022 (edited) So, how or where do I start? Any example, please? Edited April 21, 2022 by VR Flight Guy in PJ Pants I Fly, Therefore I Am. One cannot go around not saying "Thank you" every time these days, can't you? YouTube: https://www.youtube.com/channel/UCc9BDi-STaqgWsjNiHbW0fA
fargo007 Posted April 21, 2022 Posted April 21, 2022 Assuming you don't know how to write code, or understand lua syntax, start looking at tutorials on youtube of how to set up LDT, a log follower like glogg, lua tutorials, and begin looking at example MOOSE missions to build an understanding of how it works, and what it does. Also the MOOSE documentation will be of great help once you understand how it's laid out. You're not going to magically arrive at writing solid code without doing some learning. New journeys of discovery are hard, but you and your missions will be better for it. In the end, it's going to unlock amazing new potential that the ME just cannot touch. Have fun. Don't suck. Kill bad guys. https://discord.gg/blacksharkden/
VR Flight Guy in PJ Pants Posted April 21, 2022 Author Posted April 21, 2022 I write simple LUA for Roblox and Minecraft, just not knowing how to convert trigger into LUA script. I will give MOOSEa look. Thanks. I Fly, Therefore I Am. One cannot go around not saying "Thank you" every time these days, can't you? YouTube: https://www.youtube.com/channel/UCc9BDi-STaqgWsjNiHbW0fA
VR Flight Guy in PJ Pants Posted April 22, 2022 Author Posted April 22, 2022 I think I have found an example to start with: I Fly, Therefore I Am. One cannot go around not saying "Thank you" every time these days, can't you? YouTube: https://www.youtube.com/channel/UCc9BDi-STaqgWsjNiHbW0fA
cfrag Posted April 22, 2022 Posted April 22, 2022 (edited) 13 hours ago, VR Flight Guy in PJ Pants said: I write simple LUA for Roblox and Minecraft, just not knowing how to convert trigger into LUA script. I If you already know some Lua, using it over ME will feel liberating, exhilarating, addictive, and, yes, frustrating. To make the last bit less bothersome, here are some tips gleaned from my personal experience initially, avoid using libraries like MOOSE and Mist in your mission, but definitely look at their code to understand what they are doing. They are fantastic - and chock-full of at-first strange ways of going about things that only become apparent when you try it yourself and fail - usually because of some quirk in DCS itself. Go to this GREAT site, bookmark it and always have it open for your reference. While this site doesn't explain well how the sim engine itself works (hardly the authors' fault), the documentation is great, and their authors have my eternal gratitude Above link notwithstanding, the state of documentation for the scripting engine is still abysmal. Many things simply aren't explained, work different than documented or have changed, or work somewhat like explained, except not in your case. Strange quirks abound. Look at this as the salt in your life to avoid premature hair loss. Now, when you come from ME and want to make the jump to Lua scripting bliss, there is an immediate obstacle to overcome: how the heck is your code going to be invoked? How do you get DCS to call your code regularly so that you can check up on your minions? The reason this comes up is because DCS's game engine loop isn't well described, and there is no documented 'Update' loop or other standard game engine means that your code can tap into. So you will have to roll your own. I have thrown together a basic Lua 'skeleton' script that, once started, continually calls itself for the rest of the mission. That is your Update Loop, and that is where you would put 99% of your mission checking code. So if you run that script via a DOSCRIPT trigger at the very start of the mission, your own Update Loop is invoked regularly. That is where you place your former ME Trigger Conditions - and bask in the light of how much simpler and more readable this is now. And portable. OK, here's the entirety of that code: skel = {} function skel:onEvent(event) -- event handler end function skel.update() -- schedule next update invocation timer.scheduleFunction(skel.update, {}, timer.getTime() + 1) -- your own stuff and checks here trigger.action.outText("DCS, this is Lua. Hello. Lua.", 30) end world.addEventHandler(skel) -- connect event hander skel.update() -- start update cycle Put it in a DOSCRIPT that runs at mission start. From that moment on, skel.update() is invoked once a second (can you find out how?), and that method is where you place your own code. Go to the great documentation site I talked about above, and look up timer.scheduleFunction and world.addEventHandler() to see what they do. Take note of how the script invokes itself. Now, the latter is important because that little skel app also has a hook inside that is called every time world event happens. You can later tap into that to write your own code to detect situations (like people shooting, planes crashing etc) and handle that as well. Do that after you feel that you are comfortable with how Lua works in DCS And then there is one last method you absolutely must look up. It's your only real debugging device: trigger.action.outText() As a first exercise, I put it in the update loop to say 'Hello World' every second. Now, try to get it to say it only the very first time. After that, everything else is smooth sailing Once you get a handle on how Lua integrates with DCS's game loop, and tried a few tricks, only then start using Mist or MOOSE. They are far too powerful to use from the get-go. Meaning: with great power comes great frustration. If you don't know why Mist/Moose do something (just how) and merely script-kiddie some code, you are squandering the immense power and cleverness inherent in those libraries. I've also attached a demo miz with above code in place. I strongly advise that you only use it if you can't get the above to work on your own, as it's these first steps that you should be able to walk by yourself before you can super-jump to other buildings (and no, I definitely did not over-binge spidey movies last night ) Hope this helps, -ch hello world from LuaI.miz Edited April 22, 2022 by cfrag 3
Rudel_chw Posted April 22, 2022 Posted April 22, 2022 18 minutes ago, cfrag said: To make the last bit less bothersome, here are some tips gleaned from my personal experience Thanks a lot, for a really great intro on how to do scripting on DCS. For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra For Gaming: 34" Monitor - Ryzen 3600 - 32 GB DDR4 2400 - nVidia RTX2080 - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar Mobile: iPad Pro 12.9" of 256 GB
VR Flight Guy in PJ Pants Posted April 22, 2022 Author Posted April 22, 2022 2 hours ago, cfrag said: (can you find out how?) Here: timer.scheduleFunction(skel.update, {}, timer.getTime() + 1) I Fly, Therefore I Am. One cannot go around not saying "Thank you" every time these days, can't you? YouTube: https://www.youtube.com/channel/UCc9BDi-STaqgWsjNiHbW0fA
Rudel_chw Posted April 22, 2022 Posted April 22, 2022 19 hours ago, VR Flight Guy in PJ Pants said: I am using the same set of scripts across different maps, and there are quite a lot of triggers and each of them is rather long. Should I use LUA scripts instead? While learning LUA scripting can be worthwhile, you will very well spend much more hours on this learning than you would just re-typing your triggers code. Also, there is a way to copy a whole mission to a different Map, just by altering the "Theater" parameter within the mission file. However, the big difference between the two maps is the location of map origin which is what all of the coordinates for everything is based on. This means that when you swap the map, all of the mission units and trigger zones (and labels) will be on a different location, they may be even on sea or out of the map border. However, it is possible to recover them by using the Unit List, selecting the unit there, then press ctrl X, left click on the desired new position, and press ctrl V to paste it there. Same for trigger zones (not sure about labels). Test this technique (thanks @Grimes) with a simple mission first, say one with a single unit, trigger zone and trigger, to get the hang of it: Step 1: Save a copy of the mission and name it with something so you know which map it is on. Step 2: Open .miz with 7zip or winzip. Step 3: Open 'mission' file inside the .miz with notepad ++ Step 4: find the "theatre" entry and change it from the old map name to the new one. Valid names are: ["theatre"] = "Caucasus" ["theatre"] = "Nevada" ["theatre"] = "Normandy" ["theatre"] = "PersianGulf" ["theatre"] = "TheChannel" ["theatre"] = "Syria" ["theatre"] = "MarianaIslands" Step 5: Save the file to somewhere on your PC, leave it extensionless Step 6: Drag the saved file into the opened .miz in 7zip or winzip. And overwrite the mission file. 1 For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra For Gaming: 34" Monitor - Ryzen 3600 - 32 GB DDR4 2400 - nVidia RTX2080 - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar Mobile: iPad Pro 12.9" of 256 GB
VR Flight Guy in PJ Pants Posted April 22, 2022 Author Posted April 22, 2022 (edited) Huge thanks! I am not sure because there is a lot of trigger codes involved and I have to test them afterwards, not to mention there are zones involved so I need to test to see if this method works or not. So if I can use one script for all, it may save some effort, at least in long run. Update: it works! and the units are not moved too way off. Edited April 22, 2022 by VR Flight Guy in PJ Pants I Fly, Therefore I Am. One cannot go around not saying "Thank you" every time these days, can't you? YouTube: https://www.youtube.com/channel/UCc9BDi-STaqgWsjNiHbW0fA
Recommended Posts