Page 1 of 1
moving reference points
Posted: Sun Apr 19, 2020 12:56 pm
by orca
I'm trying to create a script in which the reference points for a fighter sweep (fs1 and fs2) change from the baseline by +/- 1 longitude and latitude. Below is the script I created but I get an error which seems to be because I can't use a negative number. Is there a way to use a negative number in this script?
delta=math.random(-1,1)
local lat1=-11.1891527175903
local lon2=155.851684570313
local lat2=-12.6824102401733
local lon2=156.514694213867
local newlat1=lat1 + delta
local newlon1=lon1 + delta
local newlat2=lat2 + delta
local newlon2=lon2 + delta
ScenEdit_SetReferencePoint({side='Axis', name='fs1', lat=newlat1, lon=newlon1})
ScenEdit_SetReferencePoint({side='Axis', name='fs2', lat=newlat2, lon=newlon2})
thanks
RE: moving reference points
Posted: Sun Apr 19, 2020 7:09 pm
by KnightHawk75
ORIGINAL: orca
I'm trying to create a script in which the reference points for a fighter sweep (fs1 and fs2) change from the baseline by +/- 1 longitude and latitude. Below is the script I created but I get an error which seems to be because I can't use a negative number. Is there a way to use a negative number in this script?
delta=math.random(-1,1)
local lat1=-11.1891527175903
local lon2=155.851684570313
local lat2=-12.6824102401733
local lon2=156.514694213867
local newlat1=lat1 + delta
local newlon1=lon1 + delta
local newlat2=lat2 + delta
local newlon2=lon2 + delta
ScenEdit_SetReferencePoint({side='Axis', name='fs1', lat=newlat1, lon=newlon1})
ScenEdit_SetReferencePoint({side='Axis', name='fs2', lat=newlat2, lon=newlon2})
thanks
I think it's simply that
local
lon2 = 155.851684570313;
Should read lon1 correct ? local
lon1 = 155.851684570313 change works fine for me.
should probably be a local 'delta' as well unless otherwise needed to be global.
RE: moving reference points
Posted: Fri May 01, 2020 1:06 am
by orca
Thanks, that was it. The script works now.
But after using it I realize it only works for reference points without relativity. But it doesn't work with RPs that are relative to an unit. This is because when the script is run the RP moves as it should from the script, but then it immediately goes back to the position relative to the unit. Any ideas on how to make it work with relative reference points?
Would I need to remove relativity, then move the reference point, then add back the relativity? I might be able to try to do that. Except I don't know get reference point coordinates and then insert these new coordinates into the script.
This is probably requires more LUA expertise that I have but if you know of an relatively easy way to accomplish this let me know.
Thanks
ORIGINAL: KnightHawk75
ORIGINAL: orca
I'm trying to create a script in which the reference points for a fighter sweep (fs1 and fs2) change from the baseline by +/- 1 longitude and latitude. Below is the script I created but I get an error which seems to be because I can't use a negative number. Is there a way to use a negative number in this script?
delta=math.random(-1,1)
local lat1=-11.1891527175903
local lon2=155.851684570313
local lat2=-12.6824102401733
local lon2=156.514694213867
local newlat1=lat1 + delta
local newlon1=lon1 + delta
local newlat2=lat2 + delta
local newlon2=lon2 + delta
ScenEdit_SetReferencePoint({side='Axis', name='fs1', lat=newlat1, lon=newlon1})
ScenEdit_SetReferencePoint({side='Axis', name='fs2', lat=newlat2, lon=newlon2})
thanks
I think it's simply that
local
lon2 = 155.851684570313;
Should read lon1 correct ? local
lon1 = 155.851684570313 change works fine for me.
should probably be a local 'delta' as well unless otherwise needed to be global.
RE: moving reference points
Posted: Fri May 01, 2020 2:37 am
by KnightHawk75
Any ideas on how to make it work with relative reference points?
No I can't think of anything off top my head, other than moving the unit it's relative too, or just stop making them relative and handle any relative movement yourself.
Would I need to remove relativity, then move the reference point, then add back the relativity? I might be able to try to do that. Except I don't know get reference point coordinates and then insert these new coordinates into the script.
Like you said though the game will just move it back. So restoring the relativity will just make that happen again. But if some reason that I don't follow you want to do that, or for another instance of a related problem.
Use can use ScenEdit_GetReferencePoint({side='blue',name='RP-297'}) to get the details back of a given RP.
You'll want to store the units relativeto field, which if nil means it's not set, if it exists it's the unit's name.
Then set the referncepoint with relativeto='none' specified. Then run set again with realtiveto='the unitname saved before'
Would look something like this.
Code: Select all
local Function doMyReferencepoint(s,n,x,y)
local a = ScenEdit_GetReferencePoint({side=s,name=n})
if(a ~=nil)
local restorevalue = a.relativeto or 'none' -- <-- will 'none' if a.relativeto is nil
ScenEdit_SetReferencePoint({side=s,guid=a.guid,longitude=x,latitude=y,relativeto='none'})
ScenEdit_SetReferencePoint({side=s,guid=a.guid,relativeto=restorevalue})
restorevalue= nil;
else
print('could not obtain reference point data.');
return false;
end
a=nil;
return true;
end
doMyReferncePoint('Blue','RP-297',123.01234,90.45600)
RE: moving reference points
Posted: Fri May 01, 2020 2:43 am
by michaelm75au
Relative RPs are based on the bearing and distance from an unit. So they don't really have a fixed location (lat,long) as such.