thatparadox

ICBM Missile turtle

Dec 29th, 2013
105
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.open("right")
  2.  
  3. x,y = term.getSize()
  4.  
  5.  
  6.  
  7. missiles = {}
  8.  
  9. function display()
  10. term.clear()
  11. term.setBackgroundColor(colors.black)
  12. for i = 1, 13, 2 do
  13. for v = 1, x do
  14. term.setCursorPos(v, i)
  15. term.write(" ")
  16. end
  17. end
  18. term.setBackgroundColor(colors.blue)
  19. for i = 2, 13, 2 do
  20. for v = 1, x do
  21. term.setCursorPos(v, i)
  22. term.write(" ")
  23. end
  24. end
  25. for i = 1, 12 do
  26. for k,v in pairs(missiles[i]) do
  27. if bit.band(i, 1) == 0 then
  28. term.setBackgroundColor(colors.blue)
  29. else
  30. term.setBackgroundColor(colors.black)
  31. end
  32. if k == "name" then
  33. term.setCursorPos(x/4, i)
  34. term.write(v..":")
  35. elseif k == "count" then
  36. term.setCursorPos(x/3*2, i)
  37. term.write(tostring(v))
  38. end
  39. end
  40. end
  41. end
  42.  
  43.  
  44. if fs.exists("panel") then
  45. file = fs.open("panel","r")
  46. panel = tonumber(file.readAll())
  47. file.close()
  48. else
  49. term.clear()
  50. term.setCursorPos(1,1)
  51. write("Enter the ID of the computer connected to the touch screen: ")
  52. id = tonumber(read())
  53. file = fs.open("panel", "w")
  54. file.write(id)
  55. file.close()
  56. term.clear()
  57. term.setCursorPos(1,1)
  58. end
  59.  
  60. if fs.exists("missiles") then
  61. file = fs.open("missiles", "r")
  62. missiles = textutils.unserialize(file.readAll())
  63. file.close()
  64. else
  65. missiles = {}
  66. for i = 1, 12 do
  67. table.insert(missiles, i, {name = "Unidentified", count = turtle.getItemCount(i)})
  68. end
  69. end
  70.  
  71. while true do
  72. term.setBackgroundColor(colors.black)
  73. term.clear()
  74. term.setCursorPos(x/2-string.len("Screen Saver")/2, y/2)
  75. -- term.write("screen saver")
  76. event, param1,param2,param3,param4 = os.pullEvent()
  77. for i = 1, 12 do
  78. count = turtle.getItemCount(i)
  79. for k,v in pairs(missiles[i]) do
  80. if k == "name" then
  81. missiles[i] = nil
  82. table.insert(missiles, i , {name = v, count = count})
  83. end
  84. end
  85. file = fs.open("missiles", "w")
  86. file.write(textutils.serialize(missiles))
  87. file.close()
  88. end
  89. if event == "modem_message" and param3 == tonumber(panel) and param4 == "getList" then
  90. print("got message")
  91. term.clear()
  92. term.setCursorPos(1,1)
  93. rednet.send(panel, textutils.serialize(missiles))
  94. elseif event == "modem_message" and param3 == tonumber(panel) and param4 == "setName" then
  95. id, slot = rednet.receive()
  96. rednet.send(panel, "ready")
  97. id, mName = rednet.receive()
  98. rednet.send(panel, "ready")
  99. id, slot = rednet.receive()
  100. if mName == "" then
  101. mName = "Unidentified"
  102. end
  103. missiles[slot] = nil
  104. table.insert(missiles, tonumber(slot) , {name = mName, count = turtle.getItemCount(slot)})
  105. file = fs.open("missiles", "w")
  106. file.write(textutils.serialize(missiles))
  107. file.close()
  108. elseif event == "modem_message" and param3 == tonumber(panel) then
  109. turtle.suckDown()
  110. sleep(.5)
  111. turtle.select(tonumber(param4))
  112. turtle.dropDown()
  113. end
  114. display()
  115. end
RAW Paste Data