Guest User

Untitled

a guest
Jan 21st, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. function isInRange(position, fromPosition, toPosition)
  2. return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
  3. end
  4.  
  5. function getDistanceBetween(fromPosition, toPosition)
  6. local x, y = math.abs(fromPosition.x - toPosition.x), math.abs(fromPosition.y - toPosition.y)
  7. local diff = math.max(x, y)
  8. if(fromPosition.z ~= toPosition.z) then
  9. diff = diff + 9 + 6
  10. end
  11.  
  12. return diff
  13. end
  14.  
  15. function getDirectionTo(pos1, pos2)
  16. local dir = NORTH
  17. if(pos1.x > pos2.x) then
  18. dir = WEST
  19. if(pos1.y > pos2.y) then
  20. dir = NORTHWEST
  21. elseif(pos1.y < pos2.y) then
  22. dir = SOUTHWEST
  23. end
  24. elseif(pos1.x < pos2.x) then
  25. dir = EAST
  26. if(pos1.y > pos2.y) then
  27. dir = NORTHEAST
  28. elseif(pos1.y < pos2.y) then
  29. dir = SOUTHEAST
  30. end
  31. else
  32. if(pos1.y > pos2.y) then
  33. dir = NORTH
  34. elseif(pos1.y < pos2.y) then
  35. dir = SOUTH
  36. end
  37. end
  38.  
  39. return dir
  40. end
  41.  
  42. function getCreatureLookPosition(cid)
  43. return getPosByDir(getThingPos(cid), getCreatureLookDirection(cid))
  44. end
  45.  
  46. function getPositionByDirection(position, direction, size)
  47. local n = size or 1
  48. if(direction == NORTH) then
  49. position.y = position.y - n
  50. elseif(direction == SOUTH) then
  51. position.y = position.y + n
  52. elseif(direction == WEST) then
  53. position.x = position.x - n
  54. elseif(direction == EAST) then
  55. position.x = position.x + n
  56. elseif(direction == NORTHWEST) then
  57. position.y = position.y - n
  58. position.x = position.x - n
  59. elseif(direction == NORTHEAST) then
  60. position.y = position.y - n
  61. position.x = position.x + n
  62. elseif(direction == SOUTHWEST) then
  63. position.y = position.y + n
  64. position.x = position.x - n
  65. elseif(direction == SOUTHEAST) then
  66. position.y = position.y + n
  67. position.x = position.x + n
  68. end
  69.  
  70. return position
  71. end
  72.  
  73. function doComparePositions(position, positionEx)
  74. return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
  75. end
  76.  
  77. function getArea(position, x, y)
  78. local t = {}
  79. for i = (position.x - x), (position.x + x) do
  80. for j = (position.y - y), (position.y + y) do
  81. table.insert(t, {x = i, y = j, z = position.z})
  82. end
  83. end
  84.  
  85. return t
  86. end
Add Comment
Please, Sign In to add comment