Page 1 of 1

Get Circle/Make RP not working

Posted: Mon Mar 22, 2021 10:13 pm
by vettim89
I modified this function from Knighhawk to pass a side, unit, and radius of a circle or RP

local function BuildCircleOfRPs(theside,pguid, range)
local unit=ScenEdit_GetUnit({guid=pguid})
local tableofcirclepoints = World_GetCircleFromPoint({latitude=unit.latitude,longitude=unit.longitude,numpoints=12,radius=range})
local counter = 1;
for k,v in ipairs(tableofcirclepoints) do
ScenEdit_AddReferencePoint({side=theside,latitude=v.latitude,longitude=v.longitude, relativeto=unit.guid, name=unit.name .. "-" .. counter})
counter = counter +1;
end
end

The call is

local patrol=ScenEdit_UnitX()
local function BuildCircleOfRPs('Iran',patrol.guid,1)

So basically when a patrol boat undocks it enters a zone that should trigger the event and then have a circle of RPs generated around the PB

This is not working

RE: Get Circle/Make RP not working

Posted: Tue Mar 23, 2021 2:48 am
by KnightHawk75
You're not calling your function, you're redefining it in the last line.

You also don't need counter here?
Also if you already have the unit wrapper from UnitX call why pass the guid and get the unit again, you can just pass the wrapper itself.

try

Code: Select all

 local function BuildCircleOfRPs(theside, unit, range)
   local tableofcirclepoints = World_GetCircleFromPoint({latitude=unit.latitude,longitude=unit.longitude,numpoints=12,radius=range})
   for k,v in ipairs(tableofcirclepoints) do
     ScenEdit_AddReferencePoint({side=theside,latitude=v.latitude,longitude=v.longitude, relativeto=unit.guid, name=unit.name .. "-" .. counter})
   end
 end
 
 local patrol=ScenEdit_UnitX()
 BuildCircleOfRPs('Iran',patrol,1)
 
 

RE: Get Circle/Make RP not working

Posted: Tue Mar 23, 2021 8:17 pm
by vettim89
ORIGINAL: KnightHawk75

You're not calling your function, you're redefining it in the last line.

You also don't need counter here?
Also if you already have the unit wrapper from UnitX call why pass the guid and get the unit again, you can just pass the wrapper itself.

try

Code: Select all

 local function BuildCircleOfRPs(theside, unit, range)
   local tableofcirclepoints = World_GetCircleFromPoint({latitude=unit.latitude,longitude=unit.longitude,numpoints=12,radius=range})
   for k,v in ipairs(tableofcirclepoints) do
     ScenEdit_AddReferencePoint({side=theside,latitude=v.latitude,longitude=v.longitude, relativeto=unit.guid, name=unit.name .. "-" .. counter})
   end
 end
 
 local patrol=ScenEdit_UnitX()
 BuildCircleOfRPs('Iran',patrol,1)
 
 

That fixed it, thanks as always