Savage_Me55iah

CCsensor door

Jul 18th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. range = {["south_east_bottom"] = {["x"] = -3, ["z"] = -3, ["y"] = 1},
  2.   ["north_west_top"] = {["x"] = 3, ["z"] = 3, ["y"] = 5}}
  3.  
  4.  
  5. function find_peripheral(t, e)
  6.   e = e or nil
  7.   sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
  8.   peripheral_found = false
  9.   for num=1, 6 do
  10.     type = peripheral.getType(sides[num])
  11.     if type == t then
  12.       if e == "wireless" then
  13.         if peripheral.call(sides[num], "isWireless") then
  14.           return sides[num]
  15.         end
  16.       elseif e == "remote" then
  17.         if not peripheral.call(sides[num], "isWireless") then
  18.           return sides[num]
  19.         end
  20.       elseif e == nil then
  21.         return sides[num]
  22.       end
  23.     end
  24.   end
  25.   if peripheral_found ~= true then
  26.     error("No " .. t .. " attached to the computer", 0)
  27.   end
  28. end
  29.  
  30. do
  31.   load_one = function(command)
  32.       if fs.exists(command) then
  33.         local fileHandler = fs.open(command, 'r')
  34.         return textutils.unserialize(fileHandler.readAll())
  35.       end
  36.   end
  37.  
  38.   save_one = function(command1, command2)
  39.       local fileHandler = fs.open(command1, 'w')
  40.       fileHandler.write(textutils.serialize(command2))
  41.       fileHandler.close()
  42.   end
  43. end
  44.  
  45. local whitelist = {[1] = "Savage_Me55iah"}
  46.  
  47. if fs.exists("whitelist") then
  48.   whitelist = load_one("whitelist")
  49. else
  50.   save_one("whitelist", whitelist)
  51. end
  52.  
  53. sensor = peripheral.wrap(find_peripheral("openperipheral_sensor"))
  54. rednet.open(find_peripheral("modem", "wireless"))
  55.  
  56. while true do
  57.   if redstone.getInput("bottom") then
  58.     print("redstone")
  59.     players_in_range = sensor.getPlayerNames()
  60.  
  61.     local open, close, x, z, y = nil, nil, nil, nil, nil
  62.     player_data = {}
  63.     for a,b in pairs(players_in_range) do
  64.       for c,d in pairs(whitelist) do if d == b then open = true else close = true end end
  65.       player_data = sensor.getPlayerData(b)
  66.       if player_data["position"]["x"] <= range["north_west_top"]["x"] and player_data["position"]["x"] >= range["south_east_bottom"]["x"] then x = true end
  67.       if player_data["position"]["z"] <= range["north_west_top"]["z"] and player_data["position"]["z"] >= range["south_east_bottom"]["z"] then z = true end
  68.       if player_data["position"]["y"] <= range["north_west_top"]["y"] and player_data["position"]["y"] >= range["south_east_bottom"]["y"] then y = true end
  69.       print(tostring(player_data["position"]["x"]).." "..tostring(player_data["position"]["z"]).." "..tostring(player_data["position"]["y"]))
  70.     end
  71.     print(tostring(open).." "..tostring(close).." "..tostring(x).." "..tostring(z).." "..tostring(y))
  72.    
  73.     if open and close == false and x and z and y then redstone.setOutput("top", false) print("true") else redstone.setOutput("top", true) print("false") end
  74.     os.startTimer(1)
  75.   else
  76.     redstone.setOutput("top", true)
  77.     print("false")
  78.   end
  79.   os.pullEvent()
  80. end
Advertisement
Add Comment
Please, Sign In to add comment