Advertisement
MrHG

smelt 1.0

Jan 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. -- Wireless Reading Turtle Smeltery Automation (CLIENT)
  2. programName="smelt"
  3. programVersion="1.0"
  4. protocol="ST0"
  5. hostname="SmeltingTurtle"
  6. oreName=""
  7. oreAmount="588"
  8. args = {...}
  9.  
  10. function FindPeripheral(p)
  11. pFound = false
  12. side = ""
  13. local pList = peripheral.getNames()
  14. for i = 1, #pList do
  15. if peripheral.getType(pList[i]) == p then
  16. pFound = true
  17. side = pList[i]
  18. end
  19. end
  20. if pFound then
  21. return side
  22. else
  23. return false
  24. end
  25. end
  26.  
  27. if FindPeripheral("modem") == false then
  28. print("Modem not Found")
  29. return
  30. else
  31. modemSide = FindPeripheral("modem")
  32. end
  33.  
  34. rednet.open(modemSide)
  35. turtleid = rednet.lookup(protocol,hostname)
  36.  
  37. -- Check if turtle is active
  38. if turtleid then
  39. -- Continue
  40. else
  41. print("Turtle Not Found.")
  42. return
  43. end
  44.  
  45. -- Check for Arguments
  46. if args[1] then
  47. oreName = args[1]
  48. if args[2] then
  49. if tonumber(args[2]) > 1024 then
  50. args[2] = 1024
  51. end
  52. oreAmount = tonumber(args[2])
  53. else
  54. -- oreAmount stays the same.
  55. end
  56. print("Telling Turtle to smelt "..oreAmount.." of "..oreName)
  57. else
  58. print("Usage: "..programName.." (ore name) [ore amount]")
  59. return
  60. end
  61.  
  62. --Sending messages to Turtle.
  63. rednet.send(turtleid, oreName, protocol)
  64. rednet.send(turtleid, oreAmount, protocol)
  65. --Awaiting Response.
  66. id2, response = rednet.receive(protocol)
  67. if response == "NO_ORE" then
  68. print("Ore not found.")
  69. return
  70. elseif response == "SUCCESS" then
  71. id3, amountDone = rednet.receive(protocol)
  72. print("Successfully smelted "..amountDone.." "..oreName)
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement