Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Kino Drone Script for OpenComputers (Optimized for Memory)
- local component = component
- local computer = computer
- local modem = component.list("modem")()
- local drone = component.list("drone")()
- local geolyzer = component.list("geolyzer")()
- local radar = component.list("radar")()
- modem = modem and component.proxy(modem)
- drone = drone and component.proxy(drone)
- geolyzer = geolyzer and component.proxy(geolyzer)
- radar = radar and component.proxy(radar)
- local base_address = "a676e3d0-282e-401b-8848-bd6ee3b3fa98"
- local tablet_address = "3998d9fd-c974-4254-8237-bcbb434d7e64"
- local scan_mode = "normal"
- -- Define the scan range (adjust these to match your actual scan parameters)
- local scan_x = -2 -- Start X offset relative to Kino
- local scan_y = -2-- Start Y offset relative to Kino
- local scan_z = -2 -- Start Z offset relative to Kino
- local scan_width = 4-- Width of the scan area
- local scan_height = 4-- Height of the scan area
- local scan_depth = 4-- Depth of the scan area
- local scan_radius = 16 -- ✅ **Total scanning area**
- local scan_step = scan_width -- ✅ **Step size for moving between scans**
- local fine_motor_control = false
- local kino_x, kino_y, kino_z = 0, 0, 0
- local function debug(msg)
- modem.send(base_address, 123, "debug", msg)
- end
- modem.open(123)
- drone.setStatusText("Ready")
- if not modem or not drone then
- debug("Missing modem or drone component!")
- end
- local function sleep(time)
- local start = computer.uptime()
- while computer.uptime() - start < time do
- computer.pullSignal(0) -- ✅ Allows OpenComputers to process events
- end
- end
- local function is_air(x, y, z)
- local hardness = geolyzer.analyze(x, y, z) -- Get block hardness
- return hardness == 0 -- Hardness 0 means air
- end
- -- **Optimized Movement Function with Position Tracking**
- local function move(dx, dy, dz)
- drone.move(dx, dy, dz)
- sleep(0.5) -- ✅ **Wait for movement to complete**
- kino_x = kino_x + dx
- kino_y = kino_y + dy
- kino_z = kino_z + dz
- debug("📍 Normal Move: X=" .. kino_x .. " Y=" .. kino_y .. " Z=" .. kino_z)
- end
- -- **Chunk-Based Scanning with Absolute Position Adjustments**
- local function scan_chunk(x_offset, z_offset)
- if not geolyzer then
- debug("No Geolyzer found, skipping scan.")
- return
- end
- debug("🔍 Scanning chunk at offset X=" .. x_offset .. " Z=" .. z_offset)
- local scan_data = {}
- local success, result = pcall(geolyzer.scan, -2, -2, -2, scan_width, scan_height, scan_depth)
- if success and type(result) == "table" then
- for i, density in ipairs(result) do
- local x = ((i - 1) % scan_width) + kino_x + x_offset
- local z = (((i - 1) // scan_width) % scan_depth) + kino_z + z_offset
- local y = (((i - 1) // (scan_width * scan_depth)) % scan_height) + kino_y - 2
- if density > 0 then
- table.insert(scan_data, x)
- table.insert(scan_data, y)
- table.insert(scan_data, z)
- table.insert(scan_data, density)
- end
- end
- debug("✅ Chunk scan complete at X=" .. kino_x + x_offset .. " Z=" .. kino_z + z_offset)
- else
- debug("❌ Scan failed at X=" .. kino_x + x_offset .. " Z=" .. kino_z + z_offset)
- end
- -- **Send scan data immediately**
- for i = 1, #scan_data, 20 do
- modem.send(base_address, 123, "scan_data", table.concat(scan_data, ",", i, math.min(i + 19, #scan_data)))
- sleep(0.1) -- ✅ **Prevent overloading the network**
- end
- end
- -- **Full Area Scan: Kino Moves & Scans Each Chunk**
- local function scan_full_area()
- debug("🔄 Starting full area scan...")
- for x_offset = -scan_radius, scan_radius, scan_step do
- for z_offset = -scan_radius, scan_radius, scan_step do
- scan_chunk(x_offset, z_offset) -- ✅ Scan each chunk
- -- ✅ Move to the next scan position
- if z_offset < scan_radius then
- move(0, 0, scan_step) -- Move forward in Z direction
- elseif x_offset < scan_radius then
- move(scan_step, 0, -scan_radius * 2) -- Move right and reset Z
- end
- end
- end
- debug("✅ Full area scan completed.")
- end
- -- Confirm script upload to sender
- modem.broadcast(123, "kino_update_success")
- -- **Main Loop: Handles movement + scan mode**
- while true do
- local _, _, sender, _, _, cmd, value = computer.pullSignal(5)
- if sender == tablet_address then
- if cmd == "move" then
- if value == "forward" then move(scan_step, 0, 0)
- elseif value == "backward" then move(-scan_step, 0, 0)
- elseif value == "left" then move(0, 0, -scan_step)
- elseif value == "right" then move(0, 0, scan_step)
- elseif value == "up" then move(0, scan_step, 0)
- elseif value == "down" then move(0, -scan_step, 0)
- end
- elseif cmd == "set_scan_mode" then scan_mode = value
- elseif cmd == "scan" then scan_full_area()
- elseif cmd == "fine_control" then
- if value == "on" then
- fine_motor_control = true
- scan_step = 1
- debug("🔧 Fine Motor Control ENABLED")
- elseif value == "off" then
- fine_motor_control = false
- scan_step = 4
- debug("🔧 Fine Motor Control DISABLED")
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement