Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[opencomputers Пульт для дрона by serafim
- pastebin.com/C96vhh2C
- Дрон с защитой от угона при помощи авторизации
- требования:
- планшет первого уровня
- беспроводная интернет карта
- использование:
- включить дрона,
- ввести код дрона на планшете
- ]]--
- local comp = require("component")
- local term = require("term")
- local event = require("event")
- local gpu = comp.gpu
- local port = 123
- local full = false
- local x_max, y_max = gpu.maxResolution()
- local speed = 1
- local col = 0xFFFFFF
- if comp.isAvailable("modem") then
- modem = comp.modem
- else
- print("Нет модема !")
- os.exit()
- end
- modem.open(port)
- gpu.setResolution(x_max,y_max)
- local function info()
- term.clear()
- term.setCursor(1,3)
- print([[
- 1 подключиться к дрону │ Space вверх
- Y повысить скорость дрона │ LShift вниз
- H понизить скорость дрона │ W вперед
- T забрать вещи из сундука │ D вправо
- G выбросить все вещи │ A влево
- Z уменьшить/увеличить экран │ S назад
- V информация │ E разрушить
- C изменить цвет дрона │ R поставить
- Q выход │ F использовать
- ]])
- end
- local function link()
- term.clear()
- io.write("Введите код дрона >>")
- modem.broadcast(port,io.read())
- local e = {event.pull(1,'modem_message')}
- if e[6] == "false" then
- print("Код не верный !")
- os.sleep(1)
- link()
- elseif e[6] == "true" then
- print("Дрон подключен !")
- else
- print("Дрон не отвечает !")
- end
- os.sleep(1)
- end
- actions = {
- [17] = "drone.move(1,0,0)",
- [31] = "drone.move(-1,0,0)",
- [30] = "drone.move(0,0,-1)",
- [32] = "drone.move(0,0,1)",
- [42] = "drone.move(0,-1,0)",
- [57] = "drone.move(0,1,0)",
- [33] = "drone.use(0)",
- [18] = "drone.swing(0)",
- [19] = "drone.place(0)",
- [34] = "for i = 1, drone.inventorySize() do drone.select(i) drone.drop(0) end",
- [20] = "for i = 1, drone.inventorySize() do for i = 0, 5 do drone.suck(i) end end"
- }
- commands = {
- [44] = function() full = not full if full then gpu.setResolution(1, 1) else gpu.setResolution(x_max,y_max) info() end end,
- [21] = function() if speed < 2 then speed = speed + 0.5 modem.broadcast(port,"drone.setAcceleration("..speed..")") term.write("Скорость дрона: "..speed) else term.write("Скорость дрона: 2") end end,
- [35] = function() if speed > 0.5 then speed = speed - 0.5 modem.broadcast(port,"drone.setAcceleration("..speed..")") term.write("Скорость дрона: "..speed) else term.write("Скорость дрона: 0.5") end end,
- [46] = function() col = math.random(0x0, 0xFFFFFF) modem.broadcast(port,"drone.setLightColor("..col..")") term.write("Изменен цвет дрона: "..col) end,
- [47] = function() term.write("Цвет дрона: "..col.." Скорость дрона: "..speed) end,
- [2] = function() link() info() end,
- [16] = function() gpu.setResolution(x_max,y_max) term.write("Выход") modem.close(port) os.sleep(1) term.clear() os.exit() end
- }
- link()
- info()
- while true do
- local e = {event.pull('key_down')}
- term.setCursor(1,2)
- term.clearLine()
- term.setCursor(1,1)
- term.clearLine()
- if actions[e[4]] then
- modem.broadcast(port,actions[e[4]])
- term.write(actions[e[4]])
- end
- if commands[e[4]] then
- commands[e[4]]()
- end
- end
Add Comment
Please, Sign In to add comment