Guest User

startup

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