Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GetRandomLocation = function(self, x, z, radius)
- if not x or not z then return end
- local radius = radius or 30
- local Params = self:GetHologramParams()
- local Parent = self:GetParentUnit()
- local MyPos = self:GetPosition()
- local ParentPos = Parent:GetPosition()
- local movePos = {}
- local keeplooking = true
- while keeplooking do
- local finalX = x + Random(-radius, radius)
- while finalX <= 0 or finalX >= ScenarioInfo.size[1] do
- finalX = x + Random(-radius, radius)
- end
- local finalZ = z + Random(-radius, radius)
- while finalZ <= 0 or finalZ >= ScenarioInfo.size[2] do
- finalZ = z + Random(-radius, radius)
- end
- movePos = { finalX, 0, finalZ }
- local height
- if self:GetCurrentLayer() == 'Seabed' or self:GetCurrentLayer() == 'Land' then
- height = GetTerrainHeight(movePos[1], movePos[3]) + GetTerrainTypeOffset(movePos[1], movePos[3])
- else
- height = GetSurfaceHeight(movePos[1], movePos[3]) + GetTerrainTypeOffset(movePos[1], movePos[3])
- end
- if EntityCategoryContains(categories.AIR, self) then
- local ran = Random(2, 10)
- movePos[2] = height + ran
- self:SetElevation(ran)
- else
- movePos[2] = height
- end
- if VDist3(ParentPos, movePos) <= radius then
- keeplooking = false
- end
- end
- return movePos
- end,
Add Comment
Please, Sign In to add comment