Guest User

Untitled

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