Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --The players that are not intruders
- defaultAllowedPlayers = {
- "abc123mewot"
- }
- --The sensors that are connected and where they are connected
- --this only allows for sensors connected via a network cable and modem
- sensorTemplates = {
- ["Back room"] = 0,
- ["Front entrance"] = 1,
- ["Front middle"] = 2,
- ["Back entrance"] = 3,
- ["Front ME"] = 4
- }
- --The monitor to print data onto
- --This can be left as nil to instead print to terminal
- mon = peripheral.wrap("left")
- --The terminal glasses to print data onto
- --This can be left as nil to print just to the monitor/terminal
- glass = peripheral.wrap("openperipheral_bridge_0")
- --The terminal glasses starting y position
- --Set to 20 if you are using a SimplyJetpacks jetpack since its HUD will interfere
- --Set to 0 if you are not using anything that interferes with the glasses HUD
- glassInitialY = 20
- --Default print color for terminal/monitor
- defaultColor = colors.yellow
- --OnIntruder event handler (called whenever there is an intruder)
- --Do not perform long operations here (single thread)
- function OnIntruder(sensorName, sensorId, intruderName)
- end
- function makeSensor(id, name)
- local s = {}
- s.id = id
- s.name = name
- s.pStr = "openperipheral_sensor_" .. id
- s.p = peripheral.wrap(s.pStr)
- if s.p == nil then error("Failed to get sensor's peripheral (" .. s.pStr) end
- s.allowedPlayers = defaultAllowedPlayers
- s.isPlayerAllowed = function(name)
- for k, v in pairs(s.allowedPlayers) do
- if name == v then return true end
- end
- return false
- end
- s.scan = function() s.players = s.p.getPlayers() end
- s.getPlayers = function()
- if s.players == nil then s.scan() end
- return s.players
- end
- print("Created sensor: " .. id .. " (" .. name .. ")")
- return s
- end
- sensors = {}
- for name, id in pairs(sensorTemplates) do
- sensors[id] = makeSensor(id, name)
- end
- function scan()
- for k, s in pairs(sensors) do s.scan() end
- end
- intuder = false
- function printG(y, msg, color, x)
- if color == nil then color = 0xFFFFFF end
- if x == nil then x = 3 end
- glass.addText(x, y, msg, color)
- return y + 10
- end
- function drawGlasses()
- glass.clear()
- y = glassInitialY
- players = {}
- for k, s in pairs(sensors) do
- --y = printG(y, s.name, 0xFFFF00)
- players = s.getPlayers()
- if players ~= nil then
- plen = table.getn(players)
- if plen > 0 then
- y = printG(y, s.name, 0xFFFF00)
- for n, p in pairs(players) do
- name = p.name
- c = 0xFF0000
- if s.isPlayerAllowed(name) then c = 0x00FF00 end
- y = printG(y, n .. ": " .. name, c, 15)
- end
- end
- else
- y = printG(y, "Players is nil?", 0xFF0000, 15)
- end
- end
- if intruder then
- y = printG(y, "INTRUDER!", 0xFF0000, 5)
- end
- glass.sync()
- end
- if mon ~= nil then
- term.redirect(mon)
- end
- while true do
- scan()
- term.clear()
- term.setCursorPos(1, 1)
- if mon ~= nil then mon.setTextScale(1) end
- term.setTextColor(defaultColor)
- for k, s in pairs(sensors) do
- write(s.name .. ": ")
- players = s.getPlayers()
- if players ~= nil then
- pls = table.getn(players)
- c = colors.red
- if pls == 0 then c = colors.cyan
- elseif pls == 1 then c = colors.orange end
- write(pls .. " players")
- term.setTextColor(defaultColor)
- print()
- for num, data in pairs(players) do
- name = data.name
- c = colors.red
- if s.isPlayerAllowed(name) then
- c = colors.green
- else
- intruder = true
- OnIntruder(s.name, s.id, name)
- end
- term.setTextColor(defaultColor)
- write(" " .. num .. ": ")
- term.setTextColor(c)
- print(name)
- term.setTextColor(defaultColor)
- end
- else
- print("Error, players is nil?!")
- end
- end
- if intruder then
- term.setTextColor(colors.red)
- print("INTRUDER")
- if dismissIntruders then intruder = false end
- end
- if glass == nil then
- term.setTextColor(colors.red)
- print("No terminal glasses!")
- else
- drawGlasses()
- end
- sleep(0.1)
- end
Add Comment
Please, Sign In to add comment