Advertisement
ccraftersanonmoose

Gate Controller

Mar 19th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.63 KB | Gaming | 0 0
  1. -- Name the peripherals for simplicity
  2. local pd = peripheral.wrap("playerDetector_0")
  3. local ri = peripheral.wrap("redstoneIntegrator_0")
  4.  
  5. -- Set up the range parameter
  6. local range = 2
  7.  
  8. function check_players()
  9.     -- Get a list of players within range
  10.     local players = pd.getPlayersInRange(range)
  11.    
  12.     -- Set output to true on the "east" side of the redstone integrator if a player is detected
  13.     if #players > 0 then
  14.         ri.setOutput("east", true)
  15.     else
  16.         ri.setOutput("east", false)
  17.     end
  18. end
  19.  
  20. -- Loop to check for players at regular intervals
  21. while true do
  22.     check_players()
  23.     sleep(0.5)
  24. end
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement