SetReferencePoint + Bearing/Distance

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
Parel803
Posts: 932
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

SetReferencePoint + Bearing/Distance

Post by Parel803 »

Good evening,

I added a RP with:

Code: Select all

local u = ScenEdit_GetUnit ({name='CVN 78 Gerald R. Ford', guid='KO61QJ-0HMTE5ENVLTKH'})
ScenEdit_AddReferencePoint({side = 'Nessik', name = 'Z5', relativeto = u.guid, bearingtype=0, bearing=180, distance=10})
Works nicely.
To Set with:

Code: Select all

local u = ScenEdit_GetUnit ({name='CVN 78 Gerald R. Ford', guid='KO61QJ-0HMTE5ENVLTKH'})
ScenEdit_SetReferencePoint({side = 'Nessik', name = 'Z1', relativeto = u.guid, bearingtype=0, bearing=180, distance=10})
Did not work. Made a mistake somewere or is it not possible.

I now used the B/D to Lat/Long I found on the forum (with input box)

Code: Select all

local function GetNumberFromUser(displaytext, minnum, maxnum, errornum)
    local retval = ScenEdit_InputBox(displaytext)
    if retval ~= nil and retval ~= "" then
        retval = tonumber(retval)
        if retval == nil then
            return errornum
        end
    else
        return errornum
    end
    if retval >= minnum and retval <= maxnum then
        return retval
    end
    return errornum
end

-- Create Reference Points Function
local function SetRpsScreen()
    local zz = ScenEdit_GetUnit({name='A 834 Den Helder', guid='KO61QJ-0HMTE5ENVLTR9'})

    local leftBearing = GetNumberFromUser('Enter left bearing (1-360):', 1, 360, 0)
    local rightBearing = GetNumberFromUser('Enter right bearing (1-360):', 1, 360, 0)
    local minDistance = GetNumberFromUser('Enter minimum distance:', 0, 100, 0)
    local maxDistance = GetNumberFromUser('Enter maximum distance:', minDistance, 100, 0)

Code: Select all

    local pt1 = World_GetPointFromBearing({ LATITUDE = zz.latitude, LONGITUDE = zz.longitude, BEARING = leftBearing, DISTANCE = minDistance })
    local pt2 = World_GetPointFromBearing({ LATITUDE = zz.latitude, LONGITUDE = zz.longitude, BEARING = leftBearing, DISTANCE = maxDistance })
    local pt3 = World_GetPointFromBearing({ LATITUDE = zz.latitude, LONGITUDE = zz.longitude, BEARING = rightBearing, DISTANCE = maxDistance })
    local pt4 = World_GetPointFromBearing({ LATITUDE = zz.latitude, LONGITUDE = zz.longitude, BEARING = rightBearing, DISTANCE = minDistance })

    ScenEdit_SetReferencePoint({ side = "Nessik", name = "Z1", lat = pt1.latitude, long = pt1.longitude, relativeto=zz.guid, bearingtype=0 })
    ScenEdit_SetReferencePoint({ side = "Nessik", name = "Z2", lat = pt2.latitude, long = pt2.longitude, relativeto=zz.guid, bearingtype=0 })
    ScenEdit_SetReferencePoint({ side = "Nessik", name = "Z3", lat = pt3.latitude, long = pt3.longitude, relativeto=zz.guid, bearingtype=0 })
    ScenEdit_SetReferencePoint({ side = "Nessik", name = "Z4", lat = pt4.latitude, long = pt4.longitude, relativeto=zz.guid, bearingtype=0 })
end

SetRpsScreen()
Regards GJ
User avatar
blu3s
Posts: 989
Joined: Fri Jul 08, 2022 9:45 am

Re: SetReferencePoint + Bearing/Distance

Post by blu3s »

If you want to change the name of the RP via SetReferencePoint you need to provide both, name and newname


Untitled.png
Untitled.png (25.16 KiB) Viewed 819 times

If you are adding RP you should use in your function AddReferencePoint and not SetReferencePoint, if you are changing RP coordinates SetReferencePoint works fine

Regards
Parel803
Posts: 932
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: SetReferencePoint + Bearing/Distance

Post by Parel803 »

Blu3s,

Thank you for your time and answer.
I was wondering if you could you SetRP for a relative RP by giving the line a bearing and distance, just to change it's position.

regards GJ
User avatar
blu3s
Posts: 989
Joined: Fri Jul 08, 2022 9:45 am

Re: SetReferencePoint + Bearing/Distance

Post by blu3s »

You can calculate the new position with the function

https://commandlua.github.io/assets/Fun ... earing.htm

I dont' thnkt that SetRP allows you to enter a bearing and a distance unless you are referring to a point relative to a unit.
Parel803
Posts: 932
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: SetReferencePoint + Bearing/Distance

Post by Parel803 »

Blu3s,

Thank you, understood.

regards GJ
Post Reply

Return to “Lua Legion”