Get Circle/Make RP not working

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
vettim89
Posts: 3650
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

Get Circle/Make RP not working

Post 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
"We have met the enemy and they are ours" - Commodore O.H. Perry
KnightHawk75
Posts: 1556
Joined: Thu Nov 15, 2018 7:24 pm

RE: Get Circle/Make RP not working

Post 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)
 
 
User avatar
vettim89
Posts: 3650
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

RE: Get Circle/Make RP not working

Post 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
"We have met the enemy and they are ours" - Commodore O.H. Perry
Post Reply

Return to “Lua Legion”