Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ opencomputers nano на русском
- Программа для включения эффектов нанитов.
- требования: планшет или компьютер с wi-fi картой
- примечание: могут одновременно активны только 2 эффекта
- 4 назначить вход
- номер входа 1-18
- состояние вкл(1) выкл(2)
- ]]--
- local event = require("event")
- local component = require("component")
- local term = require("term")
- local lastResponse = ""
- local modem = component.modem
- modem.open(1)
- modem.broadcast(1, "nanomachines", "setResponsePort", 1)
- local function printResponse()
- local w, h = component.gpu.getResolution()
- component.gpu.fill(1, h, w, h, " ")
- component.gpu.set(1, h, lastResponse)
- end
- local function handleModemMessage(_, _, _, _, _, header, command, ...)
- if header ~= "nanomachines" then return end
- lastResponse = "последний ответ: " .. command
- for _, v in ipairs({...}) do
- lastResponse = lastResponse .. ", " .. tostring(v)
- end
- printResponse()
- end
- event.listen("modem_message", handleModemMessage)
- local function send(command, ...)
- component.modem.broadcast(1, "nanomachines", command, ...)
- end
- local function readNumber(name, validator)
- local index
- while not index do
- io.write(name..": ")
- index = tonumber(io.read())
- if not index or validator and not validator(index) then
- index = nil
- io.write("такого входа не существует\n")
- end
- end
- return index
- end
- local running = true
- local commands = {
- { "питание нанитов",
- function()
- send("getPowerState")
- end
- },
- { "активные эфекты",
- function()
- send("getActiveEffects")
- end
- },
- { "состояние входа",
- function()
- local index = readNumber("номер входа")
- send("getInput", index)
- end
- },
- { "установить состояние входа",
- function()
- local index = readNumber("номер входа")
- io.write("1. влючить \n")
- io.write("2. выключить\n")
- local value = readNumber("состояние", function(x) return x == 1 or x == 2 end)
- send("setInput", index, value == 1)
- end
- },
- { "количество входов",
- function()
- send("getTotalInputCount")
- end
- },
- { "количество безопасных входов",
- function()
- send("getSafeActiveInputs")
- end
- },
- { "сколько всего активных входов",
- function()
- send("getMaxActiveInputs")
- end
- },
- { "зодоровье игрока",
- function()
- send("getHealth")
- end
- },
- { "голод игрока",
- function()
- send("getHunger")
- end
- },
- { "возраст игрока",
- function()
- send("getAge")
- end
- },
- { "имя игрока",
- function()
- send("getName")
- end
- },
- { "опыт игрока",
- function()
- send("getExperience")
- end
- },
- { "выход",
- function()
- running = false
- end
- }
- }
- function main()
- while running do
- term.clear()
- for i = 1, #commands do
- local command = commands[i]
- io.write(i," ",command[1],"\n")
- end
- printResponse()
- local command = readNumber("введите команду", function(x) return x > 0 and x <= #commands end)
- commands[command][2]()
- end
- end
- local result, reason = pcall(main)
- if not result then
- io.stderr:write(reason, "\n")
- end
- event.ignore("modem_message", handleModemMessage)
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement