Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Version A3
- os.pullEvent = coroutine.yield
- local mon = peripheral.find "monitor"
- local systems = peripheral.wrap "top"
- local sign = peripheral.wrap "front"
- local wasCol = colors.green
- local lastPlayer = ""
- function fireLaser(y, p, w)
- return pcall(systems.fire, y, p, w)
- end
- function uselessLasering()
- fireLaser(0, math.random(240, 300), 0.1)
- end
- function setColor(col)
- mon.setBackgroundColor(col)
- mon.clear()
- end
- function getYawPitch(entity)
- local x, y, z = entity.x, entity.y, entity.z
- local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
- local yaw = math.atan2(-x, z)
- print(yaw, pitch)
- return math.deg(yaw), math.deg(pitch)
- end
- function status(col)
- local topLine = ""
- if col == colors.red then
- topLine = "No Entry"
- elseif col == colors.orange then
- topLine = "Wait for it..."
- elseif col == colors.green then
- topLine = "Fine..."
- elseif col == colors.yellow then
- topLine = "Er."
- elseif col == colors.white then
- topLine = "This is fine..."
- elseif col == colors.blue then
- topLine = "Oops."
- end
- sign.setSignText(topLine, "I'm " .. os.getComputerLabel(), "Hi " .. lastPlayer, "")
- end
- function runLights()
- while true do
- local r = math.random()
- local col = nil
- if wasCol == colors.red then
- col = colors.orange
- elseif wasCol == colors.orange then
- if r >= 0.2 then
- col = colors.green
- elseif r >= 0.05 then
- col = colors.red
- else
- col = colors.yellow
- end
- elseif wasCol == colors.green then
- col = colors.red
- elseif wasCol == colors.yellow then
- if r > 0.3 then
- col = colors.blue
- else
- col = colors.green
- end
- elseif wasCol == colors.white then
- if r > 0.8 then
- col = colors.blue
- else
- col = colors.white
- end
- else
- col = colors.yellow
- end
- if r > 0.95 then
- col = colors.white
- end
- status(col)
- setColor(col)
- wasCol = col
- uselessLasering()
- sleep(3)
- end
- end
- function handleEntities()
- while true do
- local ok, entities = pcall(systems.sense)
- if ok then
- for _, e in pairs(entities) do
- if e.displayName == "ndiniz2012" or e.displayName == "Keanu73" or displayName == "nagoL2015" or displayName == "Twijn" then
- setColor(colors.magenta)
- local y, p = getYawPitch(e)
- fireLaser(y, p, 0.5)
- sleep(0.5)
- elseif e.displayName == "gollark" then
- setColor(colors.green)
- elseif e.displayName == "reboot" then
- os.reboot()
- elseif e.displayName == "nothjarnan" then
- for i = 0, 15 do
- setColor(math.pow(2, i))
- sleep(0.1)
- end
- elseif e.displayName == "EldidiStroyrr" then
- for i = 0, 10 do
- print "E"
- end
- end
- lastPlayer = e.displayName
- end
- end
- sleep(0.1)
- end
- end
- function update()
- while true do
- print "Checking firmware database"
- local req = http.get "https://pastebin.com/raw/8VhRA26t"
- local newCode = req.readAll()
- print "Downloaded."
- print "Loading existing startup..."
- local f = fs.open("startup", "r")
- local oldCode = f.readAll()
- f.close()
- print "Checking syntax"
- local syntaxChecks = loadstring(newCode) ~= nil
- if not syntaxChecks then
- print "Syntax error. Update cancelled."
- else
- print(syntaxChecks)
- end
- if newCode ~= oldCode and syntaxChecks then
- print "Flashing..."
- local f = fs.open("startup", "w")
- f.write(newCode)
- f.close()
- print "Flashed"
- sleep(1)
- os.reboot()
- end
- sleep(60)
- end
- end
- for i = 1, 10 do
- setColor(colors.black)
- sleep(0.2)
- setColor(colors.white)
- sleep(0.2)
- end
- parallel.waitForAll(runLights, handleEntities, update)
Add Comment
Please, Sign In to add comment