Advertisement
furest

Untitled

Aug 23rd, 2014
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. print("start")
  2. whitelist = {"furest","arthuremen1"}
  3. print("whitelist done")
  4. os.loadAPI("ocs/apis/sensor")
  5. mysensor = peripheral.wrap("left")
  6.  
  7. -- vérifie si le joueur détecté est whitelist
  8. function checkexist(nickname)
  9.   for key, nom in pairs(whitelist) do
  10.     if nom == nickname then
  11.       return true
  12.     end
  13.   end
  14. return false
  15. end
  16.  
  17. --Ouvre la porte
  18. function Ouvre()
  19. rs.setOutput("right", true)
  20. sleep(0.2)
  21. rs.setOutput("right", false)
  22. sleep(0.1)
  23. return true
  24. end
  25.  
  26. --Ferme la porte
  27. function Ferme()
  28. rs.setOutput("bottom", true)
  29. sleep(0.2)
  30. rs.setOutput("bottom", false)
  31. sleep(0.1)
  32. return true
  33. end
  34.  
  35.  
  36. --Distance du centre de détection
  37. local offset = {
  38. X = 0,
  39. Y = 8,
  40. Z = 0
  41. }
  42. local rayon = 3
  43.  
  44. --Calcule la distance
  45. function distance(pos)
  46.   local xd = pos.X - offset.X
  47.   local yd = pos.Y - offset.Y
  48.   local zd = pos.Z - offset.Z
  49.   return math.sqrt(xd*xd + yd*yd + zd*zd)
  50. end
  51.  
  52. function nearby()
  53.     print("check")
  54.     t = mysensor.getTargets()
  55.     print("targets got")
  56.     for name, details in pairs(t) do
  57.         print(name)
  58.         local x = mysensor.getTargetDetails(name)
  59.         if details.Name == "Player" and checkexist(x.Username) and distance(details.Position) < rayon then
  60.             print(x.Username .. " is there!")
  61.             return true
  62.         end
  63.     end
  64.     return false
  65. end
  66.  
  67. while true do
  68.     if nearby() == true then
  69.         Ouvre()
  70.     else
  71.         Ferme()
  72.     end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement