Advertisement
NanoBob

Portal control

Jul 21st, 2015
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. if fs.exists("events")==false then
  2.     shell.run("pastebin get bmKBU4Rv events")
  3. end
  4. os.loadAPI("events")
  5.  
  6. if fs.exists("button")==false then
  7.     shell.run("pastebin get hbeLn1ni button")
  8. end
  9. os.loadAPI("button")
  10.  
  11. local chest=peripheral.wrap("iron_2")
  12. local portal=peripheral.wrap("right")
  13. local monitor=peripheral.wrap("top")
  14. local sensor=peripheral.wrap("bottom")
  15. local screenx,screeny=monitor.getSize()
  16. button.setMonitorSide("top")
  17.  
  18. local whiteLists={
  19.     ["NanoBob"]={
  20.         ["NanoBob_"]=true,
  21.         ["Joeneter10"]=true,
  22.         ["Ardron"]=true,
  23.     },
  24. }
  25.  
  26. function buttonClicked(buttonID,text)
  27.     local allowed=false
  28.     local players=sensor.getPlayers()
  29.     for i,d in pairs(players) do
  30.         local playerFunctions=sensor.getPlayerByName(d.name)
  31.         local playerData=playerFunctions.select(1)
  32.         local pos=playerData.position
  33.         if whiteLists[text]==nil or whiteLists[text][d.name]==true and pos.x<10 and pos.x>-10 and pos.y<10 and pos.y>-10 and pos.z<10 and pos.z>-10 or whiteLists["*"]==true then
  34.             allowed=true
  35.             break
  36.         end
  37.     end
  38.     if allowed==false then drawWhitelistDeny() sleep(3) return end
  39.     for i=1,chest.getInventorySize() do
  40.         local info=chest.getStackInSlot(i)
  41.         if info~=nil then
  42.             if info.myst_book.destination==text then
  43.                 chest.pushItem("up",i,1,1)
  44.                 sleep(5)
  45.                 portal.pushItem("down",1,1,i)
  46.                 break
  47.             end
  48.         end
  49.     end
  50.     drawDisplay()
  51. end
  52.  
  53. function emptyPortal()
  54.     for i=1,chest.getInventorySize() do
  55.         local info=chest.getStackInSlot(i)
  56.         if info==nil then
  57.             portal.pushItem("down",1,1,i)
  58.             break
  59.         end
  60.     end
  61. end
  62. emptyPortal()
  63.  
  64. function drawDisplay()
  65.     button.removeAllButtons()
  66.     local buttonID=0
  67.     for i=1,chest.getInventorySize() do
  68.         local info=chest.getStackInSlot(i)
  69.         if info~=nil then
  70.             if buttonID>=screeny/3-1 then
  71.                 print(info.myst_book.destination.." - Volume 2 ")              
  72.                 button.addButton(math.floor(screenx*0.5),(buttonID-screeny/3)*3+2,math.floor(screenx*0.5+1),3,info.myst_book.destination,buttonClicked,false,false,128,256)        
  73.             else
  74.                 print(info.myst_book.destination.." - Volume 1 ")          
  75.                 button.addButton(1,buttonID*3+1,math.floor(screenx*0.5),3,info.myst_book.destination,buttonClicked,false,false,128,256)
  76.             end
  77.             buttonID=buttonID+1
  78.         end
  79.     end
  80.    
  81. end
  82. drawDisplay()
  83.  
  84. function drawWhitelistDeny()
  85.     monitor.setBackgroundColor(1)
  86.     monitor.setTextColor(16384)
  87.     for i=1,5 do
  88.         monitor.setCursorPos(screenx*0.5-10,screeny*0.5-4+i)
  89.         monitor.write("                    ")
  90.     end
  91.     monitor.setCursorPos(screenx*0.5-4,screeny*0.5-2)
  92.     monitor.write("Error : ")
  93.     monitor.setCursorPos(screenx*0.5-6,screeny*0.5-1)
  94.     monitor.write("Insufficient")
  95.     monitor.setCursorPos(screenx*0.5-6,screeny*0.5)
  96.     monitor.write("Permission")
  97. end
  98.  
  99. while true do
  100.     events.handleCCEvents()
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement