Advertisement
TheMeFund

ElevatorConcept

Mar 5th, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. --Wrap modem and open Rednet on left of Computer
  2. rednet.close("left")
  3. rednet.open("left")
  4.  
  5. --Set variable for and wrap touchscreen on top of Computer
  6. m = peripheral.wrap("top")
  7.  
  8. --Check for Restone Output
  9. local rsCheck = redstone.getOutput("bottom")
  10.  
  11. --Build our Tables
  12. floorID = {"591", "590", "584", "589", "644","702", "769"} --Ids of the computers
  13. floorNAME = {"Power","Sorting","Storage","Farming","Library","Control", "MobFarm"} --Names of the floors
  14. floorNUM = {} --Giving Index Values to the Floors
  15. for i,v in ipairs(floorID) do
  16.     floorNUM[v] = i
  17. end
  18.  
  19.  
  20. --Write our buttons
  21. m.clear()
  22. ymin = 1
  23. for i = 1,table.getn(floorID) do
  24.     m.setCursorPos(1,ymin)
  25.     m.write(floorNAME[i])
  26.     ymin = ymin + 1
  27. end
  28.  
  29. --Start Loop
  30. while true do
  31.     local compID = os.getComputerID()
  32.     local event,senderID,message,y = os.pullEvent()
  33.  
  34. --Check for user input
  35.     if event == "monitor_touch" then
  36.         if floorID[y] == tostring(compID) and rsCheck == false then
  37.             rednet.broadcast("Clear Elevator Redstone")
  38.             print("Clearing Redstone Elsewhere")
  39.             print("Calling Elevator Here")
  40.             redstone.setOutput("bottom",true)
  41.         elseif floorID[y] == tostring(compID) and rsCheck == true then
  42.             print("Elevator Already Here")
  43.         else
  44.             rednet.broadcast(floorID[y])
  45.             print( "Message Sent to ",floorID[y] )
  46.             redstone.setOutput("bottom",false)
  47.         end
  48.          
  49. --Look for Rednet Messages
  50.     elseif event == "rednet_message" then
  51.         if senderID == compID and rsCheck == false and message == tostring(compID) then
  52.             print("Calling Elevator")
  53.             rs.setOutput("bottom",true)
  54.         elseif senderID == compID and rsCheck == true and message == tostring(  compID) then
  55.             print("Elevator Here Already")
  56.         elseif senderID ~= compID then
  57.             print("Command from ",senderID," to ",message)
  58.  
  59. --If message is the Id of the current Comp, turn redstone on
  60.             if message == tostring(compID) then
  61.                 redstone.setOutput("bottom",true)
  62.                 print("Calling Elevator")
  63.             elseif message == "Clear Elevator Redstone" then
  64.                 print("Elevator got called to computer ",senderID)
  65.                 redstone.setOutput("bottom",false)
  66.             else
  67.                 for i = 1,table.getn(floorID) do
  68.                     if message == floorID[i] then
  69.                         print("Elevator going to computer ",message)
  70.                         redstone.setOutput("bottom",false)
  71.                     else
  72.                         print("Not for Elevator")
  73.                     end
  74.                 end
  75.             end
  76.         end
  77.     end
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement