DackSter94 Posted March 25, 2016 Posted March 25, 2016 Hello, everyone. Let's start by saying that I have 0 experience in DCS scripting engine :). I understand .lua a bit (I can write a basic calculator that runs in command prompt xD) , but I still can't understand simulator scripting engine "syntax". I have read Introduction to Simulator Scripting Engine article on Hoggit wiki but it didn't make any sense for a noob like me. It starts too complex. So my first question is: Is there any Simulator Scripting Engine guide that starts explaining things from "total noob in DCS scripting" level? Now, back to my specific problem.I was creating a mission today with some triggers and I ran into a problem. Imagine a trigger zone that has x amount of red coalition ground units in it, some of them being from different groups(that part is important). I needed a condition that performed some action if 90percent or more (or just y ammont or more)of those red units in the trigger zone get destroyed. The closest condition game offers is something like "group alive less then y percent". But I need something trigger zone related and not specific group. If that is not a hard to make script, can someone post it here? That will probably help me and others to understand simulator scripting engine "syntax" alot more :). Thanks! LOOK MA, NO HOOK
FSFIan Posted March 25, 2016 Posted March 25, 2016 Did you read the Tutorial: Introduction to Lua Scripting that is stickied in this very forum? It seems to be a common theme that people want to start with Lua scripting, take one look at the hoggit wiki, and then get this deer in the headlights look because they see a lot of information at once and don't know where to start. Maybe I should do a screencast about this at some point... Here's a list of steps I would recommend to get started: Download and set up DCS Witchcraft. It gives you a live "Lua Console" that allows you to write and execute snippets of Lua code while the mission is running. When something does not do what you expect it to, you can instantly try again. Here's a screenshot of what it looks like: https://jboecker.github.io/dcs-witchcraft/dcs-witchcraft-alpha1-luaconsole.png Make a simple mission that loads a current version of MiST, calls witchcraft.start(_G) as described in the DCS Witchcraft readme, and has a few ground unit groups with names that are easy to remember. Learn Lua! The documentation for the scripting engine and MiST is a reference for the functions that DCS and MiST provide; its job is not to teach you the core programming language. You don't have to know all of Lua before jumping into the fray, but you should at least know how to use local and global variables, do basic math, and how to work with tables (the data structure that Lua uses for everything). You can learn about flow control (if statements and loops) later. Take a look at the Group and Unit classes. Whenever you need some information about units on the map, you will need to use their member functions. It often starts with a call to Group.getByName(). Read this post, where I describe the general process I go through when I want to do anything with the scripting engine Use the Lua Console to experiment with the ground units in your test mission. Grab a group object with Group.getByName, get a specific unit by calling getUnit() on that, and see if you can use the Scripting Engine Documentation to make sense of the return value of getPosition(). See what happens if you call unit:destroy(). Try respawning the group with MiST. Play around with the trigger.action.explosion function... DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
0xDEADBEEF Posted March 25, 2016 Posted March 25, 2016 Ian did you update whichcraft to work with 1.5? I've tried it few weeks back but could not get it running ... would be very cool! @DackSter: Start step by step. I personally don't use much triggers in MissionEditor as I personally find it more convenient to do things in code. All I use MissionEditor for is placing things and loading scripts, I do all the scripts in an external editor (Notepad++ is the most recommended, I have started to use Eclipse which helps with syntax highlighting, both are free). Theres many missions out there which rely mostly on Mission Editor Triggers and it works well as well. It's really mostly a personal preference which will develop as you get deeper in to scripting. Getting started is the hardest part you need get over, once you have established basic understanding things will move a lot faster. What may also help you is loading Multiplayer-Trackfiles into MissionEditor and see how the Missiondesigner has made things, the Tracks contain the Mission-Files including triggers and scripts. Theres many different approaches on how to achieve things. Some may work better for you than others and vice versa. Once you get the hang of it you'll love it. The scripting engine is very powerful and has rather littler limitations.
FSFIan Posted March 25, 2016 Posted March 25, 2016 Ian did you update whichcraft to work with 1.5? I did not, because there was no need to. The Lua Console works fine with current versions of DCS. Make sure you use a current version of MiST. The unit moving part is probably broken, use this hack instead. DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
DackSter94 Posted March 25, 2016 Author Posted March 25, 2016 First of, thanks for response and all the links. Ian;2722630']Did you read the Tutorial: Introduction to Lua Scripting that is stickied in this very forum? Yes I have read that. And that is exactly the kind of guide I was looking for except it only has one part! Now I came across DCS Witchcraft and MIST, and those must be great tools for an experienced DCS scripter, but for a noob they are just additional pile of "whatisthat" and "wheredoistart" questions in addition to original game. So for you those tools make life easier, for a noob like me - they just complicate things. Ian;2722630'] Take a look at the Group and Unit classes. Whenever you need some information about units on the map, you will need to use their member functions. It often starts with a call to Group.getByName(). Of course I visited those pages. Got "deer in the headlights look" there. It feels that you learn more from just creating a mission with one unit and then reading through mission.lua from .miz file :) LOOK MA, NO HOOK
DackSter94 Posted March 25, 2016 Author Posted March 25, 2016 @DackSter: What may also help you is loading Multiplayer-Trackfiles into MissionEditor and see how the Missiondesigner has made things, the Tracks contain the Mission-Files including triggers and scripts. Theres many different approaches on how to achieve things. Some may work better for you than others and vice versa. Yes i thought about that. The problem is that most MP missions are usually too complex. LOOK MA, NO HOOK
FSFIan Posted March 25, 2016 Posted March 25, 2016 Now I came across DCS Witchcraft and MIST, and those must be great tools for an experienced DCS scripter, but for a noob they are just additional pile of "whatisthat" and "wheredoistart" questions in addition to original game. So for you those tools make life easier, for a noob like me - they just complicate things. If you try to understand the Scripting Engine Documentation or the MiST documentation without having a solid background in the basics of the Lua programming language itself, you will be confused a lot. It would be like trying to do a type rating for an A380 without having a pilots license: the type rating teaches you the A380-specific things (such as how to tune the COM1 radio to a specific frequency and where the push-to-talk button is), but it won't teach you about the ATC system or how to talk on the radio. Once you know Lua, you can look at the Scripting Engine Documentation as your toolbox. MiST adds even more tools to your toolbox -- some are high-level functions that handle the details of commonly needed operations for you (such as respawning or teleporting a group of ground units), others are small utility functions that you could write yourself, but don't have to (such as doing vector math). You do not need to know how to use each tool in your toolbox right away, but you should have a general idea of what's in there. Scan through the entire documentation at least once, even if you don't understand everything right away, to get an idea of what tools are available to you. The Lua Console in DCS Witchcraft will let you iterate much faster. Even professional programmers routinely write code that does not work on the first try, so it is quite normal that lots of trial and error is involved. That gets more important when you are writing Lua scripts in DCS: World, because the Lua interpreter cannot catch as many errors up front as a compiler for a strongly typed language such as Java can. Being able to fix an error and retry your code snippets within five seconds instead of having to wait for the mission to reload will save you a lot of time and frustration. Here's something that might get you started. This code snippet returns the number of blue ground units in a trigger zone. It is a slightly adapted version of the example for the searchObjects() function. If you change the return statement to something like "return numBlueUnits < 5", you could use it as a Lua Predicate that returns true as soon as there are less than five blue ground units in the trigger zone. local sphere = trigger.misc.getZone('name of trigger zone') local volS = { id = world.VolumeType.SPHERE, params = { point = sphere.point, radius = sphere.radius } } local numBlueUnits = 0 local ifFound = function(foundItem, val) if foundItem:getCoalition() == coalition.side.BLUE then numBlueUnits = numBlueUnits + 1 end end world.searchObjects(Object.Category.UNIT, volS, ifFound) return numBlueUnits DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
DackSter94 Posted March 26, 2016 Author Posted March 26, 2016 Thanks for the code example. I'll try to play around with it to see what I can understand. LOOK MA, NO HOOK
FlightControl Posted March 26, 2016 Posted March 26, 2016 Lua predicates are not working in dcsw 1.5.3 update 1. Haven't tested in update 2. [TABLE][sIGPIC][/sIGPIC]| Join MOOSE community on: DISCORD :thumbup: Website of the MOOSE LUA Framework. MOOSE framework Downloads. Check out Example Missions to try out and learn. MOOSE YouTube Channel for live demonstrations and tutorials. [/TABLE]
FSFIan Posted March 26, 2016 Posted March 26, 2016 Lua predicates are not working in dcsw 1.5.3 update 1. Haven't tested in update 2. In that case, use mist.scheduleFunction in an initialization script to schedule a custom function that checks your condition, and set it to repeat once a second (or slower, if you don't need your trigger to react that fast). DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
Recommended Posts