Skynet99 Posted February 14, 2023 Posted February 14, 2023 Hi, I've been thinking about creating a dynamic flight plan creator. I'm using the latest openbeta, tried it on a syria map. So far I've got this code: -- Define the altitude at which the waypoints will be added (in meters) local ALTITUDE = 1500 -- Define the maximum number of waypoints the player can add local MAX_WAYPOINTS = 15 -- Create an empty table to store the player's waypoints local playerWaypoints = {} -- Define a function to create a waypoint based on a map marker function createWaypointFromMarker(marker, player) -- Get the coordinates of the map marker local point = marker:getPoint() -- Create a new waypoint at the same coordinates local waypoint = { ["type"] = "Turning Point", ["action"] = "Turning Point", ["altitude"] = ALTITUDE, ["alt_type"] = "BARO", ["speed"] = 150, ["x"] = point.x, ["y"] = point.z, ["name"] = "Waypoint " .. #Group.getByName(player:getClientGroup():getName()):getWaypoints() + 1, ["task"] = { ["id"] = "ComboTask", ["params"] = { ["tasks"] = { { ["enabled"] = true, ["id"] = "EngageTargets", ["number"] = 1, ["params"] = { ["expend"] = "Jettison", ["weaponType"] = 2032 } } } } } } -- Add the new waypoint to the group Group.getByName(player:getClientGroup():getName()):getController():pushTask(waypoint) end function onPlayerAddMarker(eventName, args) local clientName = args.initiator:getClientName() if clientName ~= nil then -- Get the player's coalition local coalition = args.initiator:getCoalition() -- Get the map marker based on the name of the marker group and the text of the marker local markerGroup = coalition.getGroups(coalition, Group.Category.MARKER) for _, group in pairs(markerGroup) do if group:getName() == args.groupName then for _, marker in pairs(group:getMarkers()) do if marker:getName() == args.text then -- Add a new waypoint based on the map marker local client = args.initiator:getClientGroup():getUnits()[1] if not playerWaypoints[client] then playerWaypoints[client] = {} end if #playerWaypoints[client] < MAX_WAYPOINTS then createWaypointFromMarker(marker, client) table.insert(playerWaypoints[client], marker) trigger.action.outTextForGroup(client:getGroup():getID(), "Added waypoint " .. #playerWaypoints[client], 5) else trigger.action.outTextForGroup(client:getGroup():getID(), "You have reached the maximum number of waypoints (" .. MAX_WAYPOINTS .. ")", 5) end break end end break end end end end -- Register the event handler for the "mark_added" event -- This event is triggered when a player adds a new marker on the F10 map world.addEventHandler("mark_added", onPlayerAddMarker) I load up the mission, and jump into a client A-10C and when I try to add a marker on the F10 Map I get the error: (See attached) Anyone got any ideas how this could be resolved. If this is something that DCS is currently not supporting please also let me know. Thanks in advance!
TEMPEST.114 Posted February 14, 2023 Posted February 14, 2023 I believe you should be using the world enum not "mark_added" e.g. Quote world.event.S_EVENT_MARK_ADDED
Chump Posted February 14, 2023 Posted February 14, 2023 Your event handler is incorrect, and some other errors. Here is a suggestion on how to handle events: local function onPlayerAddMarker(event) local unit = event.initiator if unit and event.id == world.event.S_EVENT_MARK_ADDED then local clientName = unit:getPlayerName() if clientName then -- get some values local coalition = unit:getCoalition() local group = unit:getGroup() local markId = event.idx local markText = event.text local markPosition = event.pos -- do your stuff here end end end local eventHandler = { f = onPlayerAddMarker } function eventHandler:onEvent(e) self.f(e) end world.addEventHandler(eventHandler)
Skynet99 Posted February 14, 2023 Author Posted February 14, 2023 (edited) 2 hours ago, Elphaba said: I believe you should be using the world enum not "mark_added" e.g. "mark_added" is the name, so it can be anything as far as I know. (but I get what you mean) 2 hours ago, Chump said: Your event handler is incorrect, and some other errors. Here is a suggestion on how to handle events: local function onPlayerAddMarker(event) local unit = event.initiator if unit and event.id == world.event.S_EVENT_MARK_ADDED then local clientName = unit:getPlayerName() if clientName then -- get some values local coalition = unit:getCoalition() local group = unit:getGroup() local markId = event.idx local markText = event.text local markPosition = event.pos -- do your stuff here end end end local eventHandler = { f = onPlayerAddMarker } function eventHandler:onEvent(e) self.f(e) end world.addEventHandler(eventHandler) I'll give this one a try, thank you! Edited February 14, 2023 by Skynet99
Grimes Posted February 14, 2023 Posted February 14, 2023 IIRC there is a bug where event.initiator on the mark events is missing in single player but it works just fine in multiplayer. 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
Recommended Posts