I think you can do it in the GUI because, well once you could. Then you couldn't for a long while, then people brought it up and I think gui wise they brought it back. The actual "why" is the lua function code was never changed to add a parameter for what side to search for the unit, at present it uses the side specified in the SE_AddReferencePoint(), or SE_SetReference point() calls for it's RP search, it does not search all sides.
Either we need a relativeto_side parameter in both functions, or the lookup needs to do the own-side first (most common), followed by then searching all the rest of the sides for a guid match. Ideally it would would just accept an additional parameter and use that for the relative-to search for the unit.
In short I agree this does need some developer love.
btw if want for future (handles selected unit or selected contact)
Code: Select all
local function getSingleSelectedUnitsOrContactsUnit()
local s,ug = ScenEdit_SelectedUnits(),nil
if (s.units ~=nil) and s.units[1] ~=nil and #s.units <=1 then --try units first.
ug=s.units[1].guid
elseif (s.contacts ~=nil) and s.contacts[1] ~=nil and #s.contacts <=1 then --try contacts
-- get contact's underling unit object.
retval,ct = pcall(VP_GetContact,{guid=s.contacts[1].guid});
if (retval) and ct ~=nil and ct.actualunitid ~=nil then
ug = ct.actualunitid; --actual unitguid
else
print("failed to get the contact for guid: " .. s.contacts[1].guid .. " this could be known bug in Tiny if base\airbase.");
end
else
print('Please select only one contact or only one unit.')
end
if ug ~=nil then
retval, unit = pcall(ScenEdit_GetUnit,{guid=ug});
if (retval) and unit ~=nil then return unit; end
else
print("selected unit or selected contact could not be obtained.")
end
return nil;
end
local function CreateRelativeRefPointsToUnit(rpside,unit,rpnameprefix,distance,stepping)
if rpside ==nil then print("failed to specifiy a side, call aborted.") return false; end
if (unit ==nil) or unit.guid ==nil then print("failed to supply a unit wrapper, call aborted.") return false; end
if (distance==nil) or type(distance) ~="number" then distance = 20; end
if (stepping ==nil) or type(stepping) ~="number" then stepping = 20; end
local customname = false;
if (rpnameprefix==nil) then customname=false; else customname=true;end
for i=0,359, stepping do
local coordinates=World_GetPointFromBearing({latitude=unit.latitude, longitude=unit.longitude, bearing=i, distance=distance})
if customname then
local retval,rp = pcall(ScenEdit_AddReferencePoint,{side=rpside, name=rpnameprefix .."-"..i, bearingType=0, latitude=coordinates.latitude, longitude=coordinates.longitude,highlighted=false})
--future build local retval,rp = pcall(ScenEdit_AddReferencePoint,{side=rpside, relativeto=unit.guid,relativeto_side=unit.side,bearingType=0, latitude=coordinates.latitude, longitude=coordinates.longitude,highlighted=false})
else
local retval,rp = pcall(ScenEdit_AddReferencePoint,{side=rpside, bearingType=0, latitude=coordinates.latitude, longitude=coordinates.longitude,highlighted=false})
--future build local retval,rp = pcall(ScenEdit_AddReferencePoint,{side=rpside, relativeto=unit.guid,relativeto_side=unit.side,bearingType=0, latitude=coordinates.latitude, longitude=coordinates.longitude,highlighted=false})
end
if not retval then
print("Failed to create RP: ".. tostring(rp));
end
end
end
CreateRelativeRefPointsToUnit("Blue",getSingleSelectedUnitsOrContactsUnit(),"testing");