KnightHawk75
Posts: 1450
Joined: 11/15/2018 Status: offline
|
Your problem there is primarily that RelocateSubs in theory there takes a unitwrapper as a param, and not a unit guid. So either need to SE_GetUnit in the function or get it before hand and pass it in. There are other issues with missing ')' and '{''s You are also calling GetLocation that gets elevation and landtype data etc data I don't think you want there, not yet anyway, I think you mean to call World_GetPointFromBearing Ie...should look more like this:
function RelocateSub (theside, unitguid)
local retval,unit = pcall(ScenEdit_GetUnit,{guid=unitguid})
if (retval ==true) and theunit ~=nil then --if the call returned successfully and unit looks valid.
math.randomseed(os.time())
math.random();
local rbearing=math.random(1,359)
local rdistance=math.random(25,100)
local newloc=World_GetPointFromBearing({latitude=unit.latitude, longitude=unit.longitude, DISTANCE=rdistance, BEARING=rbearing})
if newloc ~nil and type(newloc) == 'table' --is valid return table indicating some form.
u.latitude = newloc.Latitude --no need for set unit if already have unitwrapper.
u.longitude = newloc.Longitude --no need for set unit if already have unitwrapper.
--... other stuff if needed... like you aren't checking if this particular location is actually water. ;)
--... but maybe for your circumstances it's not an issue and don't need the complication
end
else
print("could not obtain unit with guid" .. unitguid
end
end
local someListOfSubGuids = {'W7ZXL3-0HM9G95HNBS56'}
For k,v in pairs(someListofSubGuids) do
RelocateSubs ("USSR", v)
end
There is code buried somewhere in the forum (edit nm found it) already for random unit location generation from Whicker and I some years back. http://www.matrixgames.com/forums/fb.asp?m=4587348 Should work for your basic needs (and deals with depth checking). But if you need something more advanced ask, as I have another way more advanced one including random pathing toward target generation as well as other stuff (EX zone checking) but sounds like it would be overkill for you needs atm.
< Message edited by KnightHawk75 -- 6/20/2021 6:26:19 AM >
|