View difference between Paste ID: S3SgLfLx and r6ta6c3G
SHOW: | | - or go back to the newest paste.
1-
--Created By RenKylo
1+
2
local computer = require("computer")
3-
local event = require("event")
3+
local gui = require("gui")
4-
local unicode = require("unicode")
4+
local unicode=require("unicode")
5
local gpu = component.gpu
6
local event = require('event')
7
local chat = component.chat_box
8
local redstone = component.redstone
9
10
local level, file, file_text, message_orig
11
local array
12
local saved = {}
13
local rep_players = {}
14
15
--SETTINGS
16
local RIGHTS = {["guard"]=99,["light"]=1,["music"]=1,["hello"]=1,["repeat"]=7}
17-
	array = {}
17+
local NAME = "§6Алекса§7"
18-
	for a in string.gmatch(i, "[^ ]+") do
18+
19-
		array[#array+1] = a
19+
20-
	end
20+
local OUTPUTS = {["guard"]=1,["light"]=2,["music"]=3}
21-
	MEMBERS[array[1]] = array[2]
21+
22
updateRes(56, 29)
23
24
-- Переменную с окнами должна быть глобальной!!!
25
Home = {['windows'] = {
26
                  [1] = {
27
                    ['head'] = {['width'] = "parentX - 4", ['max-width'] = 120, ['height'] = "parentY - 2", ['visible'] = true},
28-
	saved[#saved+1] = tonumber(i)
28+
                    ['body'] = {
29
                      {['type'] = 'rect', ['style'] = {1, 1, "full", "full", 0x171717, false}},
30
                      {['type'] = 'rect', ['style'] = {"center", "center", "parent", "parent", 0xeeeeee, false}},
31
                      {['type'] = 'text', ['style'] = {"center", 3, 0x000}, ['text'] = '&0Умный дом '},
32
                      {['type'] = 'line', ['style'] = {"center", 4, "parent", 0x000}},
33
                      {['type'] = 'text', ['style'] = {4, 3, 0x000}, ['text'] = '&0© &9RenKylo'},
34-
local RIGHTS = {["guard"]=7,["light"]=1,["music"]=1,["hello"]=1}
34+
                    }
35-
local NAME = "§9§lSmartHome§7"
35+
                  },
36
                }
37
              }
38
39
local elem_count = #Home['windows'][1]['body']
40
41
local function touch(_, _, x, y)
42-
if LIGHT == 1 then redstone.setOutput(0, 16) else redstone.setOutput(0, 0) end --Свет
42+
  for i = 1, #buttons do
43-
if GUARD == 1 then redstone.setOutput(1, 16) else redstone.setOutput(1, 0) end --Защита
43+
    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
44-
if MUSIC == 1 then redstone.setOutput(2, 16) else redstone.setOutput(2, 0) end --Музыка
44+
      -- Анимация кнопки при клике
45-
gpu.setForeground(0xFFFF55)
45+
      click(buttons[i])
46-
io.write("Умный дом ")
46+
      -- Выполнение функции кнопки
47-
gpu.setForeground(0x55FF55)
47+
      buttons[i]['action'](player)
48-
io.write("Активирован")
48+
      break
49-
print("")
49+
    end
50-
print("Функции:")
50+
  end
51
end
52
53-
	file = io.open("config", "w")
53+
local e = {event.listen('touch', touch)} -- Ждём клика на экран
54-
	file:write(LIGHT..","..MUSIC..","..GUARD)
54+
55-
	file:close()
55+
56
local MEMBERS = {}
57
local file = io.open("users", "r")
58
file_text = file:read("*a")
59-
	message_orig = msg
59+
60-
	msg = unicode.lower(msg)
60+
61
    array = {}
62-
		level = tonumber(MEMBERS[string.lower(player)])
62+
    for a in string.gmatch(i, "[^ ]+") do
63-
        if msg == "защита" and level >= RIGHTS["guard"] then
63+
        array[#array+1] = a
64
    end
65-
            redstone.setOutput(1, 16)
65+
    MEMBERS[array[1]] = array[2]
66-
			GUARD = 1
66+
67-
        elseif msg == "стоп" and level >= RIGHTS["guard"] then
67+
68
file = io.open("config", "r")
69-
            redstone.setOutput(1, 0)
69+
70-
			GUARD = 0
70+
71-
        elseif msg == "свет" and level >= RIGHTS["light"] then
71+
72-
        	if LIGHT == 0 then
72+
    saved[#saved+1] = tonumber(i)
73-
            	chat.say("§eСвет §a§lOn")
73+
74-
                redstone.setOutput(0, 16)
74+
75
local MUSIC = saved[2]
76
local GUARD = saved[3]
77-
            	chat.say("§eСвет §c§lOff")
77+
78-
                redstone.setOutput(0, 0)
78+
79
os.execute("clear")
80
chat.setName(NAME)
81-
		elseif msg == "музыка" and level >= RIGHTS["music"] then
81+
82-
        	if MUSIC == 0 then
82+
if LIGHT == 1 then redstone.setOutput(OUTPUTS["light"], 16) else redstone.setOutput(OUTPUTS["light"], 0) end --Свет
83-
            	chat.say("§eМузыка §a§lOn")
83+
if GUARD == 1 then redstone.setOutput(OUTPUTS["guard"], 16) else redstone.setOutput(OUTPUTS["guard"], 0) end --Защита
84
if MUSIC == 1 then redstone.setOutput(OUTPUTS["music"], 16) else redstone.setOutput(OUTPUTS["music"], 0) end --Музыка
85
--Actions
86-
            	chat.say("§eМузыка §c§lOff")
86+
87
    file = io.open("config", "w")
88-
			end
88+
    file:write(LIGHT..","..MUSIC..","..GUARD)
89-
            redstone.setOutput(3, 16)
89+
    file:close()
90-
			redstone.setOutput(3, 0)
90+
91-
		elseif msg == "привет" and level >= RIGHTS["hello"] then
91+
92-
			chat.say("§fПриветствую, §c"..player)
92+
function updateData()
93-
		elseif msg == "взорви всё нахуй" and level >= RIGHTS["guard"] then
93+
  local g, m, l, r = "&cВыключено", "&cВыключено", "&cВыключено"
94-
			chat.say("§c"..player.." §fзапустил отсчёт")
94+
  if LIGHT == 1 then l = "&2Включено" end
95-
			for i = 5, 1, -1 do
95+
  if MUSIC == 1 then m = "&2Включено" end
96-
				chat.say("§fДо взрыва §c"..i)
96+
  if GUARD == 1 then g = "&2Включено" end
97-
				os.sleep(1)
97+
  Home['windows'][1]['body'][elem_count + 1] = {
98-
			end
98+
    ['type'] = 'text', ['style'] = {4, 6, 0x000}, ['text'] = "&8Защита: "..g
99-
            redstone.setOutput(0, 0)
99+
  }
100
  Home['windows'][1]['body'][elem_count + 2] = {
101-
			chat.say("§fЯ...§fв-выключаюсь...§f. §fПрощайте, §cRenKylo")
101+
    ['type'] = 'text', ['style'] = {4, 8, 0x000}, ['text'] = "&8Освещение: "..l
102-
			os.execute("clear")
102+
  }
103-
			gpu.setForeground(0xFF0000)
103+
  Home['windows'][1]['body'][elem_count + 3] = {
104-
			print("Ошибка...")
104+
    ['type'] = 'text', ['style'] = {4, 10, 0x000}, ['text'] = "&8Музыка: "..m
105-
			os.sleep(10)
105+
  }
106-
		end
106+
  local players = ""
107-
		gpu.setForeground(0xFFFF55)
107+
  for i = 1, #rep_players do
108-
		io.write(player..": ")
108+
    if i ~= 1 then
109-
		gpu.setForeground(0x55FF55)
109+
      players =  players..", "
110-
		io.write(message_orig)
110+
    end
111-
		print("")
111+
    players =  players..rep_players[i]
112-
		save() --Сохраняем все
112+
    i = i + 1
113-
	end
113+
  end
114
  if players == "" then
115
    players = "&0Нет игроков для повтора"
116
  end
117
  Home['windows'][1]['body'][elem_count + 4] = {
118
    ['type'] = 'text', ['style'] = {4, 12, 0x000}, ['text'] = "&8Повторение: &9"..players
119
  }
120
  draw(Home) -- Обновляем интерфейс
121
end
122
123
function findRepPlayer(player)
124
  local index = 0
125
  for i = 1, #rep_players do
126
    if player == rep_players[i] then
127
      index = i
128
    end
129
    i = i + 1
130
  end
131
  return index
132
end
133
updateData()
134
while true do
135
    local _,_,player,msg = event.pull("chat_message")
136
    message_orig = msg
137
    msg = unicode.lower(msg)
138
    if MEMBERS[string.lower(player)] then
139
        level = tonumber(MEMBERS[string.lower(player)])
140
        if msg == "-защита" and level >= RIGHTS["guard"] then
141
            chat.say("§eЗащита §a§lактивирована")
142
            redstone.setOutput(OUTPUTS["guard"], 16)
143
            GUARD = 1
144
        elseif msg == "-стоп" and level >= RIGHTS["guard"] then
145
            chat.say("§eЗащита §c§lдеактивирована")
146
            redstone.setOutput(OUTPUTS["guard"], 0)
147
            GUARD = 0
148
        elseif msg == "-свет" and level >= RIGHTS["light"] then
149
            if LIGHT == 0 then
150
                chat.say("§eСвет §a§lOn")
151
                redstone.setOutput(OUTPUTS["light"], 16)
152
                LIGHT = 1
153
            else
154
                chat.say("§eСвет §c§lOff")
155
                redstone.setOutput(OUTPUTS["light"], 0)
156
                LIGHT = 0
157
            end
158
        elseif msg == "-музыка" and level >= RIGHTS["music"] then
159
            if MUSIC == 0 then
160
                chat.say("§eМузыка §a§lOn")
161
                MUSIC = 1
162
            else
163
                chat.say("§eМузыка §c§lOff")
164
                MUSIC = 0
165
            end
166
            redstone.setOutput(OUTPUTS["music"], 16)
167
            redstone.setOutput(OUTPUTS["music"], 0)
168
        elseif msg == "-привет" and level >= RIGHTS["hello"] then
169
            chat.say("§fПриветствую, §c"..player)
170
        elseif msg == "-повтор" and level >= RIGHTS["repeat"] then
171
          local index = findRepPlayer(player)
172
          if index ~= 0 then
173
            rep_players[index] = nil
174
            chat.say("§eПовтор чата для §9"..player.." §c§lOff")
175
          else
176
            rep_players[#rep_players+1] = player
177
            chat.say("§eПовтор чата для §9"..player.." §a§lOn")
178
          end
179
        elseif msg == "-взорви всё нахуй" and level >= RIGHTS["guard"] then
180
            chat.say("§c"..player.." §fзапустил отсчёт")
181
            for i = 5, 1, -1 do
182
                chat.say("§fДо взрыва §c"..i)
183
                os.sleep(1)
184
            end
185
            redstone.setOutput(OUTPUTS["light"], 0)
186
            LIGHT = 0
187
            chat.say("§fЯ...§fв-выключаюсь...§f. §fПрощайте, §c"..player)
188
            os.execute("clear")
189
            os.sleep(10)
190
        else
191
          if findRepPlayer(player) ~= 0 then
192
            chat.setName("§aАнтиМут§7] [§6"..level.."§7")
193
            chat.say("§c"..player.."§f: "..message_orig)
194
            chat.setName(NAME)
195
          end
196
        end
197
        updateData()
198
        save() --Сохраняем все
199
    end
200
end