Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Kino Drone Script for OpenComputers (Drone-Compatible)
- local component = component or {} -- Fallback for EEPROM environment
- local computer = computer or {}
- -- Find Components (Manually, since require() doesn't work)
- local modemAddress = component.list and component.list("modem")()
- local droneAddress = component.list and component.list("drone")()
- local geolyzerAddress = component.list and component.list("geolyzer")()
- local radarAddress = component.list and component.list("radar")()
- -- Check if the required components exist before using them
- local modem = modemAddress and component.proxy(modemAddress) or nil
- local drone = droneAddress and component.proxy(droneAddress) or nil
- local geolyzer = geolyzerAddress and component.proxy(geolyzerAddress) or nil
- local radar = radarAddress and component.proxy(radarAddress) or nil
- -- Ensure we have a modem and drone; otherwise, exit
- if not modem then
- error("No modem found! The Kino drone requires a wireless modem to function.")
- end
- if not drone then
- error("No drone component found! This script must run on an OpenComputers drone.")
- end
- -- Configuration
- local scan_interval = 5 -- Seconds between scans
- local scan_range = 8 -- Radius for scanning (must be <= 8)
- local base_address = "a676e3d0-282e-401b-8848-bd6ee3b3fa98" -- Address of the base station
- local tablet_address = "3998d9fd-c974-4254-8237-bcbb434d7e64" -- Address of the tablet
- local detected_players = {}
- local scan_mode = "normal" -- Default scan mode
- -- Function to send debug messages to base station
- local function debug(message)
- modem.send(base_address, 123, "debug", message)
- end
- -- Function to move the Kino
- drone.setStatusText("Ready")
- modem.open(123) -- Open communication port
- local function move(direction)
- local moveAmount = 0.5 -- Drones move in small increments
- if direction == "forward" then drone.move(moveAmount, 0, 0)
- elseif direction == "backward" then drone.move(-moveAmount, 0, 0)
- elseif direction == "left" then drone.move(0, 0, -moveAmount)
- elseif direction == "right" then drone.move(0, 0, moveAmount)
- elseif direction == "up" then drone.move(0, moveAmount, 0)
- elseif direction == "down" then drone.move(0, -moveAmount, 0)
- else debug("Invalid move command: " .. tostring(direction))
- end
- end
- -- Function to serialize a table manually (since drones can't use require)
- local function serialize_table(tbl)
- local str = "{"
- for k, v in pairs(tbl) do
- if type(v) == "table" then
- str = str .. k .. "=" .. serialize_table(v) .. ", "
- elseif type(v) == "string" then
- str = str .. k .. "='" .. v .. "', "
- else
- str = str .. k .. "=" .. tostring(v) .. ", "
- end
- end
- return str .. "}"
- debug("Serialized data...")
- end
- -- Function to scan environment
- local function scan_environment()
- local scan_data = {mode = scan_mode, blocks = {}, entities = {}}
- -- Scan nearby blocks (if geolyzer is available)
- if geolyzer then
- debug("Scanning terrain...")
- -- Corrected geolyzer scan usage (added `{}` as the fifth argument)
- local success, result = pcall(function() return geolyzer.scan(-4, -4, 0, 4, 4, 4) -- Corrected Y offset
- end)
- if success and type(result) == "table" then
- for i, density in ipairs(result) do
- -- Convert 1D table index to 3D coordinates
- local x = (i - 1) % 4 - 4
- local z = ((i - 1) // 4) % 4 - 4
- local y = ((i - 1) // 16) % 4 -- Height coordinate
- table.insert(scan_data.blocks, {x = x, y = y, z = z, value = density})
- end
- debug("Geolyzer scan successful!")
- else
- debug("Geolyzer scan failed! Error: " .. tostring(result))
- end
- else
- debug("Warning: No Geolyzer found, skipping block scanning.")
- end
- -- Scan for entities (players) (if radar is available)
- if radar then
- debug("Scanning for entities...")
- local entities = radar.getEntities(scan_range)
- for _, entity in ipairs(entities) do
- if entity.type == "player" and not detected_players[entity.name] then
- detected_players[entity.name] = true
- modem.send(tablet_address, 123, "player_detected", entity.name)
- end
- table.insert(scan_data.entities, {name=entity.name, type=entity.type, x=entity.x, y=entity.y, z=entity.z})
- end
- else
- debug("Warning: No Radar found, skipping entity scanning.")
- end
- -- Convert `scan_data` into a string manually (since require("serialization") doesn't work)
- local scan_data_str = serialize_table(scan_data)
- -- Send scan data to base station
- modem.send(base_address, 123, "scan_data", scan_data_str)
- end
- -- Confirm script upload to sender
- modem.broadcast(123, "kino_update_success")
- -- Main Loop: Handles both movement commands and scanning
- while true do
- -- Scan environment at intervals
- local scan_timer = computer.uptime() + scan_interval
- while computer.uptime() < scan_timer do
- -- Listen for modem messages (since drones can't use event.listen)
- local event, _, sender, _, _, command, value = computer.pullSignal(scan_interval)
- if event == "modem_message" and sender == tablet_address then
- if command == "move" then
- move(value)
- elseif command == "set_scan_mode" then
- scan_mode = value
- end
- end
- end
- scan_environment()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement