StreamerYT

OC : Robot Remote (Computer/Tablet) - remote.lua

Aug 26th, 2020 (edited)
2,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.17 KB | None | 0 0
  1. local component = require("component")
  2. local computer = require("computer")
  3. local gpu = component.gpu
  4. local modem = component.proxy(component.list('modem')())
  5.  
  6. local window = ""
  7. local port = 467
  8.  
  9. function split(z,x);if x==nil then;x="%s";end;local t={};for v in string.gmatch(z,"([^"..x.."]+)") do;table.insert(t,v);end;return t;end;
  10.  
  11. local robot = "local robot=require('robot');"
  12. local drone = "local drone=component.proxy(component.list('drone')());"
  13.  
  14. function eval(d)
  15.     modem.broadcast(port,d)
  16. end
  17.  
  18. function gui()
  19.     gpu.setResolution(80,25)
  20.    
  21.     fill(1,1,80,1,0x000000,0x000000," ") -- panel
  22.    
  23.     fill(1,2,80,25,0x42aaff,0x000000," ") -- app
  24. end
  25.  
  26. function info()
  27.     window = "info"
  28.     gui()
  29.    
  30.     set(66,3,0x42aaff,0xffffff,"UUID: " .. split(modem.address,"-")[1])
  31.    
  32.     set(2,3,0x42aaff,0xffffff,"Закрыть приложение: Ctrl + Alt + C")
  33.     set(2,4,0x42aaff,0xffffff,"Справка: F1 (Вы здесь!)")
  34.     set(2,5,0x42aaff,0xffffff,"Меню: F3")
  35.     set(2,6,0x42aaff,0xffffff,"Минимизировать окно: F4")
  36. end
  37.  
  38. function menu()
  39.     window = "menu"
  40.     gui()
  41. end
  42. function minimize()
  43.     window = "minimize"
  44.     gpu.setResolution(1,1)
  45. end
  46.  
  47. function keytest()
  48.     window = "keytest"
  49.     gpu.setResolution(8,2)
  50. end
  51.  
  52. function fill(x,y,w,h,cb,cf,t) gpu.setBackground(cb);gpu.setForeground(cf);gpu.fill(x,y,w,h,t) end
  53. function set(x,y,cb,cf,t) gpu.setBackground(cb);gpu.setForeground(cf);gpu.set(x,y,t) end
  54.  
  55. info()
  56.  
  57. local bot = {}
  58.  
  59. function bot.forward(); eval(robot.."robot.forward()")      ;end
  60. function bot.back();    eval(robot.."robot.back()")     ;end
  61. function bot.left();    eval(robot.."robot.turnLeft()")     ;end
  62. function bot.right();   eval(robot.."robot.turnRight()")    ;end
  63. function bot.up();  eval(robot.."robot.up()")       ;end
  64. function bot.down();    eval(robot.."robot.down()")     ;end
  65.  
  66.  
  67. while true do
  68.     local event, screen_uuid, ascii, id, username = computer.pullSignal()
  69.     if event == "key_up" then
  70.             if id == 59 then info()
  71.         elseif id == 61 then menu()
  72.         elseif id == 62 then minimize()
  73.         elseif id == 88 then keytest()
  74.         elseif id == 41 then
  75.        
  76.         elseif (window == "menu" or window == "minimize") then
  77.        
  78.        
  79.                 if id == 17 then bot.forward()
  80.             elseif id == 31 then bot.back()
  81.             elseif id == 30 then bot.left()
  82.             elseif id == 32 then bot.right()
  83.             elseif id == 57 then bot.up()
  84.             elseif id == 42 then bot.down()
  85.                
  86.                
  87.             elseif id == 72 then eval(robot.."robot.swingUp()")
  88.             elseif id == 76 then eval(robot.."robot.swing()")
  89.             elseif id == 80 then eval(robot.."robot.swingDown()")
  90.            
  91.  
  92.             elseif id == 13 then eval("movetarget = '"..username.."'")
  93.             elseif id == 12 then eval("movetarget = nil")
  94.            
  95.            
  96.             elseif id == 50 then
  97.                 eval(robot.."for q = 1, 10 do;for w = 1, 10 do;robot.swing();robot.swingUp();robot.swingDown();robot.forward();end;for e = 1, 2 do;robot.turnLeft();robot.swing();robot.swingUp();robot.swingDown();robot.forward();end;for r = 1, 10 do;robot.swing();robot.swingUp();robot.swingDown();robot.forward();end;for t = 1, 2 do;robot.turnRight();robot.swing();robot.swingUp();robot.swingDown();robot.forward();end;end;")
  98.             else
  99.            
  100.             end
  101.         end
  102.        
  103.         if window == "keytest" then
  104.             print("key: " .. id)
  105.         end
  106.     end
  107. end
  108.  
Add Comment
Please, Sign In to add comment