Advertisement
Jakey4543

deployer

Jan 19th, 2022 (edited)
3,738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.15 KB | None | 0 0
  1. -- litteraly just a turtle to deploy turtles
  2. local ports = {
  3.     ["serverPort"] = 8080,
  4.     ["deployerPort"] = 5050
  5. }
  6.  
  7. local modem = peripheral.wrap("left")
  8. modem.open(ports.deployerPort)
  9.  
  10. function getItemIndex(itemName)
  11.     for slot = 1, 16, 1 do
  12.         local item = turtle.getItemDetail(slot)
  13.         if(item ~= nil) then
  14.             if(item["name"] == itemName) then
  15.                 return slot
  16.             end
  17.         end
  18.     end
  19. end
  20.  
  21. local info = nil
  22. repeat
  23.     event, side, senderChannel, replyChannel, msg, distance = os.pullEvent("modem_message")
  24.  
  25.     if msg == "DEPLOY_TURTLE" and replyChannel == ports.serverPort then
  26.         print("Deploying turtle")
  27.         local itemIndex = getItemIndex("computercraft:turtle_normal")
  28.         turtle.place(itemIndex)
  29.         os.sleep(0.5)
  30.         local newTurtle = peripheral.wrap("front") -- assuming turtle is at front of unit
  31.         newTurtle.turnOn() -- turns turtle on
  32.     elseif msg == "BREAK_TURTLE" then
  33.         turtle.dig() -- digs infront to check for turtle incase needs to be destroyed low chance of breaking turtle that is just starting
  34.     end
  35. until info ~= nil
  36.  
  37. print("over")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement