SHARE
TWEET

test

a guest Feb 8th, 2015 248 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local sensor = peripheral.wrap('top')
  2. local white_list = {'Seryoga', 'Desectus', 'AlexVBG', 'NEO', 'Ruslan1911', 'MorfSD', 'Nedfreetoplay'}
  3. local distance_locate = 3
  4.  
  5. local function open_door()
  6.   rs.setOutput('left', true)
  7.   print("Open")
  8. end
  9.  
  10. local function close_door()
  11.   rs.setOutput('left', true)
  12.   rs.setOutput('left', false)
  13.   print("Close")  
  14. end
  15.  
  16.  
  17. local function main()
  18.   close_door()
  19.  
  20.   while true do
  21.     local open = false
  22.     for No, name in pairs(white_list) do
  23.       local try, player = pcall(sensor.getPlayerByName, name)
  24.  
  25.       if try == true then
  26.         local distance = 0
  27.    
  28.         for label, pos in pairs(player['position']) do
  29.           distance = distance + pos * pos
  30.         end
  31.         distance = math.sqrt(distance)
  32.      
  33.         if distance < distance_locate then
  34.           open = true
  35.           break
  36.         end
  37.       end
  38.     end
  39.  
  40.  
  41.     if open == true then
  42.       open_door()
  43.     else
  44.       close_door()
  45.     end
  46.    
  47.     sleep(1)
  48.   end
  49. end
  50.  
  51. main()
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