Skiret

ping

Nov 29th, 2020
520
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local term = require("term")
  3.  
  4. if not term.isAvailable() then
  5.   computer.beep()
  6.   os.exit()
  7. end
  8.  
  9. function showError(message)
  10.   component.gpu.setBackground(0x000000)
  11.   component.gpu.setForeground(0xFF0000)
  12.   local xt, yt = term.getCursor()
  13.   component.gpu.set(xt, yt, message)
  14.   component.gpu.setBackground(0x000000)
  15.   component.gpu.setForeground(0xFFFFFF)
  16.   print("")
  17. end
  18.  
  19. function showErrorAndExit(message)
  20.   showError(message)
  21.   os.exit()
  22. end
  23.  
  24. if not component.isAvailable("warpdriveRadar") then
  25.   showErrorAndExit("No radar detected")
  26. end
  27.  
  28. local radar = component.warpdriveRadar
  29.  
  30. local argv = { 9999 }
  31. if #argv ~= 1 then
  32.   showErrorAndExit("Usage: ping <scanRadius>")
  33. end
  34.  
  35. local radius = tonumber(argv[1])
  36.  
  37. if radius < 1 or radius > 9999 then
  38.   showErrorAndExit("Radius must be between 1 and 9999")
  39. end
  40.  
  41. local energy, energyMax = radar.energy()
  42. local energyRequired = radar.getEnergyRequired(radius)
  43. local scanDuration = radar.getScanDuration(radius)
  44. if energy < energyRequired then
  45.   showErrorAndExit("Low energy level... (" .. energy .. "/" .. energyRequired .. ")")
  46. end
  47. radar.radius(radius)
  48. radar.start()
  49. os.sleep(0.5)
  50.  
  51. term.clear()
  52. print("Scanning... (" .. scanDuration .. " s)")
  53. os.sleep(scanDuration)
  54.  
  55. local delay = 0
  56. local count
  57. repeat
  58.   count = radar.getResultsCount()
  59.   os.sleep(0.1)
  60.   delay = delay + 1
  61. until (count ~= nil and count ~= -1) or delay > 10
  62.  
  63. if count ~= nil and count > 0 then
  64.   for i=0, count-1 do
  65.     local success, type, name, x, y, z = radar.getResult(i)
  66.     if success then
  67.       print(type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
  68.     else
  69.       showError("Error " .. type)
  70.     end
  71.   end
  72. else
  73.   print("Ничего не было найдено =(")
  74. end
  75.  
  76. --mo_transporter
  77. local keyboard = require("keyboard")
  78. local computer = require("computer")
  79. local MOtrans = component.mo_transporter
  80. local on_exit = 1
  81.  
  82. function menu()
  83. print ("K - Ввод координат / Q - Выход из программы")
  84. end
  85.  
  86. function transkoord(x,y,z)
  87. MOtrans.setX(0,x)--надо указать номер точки и значение координаты, а нумерация начинается с нуля
  88. MOtrans.setY(0,y)
  89. MOtrans.setZ(0,z)
  90. menu()
  91. end
  92.  
  93. function setkoord()
  94. print ("Введите координаты X, Y, Z в столбик через Enter")
  95. local x = io.stdin:read()
  96. local y = io.stdin:read()
  97. local z = io.stdin:read()
  98. local x=tonumber(x)
  99. local y=tonumber(y)%256
  100. local z=tonumber(z)
  101. transkoord(x,y,z)
  102. end
  103.  
  104. menu()
  105. while on_exit == 1 do
  106.   local e = { computer.pullSignal() }
  107.  if e[1] == "key_down" and e[4] == 16  then
  108. on_exit = 0
  109. elseif e[4] == 37 then
  110. setkoord()
  111. end
  112. end
RAW Paste Data