Advertisement
VADemon

Quarry Server v1.6 [RP2 Turle Quarry]

Apr 6th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. print("Booting...")
  2.  
  3. local IDList = "372,373, 374-379, 432, 433, 434" --list IDs of your turtles here
  4. local startMsg = "start13" --the number are seconds for sleep()
  5.  
  6. print("Hotkeys: \n")
  7. print("\"S\" - Start the quarry")
  8. print("\"E\" - Stop the quarry")
  9. print("Run program \"moveQuarry\" to move the quarry")
  10.  
  11. if not modemSide then modemSide = "top" end
  12.  
  13. if not rednet.isOpen(modemSide) then rednet.open(modemSide) end
  14. local work = true
  15. local button = false
  16.  
  17. --[[ Count IDs ]]
  18. local IDList = string.gsub(IDList, " ", "")
  19. local IDTable, i = {}, 1
  20.  
  21. for word in string.gmatch(IDList, "[^,]%d+") do --part of: Code not published yet
  22.     IDTable[i]=tonumber(word)
  23.         if IDTable[i]>0 then
  24.             i=i+1 --proceed
  25.         else --it's an array of IDs 204-207
  26.             local prev, curr = IDTable[i-1], IDTable[i]*-1 --faster than math.abs()
  27.             local step = 1
  28.             if prev > curr then --if the first number is bigger than the second one (e.g. "470-464")
  29.                 step = -1 --we need to count downwards
  30.             end
  31.             i = i-1 --trust me. We don't wanna to have the same ID twice
  32.             for x = prev, curr, step do
  33.                 IDTable[i] = x
  34.                 i = i+1
  35.             end
  36.         end
  37. end
  38. --[[ End Of ]]
  39.  
  40. function sendStart()
  41.     for _,i in pairs(IDTable) do
  42.         rednet.send(i, startMsg)
  43.     end
  44.     print("Sent start commands!")
  45. end
  46.  
  47. function sendStop()
  48.     for _,i in pairs(IDTable) do
  49.         rednet.send(i, "shutdown")
  50.     end
  51. end
  52.  
  53. parallel.waitForAny(
  54.     function ()
  55.         while true do
  56.             local fromID, msg = rednet.receive()
  57.  
  58.             if msg == "done" then --when ready with current row
  59.                 --Move the quarry
  60.                 sleep(0.25)
  61.                 redstone.setOutput("right", true); sleep(0.75) --contents of moveQuarry programm
  62.                 redstone.setOutput("right", false);
  63.                 redstone.setOutput("back", true); sleep(1)
  64.                 redstone.setOutput("back", false);  --end of moveQuarry programm
  65.                
  66.                 --Launch the turtles
  67.                 for _,i in pairs(IDTable) do
  68.                     rednet.send(i, "go")
  69.                 end
  70.                
  71.             else
  72.                 print("Wrong message: "..msg)
  73.             end
  74.         end
  75.     end,
  76.    
  77.     function ()
  78.         while true do
  79.             if work==false then return true end
  80.             local event, key = os.pullEvent("key")
  81.            
  82.             if key==31 then -- "s"
  83.                 if not button then
  84.                     sendStart()
  85.                     button = true
  86.                 end
  87.             elseif key==18 then -- "e"
  88.                 print("Turning off the turtles...")
  89.                 sendStop()
  90.                 rednet.close("top")
  91.                 work = false
  92.                 button = false
  93.             --elseif key==34 then -- "g"
  94.                 print("\nQuarry Server stopped!")
  95.             end
  96.         end
  97.     end
  98. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement