Advertisement
WhamyKaBlamy

ComputerCraft / Tekkit Security Gatehouse

Jul 31st, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. local mySensor = sensor.wrap("top")
  4. local Player = false
  5. local Monster = false
  6. local pos = {}
  7. -- These are the things to change for yourself
  8. local door_direction = "right"
  9. local dispenser_direction = "back"
  10. local Y_max = 1
  11. local Y_min = -2
  12. local X_max = 3
  13. local X_min = -2
  14. local Z_max = -4
  15. local Z_min = -7
  16.  
  17.  
  18. while 1>0 do
  19.   Player = false
  20.   Monster = false
  21.   os.sleep(0.5)
  22.   for k,v in pairs(mySensor.getTargets()) do
  23.     if v ~= nil and v["IsPlayer"] == true then
  24.       pos = v["Position"]
  25.       if pos["X"] > X_min and pos["X"] < X_max and pos["Y"] > Y_min and pos["Y"] < Y_max and pos["Z"] > Z_min and pos["Z"] < Z_max then
  26.         Player = true
  27.       end
  28.     elseif v~= nil and v["IsPlayer"] == false then
  29.       pos = v["Position"]
  30.       if pos["Z"] < Z_max and pos["Z"] > Z_min and pos["Y"] > Y_min and pos["Y"] < Y_max and pos["X"] > X_min and pos["X"] < X_max then
  31.         Monster = true
  32.       end
  33.     end
  34.   end
  35.   if Player == true then
  36.     redstone.setAnalogOutput(door_direction,15)
  37.   else
  38.     redstone.setAnalogOutput(door_direction,0)
  39.   end
  40.   if Monster == true and Player == false then
  41.     redstone.setAnalogOutput(dispenser_direction,15)
  42.   else
  43.     redstone.setAnalogOutput(dispenser_direction,0)
  44.   end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement