Guest User

Untitled

a guest
Jan 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. GetRandomLocation = function(self, x, z, radius)
  2.         if not x or not z then return end
  3.         local radius = radius or 30
  4.         local Params = self:GetHologramParams()
  5.         local Parent = self:GetParentUnit()
  6.         local MyPos = self:GetPosition()
  7.         local ParentPos = Parent:GetPosition()
  8.         local movePos = {}
  9.         local keeplooking = true
  10.        
  11.         while keeplooking do
  12.             local finalX = x + Random(-radius, radius)
  13.             while finalX <= 0 or finalX >= ScenarioInfo.size[1] do
  14.                 finalX = x + Random(-radius, radius)
  15.             end
  16.        
  17.             local finalZ = z + Random(-radius, radius)
  18.             while finalZ <= 0 or finalZ >= ScenarioInfo.size[2] do
  19.                 finalZ = z + Random(-radius, radius)
  20.             end
  21.        
  22.             movePos = { finalX, 0, finalZ }
  23.            
  24.             local height
  25.             if self:GetCurrentLayer() == 'Seabed' or self:GetCurrentLayer() == 'Land' then
  26.                 height = GetTerrainHeight(movePos[1], movePos[3]) + GetTerrainTypeOffset(movePos[1], movePos[3])
  27.             else
  28.                 height = GetSurfaceHeight(movePos[1], movePos[3]) + GetTerrainTypeOffset(movePos[1], movePos[3])
  29.             end
  30.                    
  31.             if EntityCategoryContains(categories.AIR, self) then
  32.                 local ran = Random(2, 10)
  33.                 movePos[2] = height + ran
  34.                 self:SetElevation(ran)
  35.             else
  36.                 movePos[2] = height
  37.             end
  38.                                    
  39.             if VDist3(ParentPos, movePos) <= radius then
  40.                 keeplooking = false
  41.             end
  42.         end
  43.         return movePos
  44.     end,
Add Comment
Please, Sign In to add comment