Guest User

mobControl

a guest
Apr 27th, 2014
541
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("ocs/apis/sensor")
  2. sen=sensor.wrap("left")
  3. local senChest=sen.getTargetDetails("0,-1,0")
  4. chest=peripheral.wrap("bottom")
  5. rednet.open("right")
  6. invTable={}
  7.  
  8. function makeInvTable(slot, itemName)
  9.   invTable[slot]=itemName
  10. end
  11.  
  12. function checkInv()
  13.   testSpawner()
  14.   invSize=chest.getSizeInventory()
  15.   print("Inventory has "..invSize.." slots.")
  16.   print("Checking for filled slots...")
  17.   chest.condense()
  18.   invTable={}
  19.   senChest=sen.getTargetDetails("0,-1,0")
  20.   for i=1, invSize do
  21.     if senChest["Slots"][i]["Name"]=="empty" then
  22.         break
  23.       elseif senChest["Slots"][i]["RawName"] ~= "item.mfr.safarinet.reusable" then
  24.         print("-----")
  25.         print("Error.")
  26.         print("Non safari-net in inventory.")
  27.         print("Maintainence Required")
  28.         print("-----")
  29.       else
  30.         makeInvTable(i, senChest["Slots"][i]["Name"])
  31.       end    
  32.     end
  33.   for i, v in pairs(invTable) do
  34.     print(i.." = "..v)
  35.   end
  36. end
  37.  
  38. function sendTable()
  39.   rednet.send(1, textutils.serialize(invTable))
  40. end
  41.  
  42. function testSpawner()
  43.   if turtle.suckUp()==true then
  44.     print("Mob already in spawner. Removing.")
  45.     turtle.dropDown()
  46.   end
  47. end
  48.  
  49. while true do
  50.   rednet.open("right")
  51.   print("Waiting for message...")
  52.   event, ID, message, dist = os.pullEvent("rednet_message")
  53.   print("Recieved message: "..message)
  54.   sleep(0.2)
  55.   if message == "refresh" then
  56.     checkInv()
  57.     sendTable()
  58.   elseif type(message)=="number" then
  59.     testSpawner()
  60.     print("Transferring mob in slot "..message)
  61.     chest.push("up", message-1, 1)
  62.     turtle.dropUp()
  63.   elseif message=="clear" then
  64.     turtle.suckUp()
  65.     turtle.dropDown()
  66.   elseif message=="grinders" then
  67.     redstone.setOutput("back", not redstone.getOutput("back"))
  68.   elseif message=="spawner" then
  69.     redstone.setOutput("top", not redstone.getOutput("top"))
  70.   elseif message=="swap" then
  71.     event, ID, fStack, dist = os.pullEvent("rednet_message")
  72.     if type(fStack)=="number" then
  73.       print(invTable[fStack].." selected")
  74.       event, ID, sStack, dist = os.pullEvent("rednet_message")
  75.       if type(sStack)=="number" then
  76.         if fStack ~= sStack then
  77.           print("Swapping "..invTable[fStack].." with "..invTable[sStack])
  78.           chest.swapStacks(fStack-1, sStack-1)
  79.         else
  80.           print("Same stack selected")
  81.         end
  82.         rednet.send(1, "done")
  83.       else
  84.         print("No mob selected")
  85.         rednet.send(1,"failed")
  86.       end
  87.     else
  88.       print("No mob selected")
  89.       rednet.send(1, "failed")
  90.     end
  91.   elseif message=="remove" then
  92.     event, ID, message, dist = os.pullEvent("rednet_message")
  93.     if type(message)=="number" then
  94.       testSpawner()
  95.       print("Removing mob in slot "..message)
  96.       chest.push("up", message-1, 1)
  97.       turtle.drop()
  98.       rednet.send(1, "done")
  99.     else
  100.       print("No mob selected")
  101.     end
  102.   end
  103.   sleep(0.01)
  104. end
RAW Paste Data