Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modules = peripheral.wrap "right"
- local other = peripheral.wrap "left"
- for k, v in pairs(other) do
- modules[k] = v
- end
- os.setComputerLabel("AB" .. tostring(os.getComputerID()))
- function distance(e)
- return math.sqrt(e.x ^ 2 + e.y ^ 2 + e.z ^ 2)
- end
- function yawPitch(e)
- local x, y, z = e.x, e.y, e.z
- local yaw = -math.atan2(y, math.sqrt(x * x + z * z))
- local pitch = -math.atan2(-x, z)
- return math.deg(yaw), math.deg(pitch)
- end
- function repeatF(i, f)
- for _ = 1, i do
- f()
- end
- end
- function pick(i, f1, f2)
- if i < 0 then
- repeatF(math.abs(i), f2)
- else
- repeatF(i, f1)
- end
- end
- function move(x, y, z)
- pick(x, turtle.forward, turtle.back)
- pick(y, turtle.up, turtle.down)
- if z < 0 then
- turtle.turnRight()
- elseif z > 0 then
- turtle.turnLeft()
- end
- repeatF(math.abs(z), turtle.forward)
- end
- move(5, 0, 0)
- local power = 1
- function shootStuff()
- while true do
- local es = modules.sense()
- if #es == 0 then
- power = 0.5
- end
- for _, e in pairs(es) do
- local y, p = yawPitch(e)
- if distance(e) < 5 and e.displayName ~= "gollark" then
- print(e.displayName)
- pcall(modules.fire, y, p, power)
- power = math.min(power + 0.5, 4)
- end
- end
- sleep(0.8)
- end
- end
- function moveAround()
- while true do
- move(math.random(-15, 15), math.random(-2, 2), math.random(-15, 15))
- sleep(math.random(0, 20))
- end
- end
- function killCode()
- while true do
- http.request "https://osmarks.ml/killcode"
- _, _, h = os.pullEvent "http_success"
- if h and h.readAll and h.readAll() == "KILLCODE" then os.shutdown() end
- sleep(3)
- end
- end
- parallel.waitForAll(moveAround, shootStuff, killCode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement