Advertisement
Guest User

americanbot

a guest
Mar 28th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 KB | None | 0 0
  1. local modules = peripheral.wrap "right"
  2. local other = peripheral.wrap "left"
  3.  
  4. for k, v in pairs(other) do
  5.     modules[k] = v
  6. end
  7.  
  8. os.setComputerLabel("AB" .. tostring(os.getComputerID()))
  9.  
  10. function distance(e)
  11.     return math.sqrt(e.x ^ 2 + e.y ^ 2 + e.z ^ 2)
  12. end
  13.  
  14. function yawPitch(e)
  15.     local x, y, z = e.x, e.y, e.z
  16.     local yaw = -math.atan2(y, math.sqrt(x * x + z * z))
  17.     local pitch = -math.atan2(-x, z)
  18.    
  19.     return math.deg(yaw), math.deg(pitch)
  20. end
  21.  
  22. function repeatF(i, f)
  23.     for _ = 1, i do
  24.         f()
  25.     end
  26. end
  27.  
  28. function pick(i, f1, f2)
  29.     if i < 0 then
  30.         repeatF(math.abs(i), f2)
  31.     else
  32.         repeatF(i, f1)
  33.     end
  34. end
  35.  
  36. function move(x, y, z)
  37.     pick(x, turtle.forward, turtle.back)
  38.     pick(y, turtle.up, turtle.down)
  39.    
  40.     if z < 0 then
  41.         turtle.turnRight()
  42.     elseif z > 0 then
  43.         turtle.turnLeft()
  44.     end
  45.    
  46.     repeatF(math.abs(z), turtle.forward)
  47. end
  48.  
  49. move(5, 0, 0)
  50.  
  51. local power = 1
  52.  
  53. function shootStuff()
  54.     while true do
  55.         local es = modules.sense()
  56.  
  57.         if #es == 0 then
  58.             power = 0.5
  59.         end
  60.            
  61.         for _, e in pairs(es) do
  62.             local y, p = yawPitch(e)
  63.             if distance(e) < 5 and e.displayName ~= "gollark" then
  64.                 print(e.displayName)
  65.                 pcall(modules.fire, y, p, power)
  66.                 power = math.min(power + 0.5, 4)
  67.             end
  68.         end  
  69.    
  70.         sleep(0.8)  
  71.     end
  72. end
  73.  
  74. function moveAround()
  75.     while true do
  76.         move(math.random(-15, 15), math.random(-2, 2), math.random(-15, 15))
  77.         sleep(math.random(0, 20))
  78.     end
  79. end
  80.  
  81. function killCode()
  82.     while true do
  83.         http.request "https://osmarks.ml/killcode"
  84.         _, _, h = os.pullEvent "http_success"
  85.         if h and h.readAll and h.readAll() == "KILLCODE" then os.shutdown() end
  86.         sleep(3)
  87.     end
  88. end
  89.  
  90. parallel.waitForAll(moveAround, shootStuff, killCode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement