Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local computer = require("computer")
- local gui = require("gui")
- local unicode=require("unicode")
- local gpu = component.gpu
- local event = require('event')
- local chat = component.chat_box
- local redstone = component.redstone
- local level, file, file_text, message_orig
- local array
- local saved = {}
- local rep_players = {}
- --SETTINGS
- local RIGHTS = {["guard"]=99,["light"]=1,["music"]=1,["hello"]=1,["repeat"]=7}
- local NAME = "§6Алекса§7"
- local DISTANCE = 150
- local OUTPUTS = {["guard"]=1,["light"]=2,["music"]=3}
- updateRes(56, 29)
- -- Переменную с окнами должна быть глобальной!!!
- Home = {['windows'] = {
- [1] = {
- ['head'] = {['width'] = "parentX - 4", ['max-width'] = 120, ['height'] = "parentY - 2", ['visible'] = true},
- ['body'] = {
- {['type'] = 'rect', ['style'] = {1, 1, "full", "full", 0x171717, false}},
- {['type'] = 'rect', ['style'] = {"center", "center", "parent", "parent", 0xeeeeee, false}},
- {['type'] = 'text', ['style'] = {"center", 3, 0x000}, ['text'] = '&0Умный дом '},
- {['type'] = 'line', ['style'] = {"center", 4, "parent", 0x000}},
- {['type'] = 'text', ['style'] = {4, 3, 0x000}, ['text'] = '&0© &9RenKylo'},
- }
- },
- }
- }
- local elem_count = #Home['windows'][1]['body']
- local function touch(_, _, x, y)
- for i = 1, #buttons do
- if x >= buttons[i]['x'] and x <= buttons[i]['x'] + buttons[i]['width'] and y >= buttons[i]['y'] and y <= buttons[i]['y'] + buttons[i]['height'] then
- -- Анимация кнопки при клике
- click(buttons[i])
- -- Выполнение функции кнопки
- buttons[i]['action'](player)
- break
- end
- end
- end
- local e = {event.listen('touch', touch)} -- Ждём клика на экран
- --Получение списка Мемберов
- local MEMBERS = {}
- local file = io.open("users", "r")
- file_text = file:read("*a")
- file:close()
- for i in string.gmatch(file_text, "[^,]+") do --Делим текст
- array = {}
- for a in string.gmatch(i, "[^ ]+") do
- array[#array+1] = a
- end
- MEMBERS[array[1]] = array[2]
- end
- --Загрузка сохранений дома
- file = io.open("config", "r")
- file_text = file:read("*a")
- file:close()
- for i in string.gmatch(file_text, "[^,]+") do --Делим текст
- saved[#saved+1] = tonumber(i)
- end
- local LIGHT = saved[1]
- local MUSIC = saved[2]
- local GUARD = saved[3]
- --SWITCH VARIABLES
- --Pre Actions
- os.execute("clear")
- chat.setName(NAME)
- chat.setDistance(DISTANCE)
- if LIGHT == 1 then redstone.setOutput(OUTPUTS["light"], 16) else redstone.setOutput(OUTPUTS["light"], 0) end --Свет
- if GUARD == 1 then redstone.setOutput(OUTPUTS["guard"], 16) else redstone.setOutput(OUTPUTS["guard"], 0) end --Защита
- if MUSIC == 1 then redstone.setOutput(OUTPUTS["music"], 16) else redstone.setOutput(OUTPUTS["music"], 0) end --Музыка
- --Actions
- function save()
- file = io.open("config", "w")
- file:write(LIGHT..","..MUSIC..","..GUARD)
- file:close()
- end
- function updateData()
- local g, m, l, r = "&cВыключено", "&cВыключено", "&cВыключено"
- if LIGHT == 1 then l = "&2Включено" end
- if MUSIC == 1 then m = "&2Включено" end
- if GUARD == 1 then g = "&2Включено" end
- Home['windows'][1]['body'][elem_count + 1] = {
- ['type'] = 'text', ['style'] = {4, 6, 0x000}, ['text'] = "&8Защита: "..g
- }
- Home['windows'][1]['body'][elem_count + 2] = {
- ['type'] = 'text', ['style'] = {4, 8, 0x000}, ['text'] = "&8Освещение: "..l
- }
- Home['windows'][1]['body'][elem_count + 3] = {
- ['type'] = 'text', ['style'] = {4, 10, 0x000}, ['text'] = "&8Музыка: "..m
- }
- local players = ""
- for i = 1, #rep_players do
- if i ~= 1 then
- players = players..", "
- end
- players = players..rep_players[i]
- i = i + 1
- end
- if players == "" then
- players = "&0Нет игроков для повтора"
- end
- Home['windows'][1]['body'][elem_count + 4] = {
- ['type'] = 'text', ['style'] = {4, 12, 0x000}, ['text'] = "&8Повторение: &9"..players
- }
- draw(Home) -- Обновляем интерфейс
- end
- function findRepPlayer(player)
- local index = 0
- for i = 1, #rep_players do
- if player == rep_players[i] then
- index = i
- end
- i = i + 1
- end
- return index
- end
- updateData()
- while true do
- local _,_,player,msg = event.pull("chat_message")
- message_orig = msg
- msg = unicode.lower(msg)
- if MEMBERS[string.lower(player)] then
- level = tonumber(MEMBERS[string.lower(player)])
- if msg == "-защита" and level >= RIGHTS["guard"] then
- chat.say("§eЗащита §a§lактивирована")
- redstone.setOutput(OUTPUTS["guard"], 16)
- GUARD = 1
- elseif msg == "-стоп" and level >= RIGHTS["guard"] then
- chat.say("§eЗащита §c§lдеактивирована")
- redstone.setOutput(OUTPUTS["guard"], 0)
- GUARD = 0
- elseif msg == "-свет" and level >= RIGHTS["light"] then
- if LIGHT == 0 then
- chat.say("§eСвет §a§lOn")
- redstone.setOutput(OUTPUTS["light"], 16)
- LIGHT = 1
- else
- chat.say("§eСвет §c§lOff")
- redstone.setOutput(OUTPUTS["light"], 0)
- LIGHT = 0
- end
- elseif msg == "-музыка" and level >= RIGHTS["music"] then
- if MUSIC == 0 then
- chat.say("§eМузыка §a§lOn")
- MUSIC = 1
- else
- chat.say("§eМузыка §c§lOff")
- MUSIC = 0
- end
- redstone.setOutput(OUTPUTS["music"], 16)
- redstone.setOutput(OUTPUTS["music"], 0)
- elseif msg == "-привет" and level >= RIGHTS["hello"] then
- chat.say("§fПриветствую, §c"..player)
- elseif msg == "-повтор" and level >= RIGHTS["repeat"] then
- local index = findRepPlayer(player)
- if index ~= 0 then
- rep_players[index] = nil
- chat.say("§eПовтор чата для §9"..player.." §c§lOff")
- else
- rep_players[#rep_players+1] = player
- chat.say("§eПовтор чата для §9"..player.." §a§lOn")
- end
- elseif msg == "-взорви всё нахуй" and level >= RIGHTS["guard"] then
- chat.say("§c"..player.." §fзапустил отсчёт")
- for i = 5, 1, -1 do
- chat.say("§fДо взрыва §c"..i)
- os.sleep(1)
- end
- redstone.setOutput(OUTPUTS["light"], 0)
- LIGHT = 0
- chat.say("§fЯ...§fв-выключаюсь...§f. §fПрощайте, §c"..player)
- os.execute("clear")
- os.sleep(10)
- else
- if findRepPlayer(player) ~= 0 then
- chat.setName("§aАнтиМут§7] [§6"..level.."§7")
- chat.say("§c"..player.."§f: "..message_orig)
- chat.setName(NAME)
- end
- end
- updateData()
- save() --Сохраняем все
- end
- end
Add Comment
Please, Sign In to add comment