Since I'm not very smart with the Lua first question:
I made a initiate of a circle on a selected unit with input box. The question is if it is possible to do this on a contact. I think I need the Lat/Long of the selected contact and with that the GuiD of it's unit version?
I thought I had help on soething like this but could not found the correct one in the forum.
Code: Select all
-- Function to get the selected unit's GUID and latitude/longitude
local function getSelectedUnitInfo()
local selectedUnits = ScenEdit_SelectedUnits()
if selectedUnits ~= nil then
if selectedUnits.units ~= nil and #selectedUnits.units == 1 then
local unitGuid = selectedUnits.units[1].guid
local unitInfo = ScenEdit_GetUnit({ guid = unitGuid })
if unitInfo and unitInfo.latitude and unitInfo.longitude then
return unitGuid, unitInfo.latitude, unitInfo.longitude
else
print("Selected unit does not have latitude and longitude information.")
end
else
print("Please select a single unit.")
end
else
print("No units selected.")
end
return nil, nil, nil
end
Code: Select all
-- Fixed number of reference points
local numReferencePoints = 4 -- temp 4 to ease the next step
-- Function to create a circle of reference points around a specified location
local function createCircleReferencePoints(numReferencePoints, latitude, longitude, range)
if latitude and longitude then
local circle = World_GetCircleFromPoint({
latitude = latitude,
longitude = longitude,
numpoints = numReferencePoints,
radius = range
})
for index, point in ipairs(circle) do
local rp = ScenEdit_AddReferencePoint({
side = 'Blue',
name = 'tst ' .. index,
latitude = point.latitude,
longitude = point.longitude
})
end
end
end
-- Modify this value to set the desired range (in nautical miles)
local range = 25
-- Call the function to get the selected unit's info
local unitGuid, latitude, longitude = getSelectedUnitInfo()
-- Call the function to create a circle of reference points around the selected unit's location with the fixed number of reference points
createCircleReferencePoints(numReferencePoints, latitude, longitude, range)
best regards GJ