Advertisement
ddson888

Untitled

Jan 11th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1.  
  2. function onLoad()
  3.  
  4. planetLocations = {}
  5. planetLocations[1] = {}
  6. planetLocations[2] = nil
  7. planetLocations[3] = nil
  8.  
  9. planetRelativeLocations = {}
  10. planetRelativeLocations[1] = {0,1,0}
  11. planetRelativeLocations[2] = {0,0,0}
  12. planetRelativeLocations[3] = {0,0,0}
  13. yOffset = 0
  14. recalibratePlanetLocations()
  15.  
  16.  
  17.  
  18.  
  19.  
  20. button_parameters = {}
  21. button_parameters.position = {0,1,0}
  22. button_parameters.click_function = 'test1'
  23. button_parameters.label = "test1"
  24. button_parameters.function_owner = self
  25. button_parameters.width = 500
  26. button_parameters.height = 500
  27. button_parameters.color = {0,0,0}
  28. button_parameters.font_size= 250
  29. button_parameters.font_color= {1,1,1}
  30.  
  31. self.createButton(button_parameters)
  32. end
  33.  
  34. function test1()
  35. highlightPlanets()
  36. end
  37.  
  38. function highlightPlanets()
  39. for i,j in pairs (planetLocations) do
  40. if planetLocations[i] ~= nil then
  41. highlightAtLocation(j, 3)
  42. end
  43. end
  44. end
  45.  
  46. function highlightAtLocation(coord, r)
  47. recalibratePlanetLocations()
  48. --print("coords: "..coord[1]..", "..coord[2]..", "..coord[3].."; radius: "..r)
  49. local onPlanet = findInSphere(coord, r)
  50. for i, j in pairs (onPlanet) do
  51. if j.hit_object.getName() == "Infantry" then
  52. j.hit_object.highlightOn({0.5,1,0.8})
  53. end
  54. end
  55. end
  56.  
  57. function recalibratePlanetLocations()
  58. for i,v in pairs (planetRelativeLocations) do
  59. if planetLocations[i] ~= nil then
  60. planetLocations[i][1] = planetRelativeLocations[i][1] + self.getPosition()[1]
  61. planetLocations[i][2] = planetRelativeLocations[i][2] + self.getPosition()[2] + yOffset
  62. planetLocations[i][3] = planetRelativeLocations[i][3] + self.getPosition()[3]
  63. end
  64. end
  65. end
  66.  
  67. function findInSphere(x, r)
  68. local CastVectorOrigin =
  69. {
  70. x[1],
  71. x[2],
  72. x[3]
  73. }
  74.  
  75. return Physics.cast({
  76. origin=CastVectorOrigin,
  77. type=2,
  78. size={r,r,r},
  79. max_distance = 4,
  80. direction = {0,1,0},
  81. debug = true
  82. })
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement