Slazi Posted July 27, 2014 Share Posted July 27, 2014 Can anyone provide a minimal script to spawn a unit? I've been looking at CCTS for examples, but there are a lot of connections in there to decode. I'm sure I could do it given the time, but if anyone has a simpler version it would help me out a lot. Ideally I want to just spawn a unit next to / near another unit. Link to comment Share on other sites More sharing options...
Slazi Posted July 30, 2014 Author Share Posted July 30, 2014 Harder than I expected, I guess. I'll try and post one once I figure it out then! Link to comment Share on other sites More sharing options...
FSFIan Posted July 30, 2014 Share Posted July 30, 2014 (edited) Taken from the "Spawn HMMWV (Lua Interaction)" example of DCS Witchcraft: local unitsTable = { ["visible"] = false, ["taskSelected"] = true, ["route"] = { ["spans"] = { }, -- end of ["spans"] ["points"] = { [1] = { ["alt"] = event.vec3.y, ["type"] = "Turning Point", ["ETA"] = 0, ["alt_type"] = "BARO", ["formation_template"] = "", ["y"] = event.vec2.y, ["x"] = event.vec2.x, ["ETA_locked"] = true, ["speed"] = 5.5555555555556, ["action"] = "Off Road", ["task"] = { ["id"] = "ComboTask", ["params"] = { ["tasks"] = { [1] = { ["enabled"] = true, ["auto"] = true, ["id"] = "WrappedAction", ["number"] = 1, ["params"] = { ["action"] = { ["id"] = "EPLRS", ["params"] = { ["value"] = true, ["groupId"] = 2, }, -- end of ["params"] }, -- end of ["action"] }, -- end of ["params"] }, -- end of [1] }, -- end of ["tasks"] }, -- end of ["params"] }, -- end of ["task"] ["speed_locked"] = true, }, -- end of [1] }, -- end of ["points"] }, -- end of ["route"] ["groupId"] = 30, ["tasks"] = { }, -- end of ["tasks"] ["hidden"] = false, ["units"] = { [1] = { ["y"] = event.vec2.y, ["type"] = "M1043 HMMWV Armament", ["name"] = "cursor_unit", ["unitId"] = 30, ["heading"] = witchcraft.heading, ["playerCanDrive"] = true, ["skill"] = "Average", ["x"] = event.vec2.x, }, -- end of [1] }, -- end of ["units"] ["y"] = event.vec2.y, ["x"] = event.vec2.x, ["name"] = "CursorGroup", ["start_time"] = 0, ["task"] = "Ground Nothing", } unitsTable.country = "USA" unitsTable.category = "vehicle" if copy then unitsTable.groupId = nil unitsTable.name = nil unitsTable.units[1].unitId = nil unitsTable.units[1].name = nil end mist.dynAdd(unitsTable) See also: mist.dynAdd documentation In this case: event.vec2 is the position where the HMMWV will be spawned witchcraft.heading is the initial heading It's not a minimal example, but it comes close. The general idea is that you provide a table like the mission editor would generate and then add country and category attributes before calling mist.dynAdd. If you provide a group ID or name, the spawned group will replace an already existing group with the same identifier. If you want to spawn the unit relative to another one, use someting like local spawn_vec3 = Group.getByName("SomeGroup"):getUnit(1):getPosition() local spawn_vec2 = { x = spawn_vec3.x, y = spawn_vec3.z } Shameless plug: You may want to install DCS Witchcraft, which provides a Lua debug console. Select the "Spawn HMMWV" template, then modify it to suit your needs. If you write custom Lua scripts, the 15 minutes setting up DCS Witchcraft will save you a lot of debugging time down the road because if a code snippet does not work, you can fix the error and try it seconds later without having to reload the mission. Edited July 30, 2014 by [FSF]Ian 1 DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua Link to comment Share on other sites More sharing options...
Slazi Posted August 1, 2014 Author Share Posted August 1, 2014 Thanks, [FSF]Ian. I'll have to take a look at this on the weekend. Link to comment Share on other sites More sharing options...
number3 Posted August 18, 2014 Share Posted August 18, 2014 [FSF]Ian, Can you explain the purpose of this batch of code? if copy then unitsTable.groupId = nil unitsTable.name = nil unitsTable.units[1].unitId = nil unitsTable.units[1].name = nil end 314-я смешанная авиационная дивизия 314th Mixed Aviation Division: The "Fighting Lemmings"- Forums: http://314thsquadron.enjin.com/ - ED Forum Group: http://forums.eagle.ru/group.php?groupid=119 Link to comment Share on other sites More sharing options...
FSFIan Posted August 19, 2014 Share Posted August 19, 2014 In this case (the "spawn HMMWV" example snippet), the "copy" variable holds a boolean that determines if the (existing) group should be moved or a copy should be created. If you look at the documentation of mist.dynAdd, you will see that it will create a new group if you pass an empty group name and group ID. 1 DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua Link to comment Share on other sites More sharing options...
number3 Posted August 19, 2014 Share Posted August 19, 2014 Thanks for clarifying! 314-я смешанная авиационная дивизия 314th Mixed Aviation Division: The "Fighting Lemmings"- Forums: http://314thsquadron.enjin.com/ - ED Forum Group: http://forums.eagle.ru/group.php?groupid=119 Link to comment Share on other sites More sharing options...
Recommended Posts