SHOW:
|
|
- or go back to the newest paste.
1 | -- Version A3 | |
2 | ||
3 | os.pullEvent = coroutine.yield | |
4 | - | while true do |
4 | + | |
5 | - | local r = math.random() |
5 | + | |
6 | - | local col = nil |
6 | + | local systems = peripheral.wrap "top" |
7 | local sign = peripheral.wrap "front" | |
8 | - | if wasCol == colors.red then |
8 | + | |
9 | - | col = colors.orange |
9 | + | local lastPlayer = "" |
10 | - | elseif wasCol == colors.orange then |
10 | + | |
11 | - | if r >= 0.5 then |
11 | + | function fireLaser(y, p, w) |
12 | - | col = colors.green |
12 | + | return pcall(systems.fire, y, p, w) |
13 | - | else |
13 | + | end |
14 | - | col = colors.red |
14 | + | |
15 | - | end |
15 | + | function uselessLasering() |
16 | - | elseif wasCol == colors.green then |
16 | + | fireLaser(0, math.random(240, 300), 0.1) |
17 | - | col = colors.red |
17 | + | end |
18 | - | end |
18 | + | |
19 | function setColor(col) | |
20 | - | mon.setBackgroundColor(col) |
20 | + | mon.setBackgroundColor(col) |
21 | - | mon.clear() |
21 | + | mon.clear() |
22 | end | |
23 | - | wasCol = col |
23 | + | |
24 | function getYawPitch(entity) | |
25 | - | sleep(3) |
25 | + | local x, y, z = entity.x, entity.y, entity.z |
26 | - | end |
26 | + | local pitch = -math.atan2(y, math.sqrt(x * x + z * z)) |
27 | local yaw = math.atan2(-x, z) | |
28 | ||
29 | print(yaw, pitch) | |
30 | ||
31 | return math.deg(yaw), math.deg(pitch) | |
32 | end | |
33 | ||
34 | function status(col) | |
35 | local topLine = "" | |
36 | ||
37 | if col == colors.red then | |
38 | topLine = "No Entry" | |
39 | elseif col == colors.orange then | |
40 | topLine = "Wait for it..." | |
41 | elseif col == colors.green then | |
42 | topLine = "Fine..." | |
43 | elseif col == colors.yellow then | |
44 | topLine = "Er." | |
45 | elseif col == colors.white then | |
46 | topLine = "This is fine..." | |
47 | elseif col == colors.blue then | |
48 | topLine = "Oops." | |
49 | end | |
50 | ||
51 | sign.setSignText(topLine, "I'm " .. os.getComputerLabel(), "Hi " .. lastPlayer, "") | |
52 | end | |
53 | ||
54 | function runLights() | |
55 | while true do | |
56 | local r = math.random() | |
57 | local col = nil | |
58 | ||
59 | if wasCol == colors.red then | |
60 | col = colors.orange | |
61 | elseif wasCol == colors.orange then | |
62 | if r >= 0.2 then | |
63 | col = colors.green | |
64 | elseif r >= 0.05 then | |
65 | col = colors.red | |
66 | else | |
67 | col = colors.yellow | |
68 | end | |
69 | elseif wasCol == colors.green then | |
70 | col = colors.red | |
71 | elseif wasCol == colors.yellow then | |
72 | if r > 0.3 then | |
73 | col = colors.blue | |
74 | else | |
75 | col = colors.green | |
76 | end | |
77 | elseif wasCol == colors.white then | |
78 | if r > 0.8 then | |
79 | col = colors.blue | |
80 | else | |
81 | col = colors.white | |
82 | end | |
83 | else | |
84 | col = colors.yellow | |
85 | end | |
86 | ||
87 | if r > 0.95 then | |
88 | col = colors.white | |
89 | end | |
90 | ||
91 | status(col) | |
92 | ||
93 | setColor(col) | |
94 | ||
95 | wasCol = col | |
96 | ||
97 | uselessLasering() | |
98 | ||
99 | sleep(3) | |
100 | end | |
101 | end | |
102 | ||
103 | function handleEntities() | |
104 | while true do | |
105 | local ok, entities = pcall(systems.sense) | |
106 | ||
107 | if ok then | |
108 | for _, e in pairs(entities) do | |
109 | if e.displayName == "ndiniz2012" or e.displayName == "Keanu73" or displayName == "nagoL2015" or displayName == "Twijn" then | |
110 | setColor(colors.magenta) | |
111 | local y, p = getYawPitch(e) | |
112 | fireLaser(y, p, 0.5) | |
113 | sleep(0.5) | |
114 | elseif e.displayName == "gollark" then | |
115 | setColor(colors.green) | |
116 | elseif e.displayName == "reboot" then | |
117 | os.reboot() | |
118 | elseif e.displayName == "nothjarnan" then | |
119 | for i = 0, 15 do | |
120 | setColor(math.pow(2, i)) | |
121 | sleep(0.1) | |
122 | end | |
123 | elseif e.displayName == "EldidiStroyrr" then | |
124 | for i = 0, 10 do | |
125 | print "E" | |
126 | end | |
127 | end | |
128 | ||
129 | lastPlayer = e.displayName | |
130 | end | |
131 | end | |
132 | ||
133 | sleep(0.1) | |
134 | end | |
135 | end | |
136 | ||
137 | function update() | |
138 | while true do | |
139 | print "Checking firmware database" | |
140 | local req = http.get "https://pastebin.com/raw/8VhRA26t" | |
141 | local newCode = req.readAll() | |
142 | print "Downloaded." | |
143 | ||
144 | print "Loading existing startup..." | |
145 | local f = fs.open("startup", "r") | |
146 | local oldCode = f.readAll() | |
147 | f.close() | |
148 | ||
149 | print "Checking syntax" | |
150 | local syntaxChecks = loadstring(newCode) ~= nil | |
151 | ||
152 | if not syntaxChecks then | |
153 | print "Syntax error. Update cancelled." | |
154 | else | |
155 | print(syntaxChecks) | |
156 | end | |
157 | ||
158 | if newCode ~= oldCode and syntaxChecks then | |
159 | print "Flashing..." | |
160 | local f = fs.open("startup", "w") | |
161 | f.write(newCode) | |
162 | f.close() | |
163 | print "Flashed" | |
164 | sleep(1) | |
165 | os.reboot() | |
166 | end | |
167 | ||
168 | sleep(60) | |
169 | end | |
170 | end | |
171 | ||
172 | for i = 1, 10 do | |
173 | setColor(colors.black) | |
174 | sleep(0.2) | |
175 | setColor(colors.white) | |
176 | sleep(0.2) | |
177 | end | |
178 | ||
179 | parallel.waitForAll(runLights, handleEntities, update) |