Advertisement
samuelask

kino

Mar 9th, 2025
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.31 KB | None | 0 0
  1. -- Kino Drone Script for OpenComputers (Optimized for Memory)
  2. local component = component
  3. local computer = computer
  4.  
  5. local modem = component.list("modem")()
  6. local drone = component.list("drone")()
  7. local geolyzer = component.list("geolyzer")()
  8. local radar = component.list("radar")()
  9.  
  10. modem = modem and component.proxy(modem)
  11. drone = drone and component.proxy(drone)
  12. geolyzer = geolyzer and component.proxy(geolyzer)
  13. radar = radar and component.proxy(radar)
  14.  
  15. local base_address = "a676e3d0-282e-401b-8848-bd6ee3b3fa98"
  16. local tablet_address = "3998d9fd-c974-4254-8237-bcbb434d7e64"
  17. local scan_mode = "normal"
  18.  
  19. -- Define the scan range (adjust these to match your actual scan parameters)
  20. local scan_x = -2 -- Start X offset relative to Kino
  21. local scan_y = -2-- Start Y offset relative to Kino
  22. local scan_z = -2 -- Start Z offset relative to Kino
  23.  
  24.  
  25. local scan_width = 4-- Width of the scan area
  26. local scan_height = 4-- Height of the scan area
  27. local scan_depth = 4-- Depth of the scan area
  28. local scan_radius = 16 -- ✅ **Total scanning area**
  29. local scan_step = scan_width  -- ✅ **Step size for moving between scans**
  30.  
  31. local fine_motor_control = false
  32.  
  33. local kino_x, kino_y, kino_z = 0, 0, 0
  34.  
  35. local function debug(msg)
  36.     modem.send(base_address, 123, "debug", msg)
  37. end
  38.  
  39. modem.open(123)
  40. drone.setStatusText("Ready")
  41.  
  42. if not modem or not drone then
  43.     debug("Missing modem or drone component!")
  44. end
  45.  
  46. local function sleep(time)
  47.     local start = computer.uptime()
  48.     while computer.uptime() - start < time do
  49.         computer.pullSignal(0)  -- ✅ Allows OpenComputers to process events
  50.     end
  51. end
  52. local function is_air(x, y, z)
  53.     local hardness = geolyzer.analyze(x, y, z) -- Get block hardness
  54.     return hardness == 0  -- Hardness 0 means air
  55. end
  56. -- **Optimized Movement Function with Position Tracking**
  57. local function move(dx, dy, dz)
  58.     drone.move(dx, dy, dz)
  59.     sleep(0.5)  -- ✅ **Wait for movement to complete**
  60.     kino_x = kino_x + dx
  61.     kino_y = kino_y + dy
  62.     kino_z = kino_z + dz
  63.     debug("📍 Normal Move: X=" .. kino_x .. " Y=" .. kino_y .. " Z=" .. kino_z)
  64. end
  65.  
  66. -- **Chunk-Based Scanning with Absolute Position Adjustments**
  67. local function scan_chunk(x_offset, z_offset)
  68.     if not geolyzer then
  69.         debug("No Geolyzer found, skipping scan.")
  70.         return
  71.     end
  72.  
  73.     debug("🔍 Scanning chunk at offset X=" .. x_offset .. " Z=" .. z_offset)
  74.  
  75.     local scan_data = {}
  76.     local success, result = pcall(geolyzer.scan, -2, -2, -2, scan_width, scan_height, scan_depth)
  77.  
  78.     if success and type(result) == "table" then
  79.         for i, density in ipairs(result) do
  80.             local x = ((i - 1) % scan_width) + kino_x + x_offset
  81.             local z = (((i - 1) // scan_width) % scan_depth) + kino_z + z_offset
  82.             local y = (((i - 1) // (scan_width * scan_depth)) % scan_height) + kino_y - 2
  83.  
  84.             if density > 0 then  
  85.                 table.insert(scan_data, x)
  86.                 table.insert(scan_data, y)
  87.                 table.insert(scan_data, z)
  88.                 table.insert(scan_data, density)
  89.             end
  90.         end
  91.         debug("✅ Chunk scan complete at X=" .. kino_x + x_offset .. " Z=" .. kino_z + z_offset)
  92.     else
  93.         debug("❌ Scan failed at X=" .. kino_x + x_offset .. " Z=" .. kino_z + z_offset)
  94.     end
  95.  
  96.     -- **Send scan data immediately**
  97.     for i = 1, #scan_data, 20 do
  98.         modem.send(base_address, 123, "scan_data", table.concat(scan_data, ",", i, math.min(i + 19, #scan_data)))
  99.         sleep(0.1)  -- ✅ **Prevent overloading the network**
  100.     end
  101. end
  102.  
  103. -- **Full Area Scan: Kino Moves & Scans Each Chunk**
  104. local function scan_full_area()
  105.     debug("🔄 Starting full area scan...")
  106.  
  107.     for x_offset = -scan_radius, scan_radius, scan_step do
  108.         for z_offset = -scan_radius, scan_radius, scan_step do
  109.             scan_chunk(x_offset, z_offset)  -- ✅ Scan each chunk
  110.  
  111.             -- ✅ Move to the next scan position
  112.             if z_offset < scan_radius then
  113.                 move(0, 0, scan_step)  -- Move forward in Z direction
  114.             elseif x_offset < scan_radius then
  115.                 move(scan_step, 0, -scan_radius * 2)  -- Move right and reset Z
  116.             end
  117.         end
  118.     end
  119.  
  120.     debug("✅ Full area scan completed.")
  121. end
  122.  
  123. -- Confirm script upload to sender
  124. modem.broadcast(123, "kino_update_success")
  125.  
  126. -- **Main Loop: Handles movement + scan mode**
  127. while true do
  128.     local _, _, sender, _, _, cmd, value = computer.pullSignal(5)
  129.  
  130.     if sender == tablet_address then
  131.         if cmd == "move" then
  132.             if value == "forward" then move(scan_step, 0, 0)
  133.             elseif value == "backward" then move(-scan_step, 0, 0)
  134.             elseif value == "left" then move(0, 0, -scan_step)
  135.             elseif value == "right" then move(0, 0, scan_step)
  136.             elseif value == "up" then move(0, scan_step, 0)
  137.             elseif value == "down" then move(0, -scan_step, 0)
  138.             end
  139.         elseif cmd == "set_scan_mode" then scan_mode = value
  140.         elseif cmd == "scan" then scan_full_area()
  141.         elseif cmd == "fine_control" then
  142.                 if value == "on" then
  143.                     fine_motor_control = true
  144.                     scan_step = 1
  145.                     debug("🔧 Fine Motor Control ENABLED")
  146.                 elseif value == "off" then
  147.                     fine_motor_control = false
  148.                     scan_step = 4
  149.                     debug("🔧 Fine Motor Control DISABLED")
  150.                 end
  151.         end
  152.     end
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement