Advertisement
EkielZan

turtle mobcontrol

Nov 24th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. -- Computer ID = Turtle
  2. --the ID of the control computer
  3. local spawner = peripheral.wrap("top")
  4. local controller = 2
  5. local currMob = ""
  6. local replyChannel = 1
  7. local listenChannel = 3
  8. local wlmSide= "right"
  9. local wirelessModem = peripheral.wrap(wlmSide)
  10.  
  11. local function respond(myMes)
  12.   mySerMes=textutils.serialize(myMes)
  13.   wirelessModem.transmit(replyChannel, listenChannel, mySerMes)  
  14. end
  15.  
  16. local function getExactStatus()
  17.   if spawner.getSpawnExact() then
  18.     currExact = "Yes"
  19.   else
  20.     currExact = "No"
  21.   end
  22.   respond(currExact)
  23. end
  24.  
  25. local function setCurrMob()
  26.    if spawner.getStackInSlot(1) ~= nil then
  27.      data = spawner.getStackInSlot(1)
  28.      currMob = data.captured
  29.    end
  30.   myMes={message="curMob", argument=currMob}
  31.   mySerMes=textutils.serialize(myMes)
  32.   wirelessModem.transmit(3, 1, mySerMes)
  33. end
  34.  
  35. local function removeMob()
  36.   turtle.select(emSlot)
  37.   turtle.suckUp()
  38. end
  39.  
  40. local function setMob2Spawn(mobSlotID)
  41.   if spawner.getStackInSlot(1) ~= nil then
  42.     removeMob()
  43.   end
  44.   slot = mobSlotID
  45.   emSlot = slot
  46.   turtle.select(slot)
  47.   turtle.dropUp()
  48.   respond("ok")
  49.   setCurrMob()
  50. end
  51.  
  52.  
  53. local function cleanSpawner()
  54.   local slot2Fill=1
  55.   if spawner.getStackInSlot(1) ~= nil then
  56.     for i = 1,16 do
  57.       local itemCount = turtle.getItemCount(i)
  58.       if itemCount == 0 then
  59.         slot2Fill = i
  60.         break
  61.       end
  62.     end
  63.     turtle.select(slot2Fill)
  64.     turtle.suckUp()
  65.   end
  66. end
  67.  
  68. print ("Cleaning Spawner")
  69. cleanSpawner()
  70. print ("Turtle Ready!")
  71. print ("Starting listening loop")
  72. while true do
  73.   getExactStatus()
  74.   print ("Spawner is set to "..currExact)
  75.   wirelessModem.open(listenChannel)--Open channel 3 so that we can listen on it
  76.   event, modemSide, senderChannel, replyChannel, mySerMes, senderDistance = os.pullEvent("modem_message")
  77.   myCopy=textutils.unserialize(mySerMes)
  78.   if myCopy.message == "setMob2Spawn" then
  79.     print("setMob2Spawn")
  80.     setMob2Spawn(myCopy.argument)
  81.   end
  82.   if myCopy.message == "removeMob" then
  83.     print("removeMob")
  84.     removeMob()
  85.   end
  86.   print("-")
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement