Leopold Posted May 24 Posted May 24 Hi all, I'm completely new to coding and scripting in DCS and have spent several days trying to get a simple task to work using Lua. I want to move a ground group (TestGroup) to a trigger zone (TargetZone) when the mission starts. What I'm trying to do: Use Lua scripting to move TestGroup to the center of TargetZone at mission start. I’ve used MIST before and don’t mind using it, but I’d like to understand how to do it with or without it — mainly to learn scripting basics for future use. What I’ve tried so far: Using Group.getByName("TestGroup") and getController():setTask() → errors like: vbnet KopieraRedigera attempt to call field 'setTask' (a nil value) Using routeSet(), moveGroup(), and pushTask() — all resulted in errors or did nothing. Tried per-unit pushTask() as well, based on what ChatGPT generated — no luck. Tried scripting both inline (DO SCRIPT) and with external .lua files (simple_pathfinding_vXX.lua), loaded with dofile(). Also tried MIST’s mist.goRoute() after converting a route with mist.taskToRoute() — this version worked the best, but I’m still trying to understand why. My setup: DCS 2.9 stable Group name: TestGroup Trigger zone name: TargetZone MIST is loaded via a DO SCRIPT FILE at mission start What I need help with: A simple, working example of moving a ground group to a zone using Lua Ideally an explanation of why certain methods (like setTask, pushTask, etc.) fail or silently don’t work Bonus if you can show how to do it both with and without MIST Also: I’ve been working with ChatGPT to get started, and while it’s helped with structure and ideas, the actual DCS scripting details have been really difficult to get right. Any help is appreciated! I'm just trying to understand the basics here so I can build missions that use simple automation like this. Thanks in advance!
Kanelbolle Posted May 30 Posted May 30 On 5/24/2025 at 9:38 PM, Leopold said: Hi all, I'm completely new to coding and scripting in DCS and have spent several days trying to get a simple task to work using Lua. I want to move a ground group (TestGroup) to a trigger zone (TargetZone) when the mission starts. What I'm trying to do: Use Lua scripting to move TestGroup to the center of TargetZone at mission start. I’ve used MIST before and don’t mind using it, but I’d like to understand how to do it with or without it — mainly to learn scripting basics for future use. What I’ve tried so far: Using Group.getByName("TestGroup") and getController():setTask() → errors like: vbnet KopieraRedigera attempt to call field 'setTask' (a nil value) Using routeSet(), moveGroup(), and pushTask() — all resulted in errors or did nothing. Tried per-unit pushTask() as well, based on what ChatGPT generated — no luck. Tried scripting both inline (DO SCRIPT) and with external .lua files (simple_pathfinding_vXX.lua), loaded with dofile(). Also tried MIST’s mist.goRoute() after converting a route with mist.taskToRoute() — this version worked the best, but I’m still trying to understand why. My setup: DCS 2.9 stable Group name: TestGroup Trigger zone name: TargetZone MIST is loaded via a DO SCRIPT FILE at mission start What I need help with: A simple, working example of moving a ground group to a zone using Lua Ideally an explanation of why certain methods (like setTask, pushTask, etc.) fail or silently don’t work Bonus if you can show how to do it both with and without MIST Also: I’ve been working with ChatGPT to get started, and while it’s helped with structure and ideas, the actual DCS scripting details have been really difficult to get right. Any help is appreciated! I'm just trying to understand the basics here so I can build missions that use simple automation like this. Thanks in advance! Grimes already posted an example how to make units move with MIST. You just have to modify it to your need. WARGAMES Servers: https://forum.dcs.world/topic/301046-wargames-server-pvp-and-pve-campaign-servers/ Scripts: RGC & SPGG https://github.com/AGluttonForPunishment/
DD_Friar Posted May 30 Posted May 30 @Leopold I strongly suggest you check out the DML Tool box by @cfrag. If you are wanting to stretch what you can do with a mission but are unsure of coding, this utility (which is not a mod so other players do not need to download anything or install compilers etc). It is made up of copy and paste scripts / modules that open up a whole new world of functionality. I can not speak highly enough of it. get it here Visit the Dangerdogz at www.dangerdogz.com. We are a group based on having fun (no command structure, no expectations of attendance, no formal skills required, that is not to say we can not get serious for special events, of which we have many). We play DCS and IL2 GBS. We have two groups one based in North America / Canada and one UK / Europe. Come check us out.
Solution Kanelbolle Posted May 30 Solution Posted May 30 (edited) @Leopold I modified it in to a working example: function getGroupPos(groupname) local unit1 = Group.getByName(groupname):getUnit(1) local targetCoord = unit1:getPoint() return targetCoord end function goRoute(MoveGroupname, targetGroupName) local targetCord = getGroupPos(targetGroupName) local misTask = { id = 'Mission', params = { route = { ["points"] = { [1] = { ["alt"] = 13, ["type"] = "Turning Point", ["ETA"] = 0, ["alt_type"] = "BARO", ["formation_template"] = "", ["y"] = targetCord.z, ["x"] = targetCord.x, ["ETA_locked"] = true, ["speed"] = 30, ["action"] = "Off Road", ["task"] = { ["id"] = "ComboTask", ["params"] = { ["tasks"] = {}, }, -- end of ["params"] }, -- end of ["task"] ["speed_locked"] = true, }, -- end of [1] [2] = { ["alt"] = 13, ["type"] = "Turning Point", ["ETA"] = 65.493407534521, ["alt_type"] = "BARO", ["formation_template"] = "", ["y"] = targetCord.z, ["x"] = targetCord.x, ["ETA_locked"] = false, ["speed"] = 30.5555555555556, ["action"] = "Off Road", ["task"] = { ["id"] = "ComboTask", ["params"] = { ["tasks"] = {}, }, -- end of ["params"] }, -- end of ["task"] ["speed_locked"] = true, }, -- end of [2] }, -- end of ["points"] }, }, } local group if type(MoveGroupname) == 'string' then env.info('MoveGroupname was string, getting group') group = Group.getByName(MoveGroupname) end local groupCon = group:getController() if groupCon then env.info('groupCon is valid! Pushing task!') groupCon:pushTask(misTask) return true end end env.info('Script Loaded!') goRoute('Ground-1', 'Ground-2') And if you want it to go to a trigger zone, you can use zone = trigger.misc.getZone('zonename') if zone then targetCord =zone.point end Move_Group_to_other_Group_Location.miz Edited May 30 by Kanelbolle added trigger zone WARGAMES Servers: https://forum.dcs.world/topic/301046-wargames-server-pvp-and-pve-campaign-servers/ Scripts: RGC & SPGG https://github.com/AGluttonForPunishment/
Recommended Posts