Advertisement
oGoOgO

background_app_Player_Detector.lua

Jun 3rd, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. local component = require("component")
  2. local sensor = component.openperipheral_sensor
  3. local event = require("event")
  4.  
  5. local setOutput = component.redstone.setOutput
  6. local getPlayerByUUID = sensor.getPlayerByUUID
  7. local getPlayers = sensor.getPlayers
  8.  
  9. -- min_x, min_y, min z, max_x, max_y, max_z, REDSTONE_SIDE
  10. local points = {
  11. { -2.7, 0, -5, 1.7, 3.3, 0.4, 4 },
  12. { 0, 0, 0, 0, 3.3, 0, 5 },
  13. }
  14.  
  15. local activePoints = {}
  16.  
  17. local function getPoint(uuid)
  18. local playerInfo = getPlayerByUUID(uuid)
  19. if not playerInfo then
  20. return nil
  21. end
  22. local position = playerInfo.basic().position
  23. for i = 1, #points do
  24. local point = points[i]
  25. if position.x >= point[1] and position.y >= point[2] and position.z >= point[3] and position.x <= point[4] and position.y <= point[5] and position.z <= point[6] then
  26. return point
  27. end
  28. end
  29. end
  30.  
  31. local function scan()
  32. local players = getPlayers()
  33. local newActivePoints = {}
  34. for i = 1, #players do
  35. local point = getPoint(players[i].uuid)
  36. if point then
  37. table.insert(newActivePoints, point)
  38. if not table.contains(activePoints, point) then
  39. setOutput(point[7], 15)
  40. end
  41. end
  42. end
  43.  
  44. for i = 1, #activePoints do
  45. local point = activePoints[i]
  46. if not table.contains(newActivePoints, point) then
  47. setOutput(point[7], 0)
  48. end
  49. end
  50. activePoints = newActivePoints
  51. end
  52.  
  53. table.contains = function(t, object)
  54. for _,v in pairs(t) do
  55. if v == object then
  56. return true
  57. end
  58. end
  59. return false
  60. end
  61.  
  62. event.timer(2, scan, math.huge)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement