Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- range = {["south_east_bottom"] = {["x"] = -3, ["z"] = -3, ["y"] = 1},
- ["north_west_top"] = {["x"] = 3, ["z"] = 3, ["y"] = 5}}
- function find_peripheral(t, e)
- e = e or nil
- sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
- peripheral_found = false
- for num=1, 6 do
- type = peripheral.getType(sides[num])
- if type == t then
- if e == "wireless" then
- if peripheral.call(sides[num], "isWireless") then
- return sides[num]
- end
- elseif e == "remote" then
- if not peripheral.call(sides[num], "isWireless") then
- return sides[num]
- end
- elseif e == nil then
- return sides[num]
- end
- end
- end
- if peripheral_found ~= true then
- error("No " .. t .. " attached to the computer", 0)
- end
- end
- do
- load_one = function(command)
- if fs.exists(command) then
- local fileHandler = fs.open(command, 'r')
- return textutils.unserialize(fileHandler.readAll())
- end
- end
- save_one = function(command1, command2)
- local fileHandler = fs.open(command1, 'w')
- fileHandler.write(textutils.serialize(command2))
- fileHandler.close()
- end
- end
- local whitelist = {[1] = "Savage_Me55iah"}
- if fs.exists("whitelist") then
- whitelist = load_one("whitelist")
- else
- save_one("whitelist", whitelist)
- end
- sensor = peripheral.wrap(find_peripheral("openperipheral_sensor"))
- rednet.open(find_peripheral("modem", "wireless"))
- while true do
- if redstone.getInput("bottom") then
- print("redstone")
- players_in_range = sensor.getPlayerNames()
- local open, close, x, z, y = nil, nil, nil, nil, nil
- player_data = {}
- for a,b in pairs(players_in_range) do
- for c,d in pairs(whitelist) do if d == b then open = true else close = true end end
- player_data = sensor.getPlayerData(b)
- if player_data["position"]["x"] <= range["north_west_top"]["x"] and player_data["position"]["x"] >= range["south_east_bottom"]["x"] then x = true end
- if player_data["position"]["z"] <= range["north_west_top"]["z"] and player_data["position"]["z"] >= range["south_east_bottom"]["z"] then z = true end
- if player_data["position"]["y"] <= range["north_west_top"]["y"] and player_data["position"]["y"] >= range["south_east_bottom"]["y"] then y = true end
- print(tostring(player_data["position"]["x"]).." "..tostring(player_data["position"]["z"]).." "..tostring(player_data["position"]["y"]))
- end
- print(tostring(open).." "..tostring(close).." "..tostring(x).." "..tostring(z).." "..tostring(y))
- 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
- os.startTimer(1)
- else
- redstone.setOutput("top", true)
- print("false")
- end
- os.pullEvent()
- end
Advertisement
Add Comment
Please, Sign In to add comment