HungryCoyote Posted October 30, 2024 Posted October 30, 2024 How would you script a simple option to spawn a unit at an F10 Mark Label?
cfrag Posted October 30, 2024 Posted October 30, 2024 6 hours ago, HungryCoyote said: How would you script a simple option to spawn a unit at an F10 Mark Label? Trap one of the mark events (e.g. S_EVENT_MARK_ADDED), get the pos field for the position, spawn the group there. Your logical next step would be to analyze the mark text and use that to allow you to specify what kind of units to spawn Next thing you know, you have built yourself an interactive debugger. Great exercise, incredibly powerful tool for your missions.
HungryCoyote Posted October 31, 2024 Author Posted October 31, 2024 (edited) That is way over my head. I spent the last two days just trying to learn how to use simple lua in a dcs script file. I managed to go from print ("Hello, World!") --works in lua compiler but not in DCS to local function message() msg1 = "Hello, World!" trigger.action.outText(msg1, 12) end message() --works in DCS but not in compiler This would have taken me five minutes by using the Trigger Action / Message to All edit: I added this. It does not work but at least it is not giving me any errors. So that is something. local requestM = missionCommands.addSubMenu('Request Asset') local subN1 = missionCommands.addSubMenu('Spawn Tank', requestM) local function marker() Event = { id = 25, idx = 3, time = 1, initiator = 'Player', coalition = 2, groupID = 3, text = 'spawn', pos = vec3} end marker() local function spawn() vars = { groupName = 'Tank', point = pos, action = 'clone', } end spawn() Edited October 31, 2024 by HungryCoyote
Solution cfrag Posted November 2, 2024 Solution Posted November 2, 2024 (edited) On 10/31/2024 at 11:50 AM, HungryCoyote said: I spent the last two days just trying to learn how to use simple lua in a dcs script file. I managed to go from print ("Hello, World!") --works in lua compiler but not in DCS That is because DCS's Lua API hates you. With a vengeance. What we have in DCS to support mission scripting is ill thought-out, does not seem to be engineered at all, and is unnecessarily difficult for neophytes who already do know how to program in Lua. That being said, maybe I misunderstood your requirements. What are you trying to accomplish: spawn some units at an in-game event (via F-10) at a pre-determined location, which happens to be a Mark (meaning that the spwan location is known when the mission starts up) or spawn some units at an in-game event at a dynamic, runtime player-determined location Above cases are very different. Both require spawning units. And spawning units at runtime (as opposed to late activation) is one hellish thing to learn simply because it requires you to absorb large parts of DCS's abysmal API and idiosyncrasies. It's one of the reasons why so many prefer using frameworks. Once you get beyond that, however, you have a powerful too at your disposal to create significantly better missions. So, if "all" you need is to spawn units at some player-determined time, you will have to learn how to script spawning. Getting it done is painful, but manageable. Becoming good at it takes longer. Once you can spawn, however, since you know the location, the rest is straightforward. Spawning units at a player-determined location requires a lot more, through. You can try and simplify the coding challenge by off-loading some complexity to the player (e.g. the mark must have a very specific text), but DCS provides very little by way of player script integration, so doing that will require a lot more understanding of DCS's API. So if you are looking to solve bullet two, you'll be in for quite a ride. That does not mean that it's not worth the challenge, though. I'm close to being addicted to coding, and DCS's terrible API doesn't scare me any more. It still infuriates me, yes, but once you learn and abide by the silly nonsense, creating good missions in spite of the terrible API can be quite rewarding. Edited November 3, 2024 by cfrag 1
HungryCoyote Posted November 3, 2024 Author Posted November 3, 2024 I wanted to have players place a mark on F10 map, Give it a specific name, then use comms menu to spawn late activated unit. This can already be done using Gamemaster or FatCow scripts. i wanted to make my own script that did a similar thing so I could edit it to my own needs. I looked at those lua files but there was so much extra stuff in them that i could not figure out exactly how they work. Definitely need to learn more basic coding first.
Recommended Posts