View difference between Paste ID: vWSMVhJS and YZLNksBr
SHOW: | | - or go back to the newest paste.
1
function clear()
2
term.clear()
3
term.setCursorPos(1,1)
4
end
5-
function setTable(name, freq, xmin, xmax, ymin, ymax)
5+
6
lock = false
7-
   mob[name]["freq"] = freq
7+
8-
   mob[name]["active"] = false
8+
9
tX, tY = term.getSize()
10
11-
   mob[name]["xmax"] = xmax
11+
rednet.open("right")
12-
   mob[name]["ymax"] = ymax
12+
13
clear()
14
local mob={}
15
redout = {}
16-
   setTable("Chicken", colors.red, 17, 24, 2, 3)
16+
sheep = false
17-
   setTable("Cow", colors.white, 17, 20, 6, 7)
17+
18-
   setTable("Pig", colors.yellow, 17, 20, 4, 5)
18+
function setTable(name, active, xmin, ymin, actiontype, action)
19
   --start, Whether it should be on or off when the program starts (true = on, false = off)
20
   --Modified by SuPeRMiNoR2
21
   mob[name] = {}
22
   mob[name]["action"] = action
23
   mob[name]["actiontype"] = actiontype
24
   mob[name]["active"] = active
25
   mob[name]["xmin"] = xmin
26
   mob[name]["ymin"] = ymin
27
   templen = xmin + #name - 1
28
   mob[name]["xmax"] = templen
29
   mob[name]["ymax"] = ymin
30
end
31
32-
      local on = data["active"]
32+
33
   setTable("Reboot", false, 35, 17, "other", "reboot")
34-
      fill(17,y,currColor, name)
34+
   setTable("Steam Engines", true, 1, 3, "other", "steam")
35-
      y = y+2
35+
   setTable("Lock", true, 1, 17, "other", "lock")
36
   setTable("Lights", true, 1, 1, "other", "lights")
37
end
38
39
function fill(x,y,color,text)
40
  term.setBackgroundColor(color)
41
  term.setCursorPos(x,y)
42
  term.write(text)
43
  term.setBackgroundColor(colors.black)
44-
          print(name)
44+
45
46
function screen()
47
while true do
48
term.clear()
49
   if lock == false then
50-
function setWire()
50+
51
   local currColor
52
   for name,data in pairs(mob) do
53-
      if data["active"] == false then
53+
      x = data["xmin"]
54-
         wire = colors.combine(wire, data["freq"])
54+
      y = data["ymin"]
55
      local on = data["active"]     
56
      if on == true then currColor = colors.lime else currColor = colors.red end
57-
   redstone.setBundledOutput("bottom", wire)
57+
      fill(x,y,currColor, name)
58
   end
59
   fill(36, 1, colors.lime, os.time())	
60-
fillTable()
60+
61-
setWire()
61+
   if lock == true then
62
   fill(12, 9, colors.red, "Control Panel Locked")
63-
  term.clear()
63+
64-
  screen()
64+
65-
--  fill(17,2,colors.lime, "Chicken")
65+
sleep(0.2)
66-
  local e,side,x,y = os.pullEvent("monitor_touch")
66+
67-
  print(x..":"..y)
67+
68-
  checkxy(x,y)
68+
69-
  setWire()
69+
70-
  sleep(.1)
70+
71-
end
71+
72
        if x>=data["xmin"] and x<= data["xmax"] then
73
	  if lock == false then
74
          data["active"] = not data["active"]
75
	  print(name..":"..tostring(x)..":"..tostring(y))
76
          end
77
          if lock == true then
78
          if name == "Lock" then
79
          data["active"] = not data["active"]
80
          end
81
          end
82
        end
83
      end
84
   end
85
end
86
87
function doStuff()
88
   local wire = 0
89
   for name, data in pairs(mob) do
90
      if data["active"] == true then
91
        if data["actiontype"] == "other" then
92
		if data["action"] == "reboot" then
93
			os.reboot()
94
		end
95
		if data["action"] == "sheep" then
96
			sheep = true
97
		end
98
		if data["action"] == "steam" then
99
			rednet.broadcast("steam_on")
100
		end
101
		if data["action"] == "lock" then
102
			lock = true
103
		end
104
		if data["action"] == "lights" then
105
			rednet.broadcast("lights_on")
106
		end
107
	end	
108
      end
109
     if data["active"] == false then
110
	 if data["actiontype"] == "wire" then
111
		if data["inver"] == true then
112
        		wire = colors.combine(wire, data["action"])
113
		end
114
	end
115
	if data["actiontype"] == "other" then
116
		if data["action"] == "sheep" then
117
			sheep = false
118
		end
119
	end
120
	if data["action"] == "steam" then
121
			rednet.broadcast("steam_off")
122
		end
123
	if data["action"] == "lock" then
124
			lock = false
125
		end
126
        if data["action"] == "lights" then
127
			rednet.broadcast("lights_off")
128
	end
129
    end
130
end
131
redstone.setBundledOutput("bottom", wire)
132
end
133
134
function mainLoop()
135
while true do
136
  local e,side,x,y = os.pullEvent("monitor_touch") --Get event
137
  print("Click: "..tostring(x)..":"..tostring(y))
138
  checkxy(x,y) --Check to see if click is on a button, and toggle state if it is
139
  doStuff() --Reads button state and does actions
140
  sleep(0.1)
141
end
142
end
143
144
function main()
145
fillTable() --Populate data table
146
sleep(2)
147
doStuff() --Run once to start autostart things
148
parallel.waitForAll(mainLoop, screen)
149
end
150
151
main()