Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Peripherals
- s = peripheral.wrap("front") --Wrapping Sensor
- -- Relative Coordinates (integer coord when closest to sensor but still on block)
- relX = 0 -- relative x coord to sensor
- relY = 2 -- relative y coord to sensor
- relZ = -1 -- relative z coord to sensor
- -- Helper Functions
- function rnd(num) -- floors a positive number, ceils a negative number
- if num >= 0 then
- return math.floor(num)
- else
- return math.ceil(num)
- end
- end
- function isCorrectPos(pos,x,y,z) -- Compares position vectors to see if same
- if rnd(pos.x) == x and rnd(pos.y) == y and rnd(pos.z) == z then
- return true
- else
- return false
- end
- end
- function inInv(inv,id) -- checks if an item is in the inventory
- local there = false -- true if item is in inventory
- for i = 1, table.getn(inv) do
- if inv[i].id == id then
- there = true
- end
- end
- return there
- end
- while true do
- n=table.getn(s.getPlayerNames()) -- amount of nearby players
- if n > 0 then
- for i = 1, n do
- local p=s.getPlayerNames()[i] -- player name
- local pos=s.getPlayerData(p).position -- coordinate vector of player
- local inv=s.getPlayerData(p).inventory -- inventory data of player
- if isCorrectPos(pos,relX,relY,relZ) and not(inInv(inv,1311) or inInv(inv,1312)) then
- rs.setOutput("left",true) -- Command Block give Remote
- rs.setOutput("back",true) -- Command Block give Terminal Glasses
- else
- rs.setOutput("left",false)
- rs.setOutput("back",false)
- end
- end
- end
- sleep(0) -- allow time for program to yield
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement