From 3f6068ab48f00b6176b73315ebbe08027dc6f1f2 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 27 Jun 2022 23:54:48 +0100 Subject: hole --- hole.lua | 22 ++++++++++++++++++---- pm.lua | 8 ++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/hole.lua b/hole.lua index 6dbae37..8eb8c68 100644 --- a/hole.lua +++ b/hole.lua @@ -9,14 +9,28 @@ local scanner = assert(peripheral.wrap"right") local laser = assert(peripheral.wrap"left") while true do - local targets = {} local scanned = scanner.scan() - for _,v in ipairs(scanned) do + local targets = {} + for _,s in ipairs(scanned) do + local should_add = true + for i,t in ipairs(targets) do + if t.x == s.x and t.z == s.z then + should_add = false + if s.y > t.y then + targets[i] = s + end + end + end + if should_add then + table.insert(targets,s) + end + end + for _,v in ipairs(targets) do if v.z <= 7 and v.z >= -8 and v.x <= 7 and v.x >= -8 and v.y < 0 then - local yaw,pitch = yaw_pitch(t.x,t.y,t.z) + local yaw,pitch = yaw_pitch(v.x,v.y,v.z) laser.fire(yaw,pitch,4) end end -until #targets == 0 +end diff --git a/pm.lua b/pm.lua index 5fed3d0..d1323b1 100644 --- a/pm.lua +++ b/pm.lua @@ -1,7 +1,11 @@ local function dl(filename) - local file=fs.open("/"..filename..".lua","w") - local res = http.get("https://g.gh0.pw/ccprogs/plain/"..filename..".lua") + local file,err=fs.open("/"..filename..".lua","w") + if err then error("fs.open",err) end + local res,err = http.get("https://g.gh0.pw/ccprogs/plain/"..filename..".lua") + if err then error("http.get",err) end file.write(res.readAll()) + file.flush() + file.close() end dl(arg[1]) -- cgit v1.2.3