Advertisement
BombBloke

Sensor Monitor (OpenPeripheral)

Sep 11th, 2014
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. local whiteList = {["BombBloke"] = true, ["eliteaccendo"] = true, ["Bluedemon909"] = true}
  2.  
  3. local sensorPos, mon, roomSensor, hunting = {-332,76,-841}, {}
  4. local doorPos = {-320,78,-830}
  5. local bounds = {{-349,-321},{78,84},{-864,-817}}
  6.  
  7. do
  8.     local periphs = peripheral.getNames()
  9.    
  10.     for i=1,#periphs do if peripheral.getType(periphs[i]) == "monitor" then
  11.         mon[#mon+1] = peripheral.wrap(periphs[i])
  12.     elseif peripheral.getType(periphs[i]) == "openperipheral_sensor" then
  13.         roomSensor = peripheral.wrap(periphs[i])
  14.     elseif peripheral.getType(periphs[i]) == "modem" and peripheral.call(periphs[i],"isWireless") then
  15.         rednet.open(periphs[i])
  16.     end end
  17. end
  18.  
  19. for i=1,3 do mon[i].setTextScale(2) end
  20.  
  21. local function clearMon(i)
  22.     mon[i].setTextColour(colours.white)
  23.     mon[i].setBackgroundColour(colours.black)
  24.     mon[i].setTextScale(2)
  25.     mon[i].clear()
  26.     mon[i].setCursorPos(1,1)
  27. end
  28.  
  29. local function monPrint(i,text)
  30.     local xPos,yPos = mon[i].getCursorPos()
  31.     mon[i].write(text)
  32.     mon[i].setCursorPos(1,yPos+1)
  33. end
  34.  
  35. whiteList["BombBloke"] = true
  36. whiteList["eliteaccendo"] = true
  37. whiteList["Bluedemon909"] = true
  38. whiteList["Steelwool199"] = nil
  39.  
  40. rednet.broadcast({"basepatrol"})
  41.  
  42. while true do
  43.     local players = roomSensor.getPlayerNames()
  44.     table.sort(players)
  45.    
  46.     for i=1,#players do
  47.         local pData = roomSensor.getPlayerData(players[i])
  48.        
  49.         if pData then
  50.             pData.position.x = math.floor(pData.position.x + sensorPos[1])
  51.             pData.position.y = math.floor(pData.position.y + sensorPos[2])
  52.             pData.position.z = math.floor(pData.position.z + sensorPos[3])
  53.             players[players[i]] = pData
  54.         end
  55.     end
  56.    
  57.     ----------------------------------------
  58.     -- Open / close computer access door: --
  59.     ----------------------------------------
  60.     local doorClose = true
  61.     for i=1,#players do if players[players[i]] and whiteList[players[i]] and math.abs(doorPos[1]-players[players[i]].position.x) < 5 and math.abs(doorPos[2]-players[players[i]].position.y) < 5 and math.abs(doorPos[3]-players[players[i]].position.z) < 5 then doorClose = false end end
  62.     rs.setOutput("left",doorClose)
  63.    
  64.     for i=1,#players do if players[players[i]] and (players[players[i]].position.x < bounds[1][1] or players[players[i]].position.x > bounds[1][2] or players[players[i]].position.y < bounds[2][1] or players[players[i]].position.y > bounds[2][2] or players[players[i]].position.z < bounds[3][1] or players[players[i]].position.z > bounds[3][2]) then players[players[i]] = nil end end
  65.        
  66.     ----------------------------------------
  67.     --   Update basic monitor readouts:   --
  68.     ----------------------------------------
  69.     local counter = 1
  70.    
  71.     for i=1,#players do
  72.         if players[players[i]] then
  73.             clearMon(counter)
  74.  
  75.             mon[counter].setTextColour(whiteList[players[i]] and colours.green or colours.red)
  76.             monPrint(counter,players[i])
  77.             mon[counter].setTextColour(colours.white)
  78.  
  79.             monPrint(counter,"X: "..players[players[i]].position.x.." Y: "..players[players[i]].position.y.." Z: "..players[players[i]].position.z)
  80.             monPrint(counter,players[players[i]].heldItem and ("Equipped: "..players[players[i]].heldItem.name) or "")
  81.             monPrint(counter,"")
  82.             monPrint(counter,"Health: "..players[players[i]].health.."/"..players[players[i]].maxHealth)
  83.             monPrint(counter,"Food:   "..players[players[i]].foodLevel)
  84.  
  85.             counter = counter + 1
  86.             if counter > #mon then break end
  87.         end
  88.     end
  89.    
  90.     for i=counter,#mon do clearMon(i) end
  91.    
  92.     ----------------------------------------
  93.     --              Turtles:              --
  94.     ----------------------------------------
  95.     local oldhunt = hunting
  96.     hunting = nil
  97.    
  98.     for i=1,#players do if players[players[i]] and not whiteList[players[i]] then hunting = players[i] end end
  99.    
  100.     if hunting then rednet.broadcast({"basepatrol",hunting,{players[hunting].position.x,players[hunting].position.z,players[hunting].position.y}}) end
  101.    
  102.     if oldhunt and not hunting then rednet.broadcast({"basepatrol"}) end
  103.    
  104.     sleep(1)
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement