DaveSD Posted January 2, 2023 Share Posted January 2, 2023 (edited) Hey everyone, I started trying to use LUA but got in way over my head, so I'm hoping to try to do this via triggers, waypoint actions, voodoo, anything but LUA. ### EDIT: I tried the following code and got closer - I think - after several tries. There are a few comments. Any ideas what I'm doing wrong? To cut to the chase, I'm trying to get a FAC to move to a new waypoint after a target is destroyed. local function main() do for i=1, t do local t=trigger.misc.getUserFlag('Ground-1-1') if getUserFlag="0" --Line 9 --if getUserFlag=0 --Alternate Line 9 then { } else trigger.action.switchWP('Aerial-1-1') params={fromWaypointIndex=0, goToWaypointIndex=1} end --ERROR: lua: main.lua:9: 'then' expected near '=' ### What I'm trying to do is have the status of AI Unit A affect the behavior of AI Unit B. More specifically in my case, if Unit A is killed (by any attacking unit) I'd like the FAC Unit B to move from Waypoint 1 to Waypoint 2. (In the case of an airborne FAC, it would be orbiting at Waypoint 1.) Although a complete answer is great, I also don't want to ask you to do my work for me, so if you can just sort of point me in a direction I'd appreciate it. LUA melted my brain. In the past I've tried learning JavaScript, obviously not for DCS, and it too melted my brain. Edited January 3, 2023 by DaveSD Link to comment Share on other sites More sharing options...
cfrag Posted January 3, 2023 Share Posted January 3, 2023 Generally speaking, all computer languages melt your brain the first time you try them. Until you get hooked, that is. Then they melt your life. For me it helps when I start with simple tasks in a new environment, just to get a feeling for it, "getting the lay of the land", so to speak. You know, first try the "hello world" equivalent in DCS, then start raising the difficulty by only having it say 'hello world' when certain conditions are met, and branch out from there (count how many times the condition was met, then have it do something special on the 5th occurrence, then delay the response by 5 seconds etc.). From the code sample you kindly included it seems that you are trying to jump before being able to run, perhaps even before you can walk reliably (and yes, I think I can see some C/Java knowledge shining through). Before you attempt what you are doing now, I recommend that you get a bit more comfortable with Lua's code structure in general, then look at how you can get your code invoked (which threw me for a while when I tried my hand at mission scripting in DCS). Once you feel comfortable enough with the basics, attempt a script that reliably detects that unit A is killed, and then (and only then) posts a message "Unit A was killed". That becomes the jumping-off point for all further code. I recommend going this route because it breaks the bigger problem you are trying to solve into smaller, more manageable (yet still challenging) steps (initiating a Lua-coded response to a condition) that you need to accomplish before you can embark on more complex challenges (tasking groups). Along the way you'll learn how to use the various methods that DCS's scripting environment offers up to you (see here for a great reference), and you'll rapidly gain confidence and get a lot more fun out of scripting. Since you've already cleared the biggest hurdle (actually trying your hand at mission scripting), the rest should be just a matter of time Link to comment Share on other sites More sharing options...
jonsky7 Posted January 3, 2023 Share Posted January 3, 2023 I think this is doable with the ingame triggers, especially for a simple mission (no continuous respawning of units etc) Trigger Once - "Unit dead" select unit A - FLAG ON "1" For unit B, set up waypoints, at waypoint 1, add advanced option, perform task HOLD, stop condition - user flag 1 is on when unit 1 dies, the hold condition is removed and unit b then proceeds to waypoint 2 hold till dead.miz Link to comment Share on other sites More sharing options...
sirrah Posted January 3, 2023 Share Posted January 3, 2023 4 hours ago, jonsky7 said: I think this is doable with the ingame triggers, especially for a simple mission (no continuous respawning of units etc) Trigger Once - "Unit dead" select unit A - FLAG ON "1" For unit B, set up waypoints, at waypoint 1, add advanced option, perform task HOLD, stop condition - user flag 1 is on when unit 1 dies, the hold condition is removed and unit b then proceeds to waypoint 2 hold till dead.miz What @jonsky7 says is correct Additionally, you could add a "move to waypoint X" action, and set start condition to that same flag, to have unit 2 move to a specific predetermined waypoint (not necessarily the next one). I've used this function for several of my missions (mainly because I have no scripting knowledge ) System specs: i7-8700K @stock speed - GTX 1080TI @ stock speed - AsRock Extreme4 Z370 - 32GB DDR4 @3GHz- 500GB SSD - 2TB nvme - 650W PSU HP Reverb G1 v2 - Saitek Pro pedals - TM Warthog HOTAS - TM F/A-18 Grip - TM Cougar HOTAS (NN-Dan mod) & (throttle standalone mod) - VIRPIL VPC Rotor TCS Plus with ALPHA-L grip - Pointctrl & aux banks <-- must have for VR users!! - Andre's SimShaker Jetpad - Fully adjustable DIY playseat - VA+VAICOM - Realsimulator FSSB-R3 ~ That nuke might not have been the best of ideas, Sir... the enemy is furious ~ GUMMBAH Link to comment Share on other sites More sharing options...
DaveSD Posted January 4, 2023 Author Share Posted January 4, 2023 15 hours ago, cfrag said: Generally speaking, all computer languages melt your brain the first time you try them. Until you get hooked, that is. Then they melt your life. For me it helps when I start with simple tasks in a new environment, just to get a feeling for it, "getting the lay of the land", so to speak. You know, first try the "hello world" equivalent in DCS, then start raising the difficulty by only having it say 'hello world' when certain conditions are met, and branch out from there (count how many times the condition was met, then have it do something special on the 5th occurrence, then delay the response by 5 seconds etc.). From the code sample you kindly included it seems that you are trying to jump before being able to run, perhaps even before you can walk reliably (and yes, I think I can see some C/Java knowledge shining through). Before you attempt what you are doing now, I recommend that you get a bit more comfortable with Lua's code structure in general, then look at how you can get your code invoked (which threw me for a while when I tried my hand at mission scripting in DCS). Once you feel comfortable enough with the basics, attempt a script that reliably detects that unit A is killed, and then (and only then) posts a message "Unit A was killed". That becomes the jumping-off point for all further code. I recommend going this route because it breaks the bigger problem you are trying to solve into smaller, more manageable (yet still challenging) steps (initiating a Lua-coded response to a condition) that you need to accomplish before you can embark on more complex challenges (tasking groups). Along the way you'll learn how to use the various methods that DCS's scripting environment offers up to you (see here for a great reference), and you'll rapidly gain confidence and get a lot more fun out of scripting. Since you've already cleared the biggest hurdle (actually trying your hand at mission scripting), the rest should be just a matter of time Thanks for the reply, dfrag! In the past, I've managed to fiddle with JavaScript, PHP, ASP, CFM, PERL, HTML and CSS. I had HTML nailed down until they decided to prank me by coming up with HTML5. I even tried MySQL database stuff, which really confused me. I managed to get something simple running. I think one of the things that tripped me up with LUA is that there are what I imagine are variables(?) specific to DCS. I found an online LUA syntax checker, plugged in a simple "Hello World" sort of LUA script I found, and it ran fine. Then just to see how it turned out, I replaced what I could in that simple script with my own things, like wording to replace "Hello World." It didn't run. Of course it was one of those tiny little mistakes that are so easy to miss. Anyway, I'm going to dig into DCS because I can see it will really change with way DCS is experienced. (I hesitate to say we "play" DCS - it's too realistic, at least in simulation mode, to be considered a game.) Dave 15 hours ago, jonsky7 said: I think this is doable with the ingame triggers, especially for a simple mission (no continuous respawning of units etc) Trigger Once - "Unit dead" select unit A - FLAG ON "1" For unit B, set up waypoints, at waypoint 1, add advanced option, perform task HOLD, stop condition - user flag 1 is on when unit 1 dies, the hold condition is removed and unit b then proceeds to waypoint 2 hold till dead.miz Thanks for the replies, jonsky7 and @sirrah! I'm going to give what you both suggested a try, but I'm also going to actually try to learn LUA as @cfrag suggested. It'll be a worthwhile skill to use with DCS, at least to the level I want to be operating at. Now I just need to learn how to land on a carrier (I know how, but that doesn't mean I can.), how to dogfight, how to keep SAMs from killing me, how to keep AAA from killing me, how to keep me from killing me... 1 Link to comment Share on other sites More sharing options...
DaveSD Posted January 4, 2023 Author Share Posted January 4, 2023 @cfrag, I ordered a LUA book today. I learn this stuff better via book so I don't have to constantly be switching windows. Thanks for the help! @jonsky7 and @sirrah You guys really helped! It was much simpler than I realized, and my big mistake was that I thought that when a user flag was set, it applied only to the unit that set it rather than it being a global flag for the user. I tested it out by having a unit damaged or destroyed by another ground unit and then having an aircraft end its orbit and start smoke. Worked great! Link to comment Share on other sites More sharing options...
sirrah Posted January 4, 2023 Share Posted January 4, 2023 8 minutes ago, DaveSD said: @cfrag, I ordered a LUA book today. I learn this stuff better via book so I don't have to constantly be switching windows. Thanks for the help! @jonsky7 and @sirrah You guys really helped! It was much simpler than I realized, and my big mistake was that I thought that when a user flag was set, it applied only to the unit that set it rather than it being a global flag for the user. I tested it out by having a unit damaged or destroyed by another ground unit and then having an aircraft end its orbit and start smoke. Worked great! (small bonus tip, just in case you didn't know, you can just use text for your flags. You don't have to stick to numbers. Helps a lot in remembering which flag should do what ) 1 System specs: i7-8700K @stock speed - GTX 1080TI @ stock speed - AsRock Extreme4 Z370 - 32GB DDR4 @3GHz- 500GB SSD - 2TB nvme - 650W PSU HP Reverb G1 v2 - Saitek Pro pedals - TM Warthog HOTAS - TM F/A-18 Grip - TM Cougar HOTAS (NN-Dan mod) & (throttle standalone mod) - VIRPIL VPC Rotor TCS Plus with ALPHA-L grip - Pointctrl & aux banks <-- must have for VR users!! - Andre's SimShaker Jetpad - Fully adjustable DIY playseat - VA+VAICOM - Realsimulator FSSB-R3 ~ That nuke might not have been the best of ideas, Sir... the enemy is furious ~ GUMMBAH Link to comment Share on other sites More sharing options...
jonsky7 Posted January 4, 2023 Share Posted January 4, 2023 11 minutes ago, sirrah said: (small bonus tip, just in case you didn't know, you can just use text for your flags. You don't have to stick to numbers. Helps a lot in remembering which flag should do what ) Nice, did not know that, thanks Link to comment Share on other sites More sharing options...
Recommended Posts