Advertisement
BlueMond

serverLight

Feb 8th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. --server
  2.  
  3. local loc = {}
  4. loc[1] = {1,3,-2}
  5. loc[2] = {1,3,0}
  6. loc[3] = {1,3,2}
  7. loc[4] = {1,3,4}
  8. loc[5] = {-1,3,4}
  9.  
  10. local sens = peripheral.wrap("left")
  11. local modem = peripheral.wrap("top")
  12.  
  13. for y=1,#loc do
  14.     print("opening on "..y)
  15.     modem.open(y)
  16. end
  17.  
  18. while true do
  19.     sleep()
  20.     local players = sens.getPlayers()
  21.     local id = players[1].uuid
  22.  
  23.     local player = sens.getPlayerByUUID(id)
  24.     local info = player.basic()
  25.     local position = info.position
  26.  
  27.     for x=1,#loc do
  28.         local magnitude
  29.         local dist = {loc[x][1] - position.x, loc[x][2] - position.y, loc[x][3] - position.z}
  30.         local total = math.pow(dist[1], 2) + math.pow(dist[2], 2) + math.pow(dist[3], 2)
  31.        
  32.         magnitude = math.sqrt(total)
  33.        
  34.         if magntiude <=2 then
  35.             modem.transmit(x,x,"on")
  36.         else
  37.             modem.transmit(x,x,"off")
  38.         end
  39.        
  40.     end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement