Advertisement
samuelask

Hologram New

Mar 9th, 2025 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. -- Base Station Script for Kino Drone (Holographic Rendering)
  2. local component = require("component")
  3. local event = require("event")
  4. local term = require("term")
  5. local modem = component.modem
  6. local hologram = component.hologram
  7. hologram.clear()
  8. local scan_data = {} -- Holds x, y, z, density values
  9. local lastUpdateTime = os.time()  -- Tracks when the last scan data arrived
  10. local scanTimeout = 3  -- ✅ Timeout in seconds before clearing hologram for a new scan
  11. local count = 0  -- ✅ Count stored blocks
  12. -- Configuration
  13. local kino_address = "a1a5a0ee-4ccf-45e7-961b-96ce5afc068c" -- Address of the Kino drone
  14. modem.open(123) -- Open communication port
  15. local placed_count = 0  -- ✅ Count blocks placed
  16. local function debug(msg)
  17.     print("[DEBUG] " .. msg)
  18. end
  19.  
  20. -- ✅ Increase hologram scale (Fixes tiny display issue)
  21. hologram.setScale(3)
  22.  
  23. -- Main loop
  24. print("Base Station active. Waiting for Kino data...")
  25. while true do  
  26.     local _, _, sender, _, _, command, data = event.pull(1, "modem_message")  -- ✅ 1-second timeout
  27.  
  28.     if command == "debug" then
  29.         print("[Kino] " .. data)
  30.     elseif command == "scan_data" then
  31.         lastUpdateTime = os.time()  -- ✅ Reset timeout when receiving new data
  32.         -- ✅ Convert received string back into a table
  33.         for x, y, z, d in string.gmatch(data, "([^,]+),([^,]+),([^,]+),([^,]+)") do
  34.             local tx = tonumber(x) + 16
  35.             local ty = tonumber(y) + 12
  36.             local tz = tonumber(z) + 16
  37.             local density = tonumber(d)
  38.  
  39.             if density and density > 0 then
  40.                 -- ✅ Store data for future use
  41.                 local key = string.format("%d,%d,%d", tx, ty, tz)
  42.                 scan_data[key] = {tx, ty, tz, density}
  43.                
  44.                 hologram.set(tx, ty, tz, 1)
  45.                 debug("✅ Placed block at: HX=" .. tx .. " HY=" .. ty .. " HZ=" .. tz)
  46.             else
  47.                 debug("⚠️ Invalid data format: " .. x .. "," .. y .. "," .. z .. "," .. d)
  48.             end
  49.         end
  50.     elseif os.time() - lastUpdateTime > scanTimeout and #scan_data > 0 then
  51.         -- ✅ If no new scan data is received within timeout, update the hologram
  52.         debug("⌛ No new data received for " .. scanTimeout .. " seconds. Updating hologram.")
  53.    
  54.         -- ✅ Render all blocks
  55.         for _, block in ipairs(scan_data) do
  56.             local hx, hy, hz = block[1], block[2], block[3]
  57.  
  58.             if hy >= 0 and hy <= 32 then
  59.             --  hologram.set(hx, hy, hz, 1)
  60.                 debug("✅ Placed block at: HX=" .. hx .. " HY=" .. hy .. " HZ=" .. hz)
  61.                 placed_count = placed_count + 1
  62.             else
  63.                 debug("❌ Block out of range: HX=" .. hx .. " HY=" .. hy .. " HZ=" .. hz)
  64.             end
  65.         end
  66.  
  67.         debug("🎉 Hologram updated!")
  68.         lastUpdateTime = os.time()  -- ✅ Reset timer     
  69.         debug("🎉 Hologram updated! Total blocks placed: " .. tostring(placed_count))
  70.     end
  71. end
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement