shagrat Posted October 11, 2013 Posted October 11, 2013 (edited) Yes! Let's make it an community effort to include examples on every function, including the SSE. I've requested a login for the Hoggit-wiki. :thumbup: Any script with documentation (comments) is worth more than all "explanations of the syntax... I guess I'm not the only one who mostly "edits" existing scripts to tweak them, which is easier than programming things from scratch. My biggest issue is to track errors. A simple tool to run the script and track variables content or state would be awesome, to see what happens! Most of the time I need to test fly the mission, provoke conditions or edit the mission setting triggers by hand and try to find errors in the log! :cry: For example I added a functions to set spawned Ground troops to immortal and invisible to Ragnarda's Medevac script, so they don't get killed seconds after spawning. The hardest part, was figuring where the troops where actually spawned and call the function after that... Still I learned mor about the condition check and loops in lua, than I could have learned from any syntax explanation. By the way, thanks RagnarDa for the awesome script :D EDIT: Even harder is, to understand what you can do to Objects in the Sim. Is there a catalog anywhere with the Objects and all there states, actions, parameters etc.??? Edited October 11, 2013 by shagrat Shagrat - Flying Sims since 1984 - Win 10 | i5 10600K@4.1GHz | 64GB | GeForce RTX 3090 - Asus VG34VQL1B | TrackIR5 | Simshaker & Jetseat | VPForce Rhino Base & VIRPIL T50 CM2 Stick on 200mm curved extension | VIRPIL T50 CM2 Throttle | VPC Rotor TCS Plus/Apache64 Grip | MFG Crosswind Rudder Pedals | WW Top Gun MIP | a hand made AHCP | 2x Elgato StreamDeck (Buttons galore)
Grimes Posted October 11, 2013 Posted October 11, 2013 My biggest issue is to track errors. A simple tool to run the script and track variables content or state would be awesome, to see what happens! Honestly you need to just put env.info() statements everywhere so you can follow the logic and see what is happening. mist.utils.tableShow is insanely valuable to see what the contents of a table are. EDIT: Even harder is, to understand what you can do to Objects in the Sim. Is there a catalog anywhere with the Objects and all there states, actions, parameters etc.??? It is dependent on the object class a specific object belongs to: http://wiki.hoggit.us/view/Part_2 For the most part the class functions get data on the specific object. Object.destroy() which is available to most classes, is the only "action" available and it completely removes the object from the simulator. The Controller Class is where actions and manipulation comes into play. It basically has everything the mission editor has in regard to tasking, commands, options, etc. The only difference is the scripting engine has MUCH more control over it. 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
ENO Posted October 11, 2013 Author Posted October 11, 2013 I'm smiling because I'm not sure you can even grasp how absent my knowledge is. I just went to google using env.info() and needless to say am no further ahead. My knowledge is so fundamentally lacking that I'm not even sure how to benefit from that critical tool. When you say to use it- I just don't know how to implement it. Do I put: do trigger.action.outText(mist.utils.tableShow(myTable), 25) end ... into something? Does it ACTUALLY print somewhere or does it write it out in a file? And where do I put in the env.info() entries everywhere to benefit? HAAAAAAAaaaaallllp! I know you give that advice a lot and I've never really understood what it meant- but I think a ground level entry into how to use it would be extremely helpful for this kind of thread. Right now I always have to resort to finding "another way around." "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
Grimes Posted October 12, 2013 Posted October 12, 2013 Search the wiki pages... http://wiki.hoggit.us/view/Part_1#env env.info() adds an entry to your dcs.log file in saved games. It is useful to see which variables are getting passed to a function or where something might be getting held up in your code. Take the following example of code. Assume the table passed to it is {'hello', 'world'} function myFunc(table) env.info('start my func') for index, data in pairs(table) do env.info(index) env.info(data) if data == 'world' then env.info('statement is true') end end env.info('end my func') end When you run that function the dcs.log would have something like... 00033.999 INFO SCRIPTING: start my func 00033.999 INFO SCRIPTING: 1 00033.999 INFO SCRIPTING: hello 00033.999 INFO SCRIPTING: 2 00033.999 INFO SCRIPTING: world 00033.999 INFO SCRIPTING: statement true 00033.999 INFO SCRIPTING: end my func You can also use env.info('whatever happened', true) and the message will be displayed in the upper left hand corner of the screen, sort of like warehouse deliveries. The trigger.action.outText just displays a table as a trigger message. Its use is limited though because, A. Can be overwritten by other triggers B. Can only have so many entries before info gets cut off screen. C. Must be in game and generally must pause to read it. 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
ENO Posted October 12, 2013 Author Posted October 12, 2013 Okay so just to be clear- the "printing" occurs in the log? And these entries- are they just "do script" entries at "mission start" resulting in data that can be interpreted in the log? "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
Grimes Posted October 12, 2013 Posted October 12, 2013 Yeah they replace print() statements which for some reason or another no longer work in the mission environment, so you have to use env.info(), env.error(), or env.warning() They execute at the same time as whatever code you have. Its just another line and function within the code that has to execute. From my example, each time you call myFunc() its going to add the entries to the log with the correct time stamp and whatever happens within the function. The entries can quickly add up within the log depending on what you are doing, so I like to either remove them or comment em out once I know the function is working. 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
ENO Posted October 13, 2013 Author Posted October 13, 2013 Ugh... my castle for 1 more brain cell right now. "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
Prof_hilactic Posted October 16, 2013 Posted October 16, 2013 Just when I thought I understood lua, I stumble on another arcane requirement. :helpsmilie: This time it is with Controller.isTargetDetected(Controller self, Object target, [Controller.Detection detection1, Controller.Detection detection2, ... Controller.Detection detectionN] or nil) what do I need to put in [Controller.Detection detection1] to use RADAR? local radar1 = 'radar1' local target1 = 'target1' local OriginGroup, TargetGroup = Group.getByName(radar1), Group.getByName(target1) local OriginUnits, TargetUnits = OriginGroup:getUnits(), TargetGroup:getUnits() local detect =Controller.isTargetDetected(OriginGroup,TargetGroup,RADAR) if detect == true or detect == 1 then trigger.action.outText("detected", 40) trigger.action.setUserFlag('10', true) elseif detect == false or detect == 0 then trigger.action.outText("not detected", 40) trigger.action.setUserFlag('10', false) end I tried with a tungunska once an A-10 is in range and the only thing I can see is the message "not detected' even if the tungunska is actively trackingthe A-10. also what do I need to do to have this checked every 10 seconds or so using mist.schedulefunction?
Grimes Posted October 16, 2013 Posted October 16, 2013 (edited) Could try changing RADAR to : Controller.Detection.RADAR Right now it is looking for the variable "RADAR" to reference... which is nil. How to loop it, you'd have to put it in a function and call that with mist.scheduleFunction.... function targetDetection() --your code end mist.scheduleFunction(targetDetection, {}, timer.getTime() + 10, 10) Edited October 16, 2013 by Grimes 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
SNAFU Posted October 17, 2013 Posted October 17, 2013 (edited) In my tests the Controller.isTargetDetected(...,..., RADAR) works fine, but only with the RADAR of ground units. I never got this function working with airborne RADAR or using "nil" (all sensors?) as sensor type. local possibleintruder = Unit.getByName(allairunits.name) local EWRgroup = allEWRunits[j].group local EWRgroupcontroller = EWRgroup:getController() possibleintrudergroupdetected = Controller.isTargetDetected(EWRgroupcontroller, possibleintruder, RADAR) Edited October 17, 2013 by SNAFU [sIGPIC][/sIGPIC] Unsere Facebook-Seite
Prof_hilactic Posted October 17, 2013 Posted October 17, 2013 Thank you Grimes and SNAFU for the answers. unfortunately It is not working I still get no detection from any radar unit. I also tried SNAFU script but no luck. SNAFU could you provide a miz example?
ENO Posted October 19, 2013 Author Posted October 19, 2013 mist.teleportInZone('group1', 'zone1', {disperse = true, radius = 4000}) I'm doing this script but it keeps just doing what I'm assuming is the default 250m. Any thoughts? "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
Grimes Posted October 19, 2013 Posted October 19, 2013 mist.teleportInZone('group1', 'zone1', disperse = true, radius = 4000) No need for the table brackets. 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
ENO Posted October 19, 2013 Author Posted October 19, 2013 Thanks again Grimes! "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
ENO Posted October 20, 2013 Author Posted October 20, 2013 00051.312 ERROR DCS: Mission script error: : [string "mist.teleportInZone('1', 'ocean', disperse = true, radius = 400..."]:1: ')' expected near '=' Make any sense to anyone? "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
Prof_hilactic Posted October 20, 2013 Posted October 20, 2013 Generally I use mist.teleportToPoint and for dispersion I just put 'disp', it seems to work. So try mist.teleportInZone('group1', 'zone1', 'disp', 4000) 1
Grimes Posted October 20, 2013 Posted October 20, 2013 Yeah I totally blanked on fixing that for you. I saw the obvious problem, the creation of a table {} and didn't see the other error. It happens more than I care to admit in my own code. :) 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
ENO Posted October 21, 2013 Author Posted October 21, 2013 (edited) I got that working, and also got it to work with the "random" table of names as well. Thanks guys. One issue I'm having is that these groups randomly respawn on water and it's not that kind of "mission." I noticed there is a "is terrain valid" entry in the MIST guide but I'm quite certain it's not going to work for what I want it to... I'm going to hunt around for answers in the event this question has been answered and I'll take the question down if I find anything. 1. "Spawn random group", thats a good idea! Also might do something to randomize the units position within a group so that a strella won't always be in the same spot. 2. Terrain types will work, and it is obviously something that should be part of the script but it isn't yet I don't think. Towns is possible but might be tricky. Forests is impossible as the scripting engine doesn't have access to where trees are. 3. Also possible. This is as close as I got... Did it ever make it's way in there Grimes? Edited October 21, 2013 by ENO "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
Prof_hilactic Posted October 21, 2013 Posted October 21, 2013 Ok managed to get the targetdetected script to work function targetDetection() local possibleintruder = Unit.getByName('A-10') local EWRgroup = Group.getByName('Sam') local EWRgroupcontroller = EWRgroup:getController() possibleintrudergroupdetected = Controller.isTargetDetected(EWRgroupcontroller, possibleintruder, RADAR) if possibleintrudergroupdetected == true or possibleintrudergroupdetected == 1 then trigger.action.outText("detected", 5) trigger.action.setUserFlag('10', true) elseif possibleintrudergroupdetected == false or possibleintrudergroupdetected == 0 then trigger.action.outText("not detected", 5) trigger.action.setUserFlag('10', false) end end mist.scheduleFunction(targetDetection, {}, timer.getTime() + 10, 10) However it is stuck with A-10 as a unit. How do I change this for any type of '[blue][plane]'? I tried with local airunit = mist.makeUnitTable({'[blue][plane]'}) and replacing A-10 with airunit but no luck
Grimes Posted October 21, 2013 Posted October 21, 2013 One issue I'm having is that these groups randomly respawn on water and it's not that kind of "mission." This is as close as I got... Did it ever make it's way in there Grimes? Its there, but its not there completely... It checks it for the first unit in the group but not for each subsequent unit in the group. Ok managed to get the targetdetected script to work However it is stuck with A-10 as a unit. How do I change this for any type of '[blue][plane]'? I tried with local airunit = mist.makeUnitTable({'[blue][plane]'}) and replacing A-10 with airunit but no luck You are going to have to iterate through the table it returns with all of your logic. local checkUnits = mist.makeUnitTable({'[blue][plane]'}) for id, unitName in pairs(checkUnits) do local possibleintruder = Unit.getByName(unitName) ... end 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
ENO Posted November 1, 2013 Author Posted November 1, 2013 (edited) Quick question- if I run a script that is in the mission but not yet activated, will the script see the unit in a table and just apply the script when the unit activates? Or will I get an error? Okay, well I just went and tested it since I realized I know enough to do that... and the short answer is "yes." It did work! :) Edited November 2, 2013 by ENO "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
Winfield_Gold Posted November 7, 2013 Posted November 7, 2013 Noob question, once Mist is loaded at the start in the mission editor, where are all the mist functions entered? Are they entered into the actual mission editor or are 20 different scripts created in notepad++ and then ran by "do script"
Grimes Posted November 7, 2013 Posted November 7, 2013 Noob question, once Mist is loaded at the start in the mission editor, where are all the mist functions entered? Are they entered into the actual mission editor or are 20 different scripts created in notepad++ and then ran by "do script" Whatever suits your needs: http://wiki.hoggit.us/view/Scripting_Engine_Introduction If I am doing a script that is more than a few lines I typically work in notepad++ and just copy/paste the code into a do script action. The script boxes in the editor are kinda small, so once you get above 10 lines or have a really long line its not very manageable to just use the editor.. Plus notepad++ has syntax highlighting which is insanely useful to have. 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
ENO Posted November 7, 2013 Author Posted November 7, 2013 Being a copy paste guy myself- as grimes said if I'm copying a script (as oppsed to writing my own) with the intention of modifying it, I'll modify it in notepad++ because its much easier. "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
mwd2 Posted November 10, 2013 Posted November 10, 2013 i have a BTR on patrol route with mist.ground.patrol('BTR', nil, 20) on a 'special event' (mist.flagFunc.units_LOS(), i set FLAG x to true, when any enemy aircraft is in range) If FLAG is true, the BTR should stop his patrol and spawn a MANPADS team with the Dismounts Script from MBot (http://forums.eagle.ru/showthread.php?t=109676&highlight=Dismounts). How do i get the HOLD function active via script? PS.: also if the aricraft leave the area, the patrol should go on....! Playing: DCS World Intel i7-13700KF, 64GB DDR5 @5600MHz, RTX 4080 ZOTAC Trinity, WIN 11 64Bit Prof. Squadron "Serious Uglies" / Discord-Server: https://discord.gg/2WccwBh Ghost0815
Recommended Posts