SHARE
TWEET

startup

a guest May 25th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("ocs/apis/sensor")
  2. local proximity = sensor.wrap("right")
  3. local signal = false
  4.  
  5.  
  6. local offset = {
  7. X = 0,
  8. Y = 2,
  9. Z = 0
  10. }
  11.  
  12. -------------------------------------
  13.  
  14. local radius = 10
  15. local pName = "mkmush"
  16. local outp = "top"
  17.  
  18. -------------------------------------
  19.  
  20.  
  21. function distance(pos)
  22.   local xd = pos.X - offset.X
  23.   local yd = pos.Y - offset.Y
  24.   local zd = pos.Z - offset.Z
  25.   return math.abs(xd*xd + yd*yd + zd*zd)
  26. end
  27.  
  28.  
  29. function opendoor()
  30. t = proximity.getTargets()
  31. for name, basicDetails in pairs(t) do
  32.    local master = proximity.getTargetDetails(name)
  33.     if distance(master.Position) <= radius and master.Username == pName then
  34.       print("Player " .. pName .. " detected")
  35.       return true
  36.     end
  37. end
  38. return false
  39. end
  40.  
  41.  
  42. while true do
  43.  term.clear()
  44.  term.setCursorPos(1,1)
  45.  print("Running")
  46.  
  47.  rs.setOutput(outp, opendoor())
  48.  
  49.  sleep(0.5)
  50.  
  51. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top