moving reference points

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
orca
Posts: 545
Joined: Wed Nov 06, 2013 4:59 pm

moving reference points

Post 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
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: moving reference points

Post 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.
orca
Posts: 545
Joined: Wed Nov 06, 2013 4:59 pm

RE: moving reference points

Post 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.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: moving reference points

Post 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)
 
User avatar
michaelm75au
Posts: 12465
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: moving reference points

Post 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.
Michael
Post Reply

Return to “Lua Legion”