Advertisement
shirkit

Untitled

Jun 29th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. -- Variables
  2. local itemSensorPlace = "right"
  3. local nuclearSensorPlace = "left"
  4. local modemPlace = "top"
  5. local reactorName = "ic2.blocknuclearreactor"
  6. local lzhName = "item.reactorcondensatorlap"
  7. local cellName = "item.reactoruraniumquad"
  8. local cellEmptyName = "item.itemcelluranempty"
  9.  
  10. -- Private fields
  11. local reactors = {}
  12. local turtles = {}
  13.  
  14. turtles["-2,1,2"] = {6, "-2,0,1"}
  15.  
  16. --[[
  17. 1 = LZH
  18. 2 = Uranium Cell
  19. 3 = Plating
  20. 4 = heat vent
  21. 5 = exchanger
  22. ]]--
  23.  
  24. local items = {
  25. 1,1,1,1,1,1,1,1,1,
  26. 2,2,2,2,2,2,2,2,2,
  27. 2,2,2,2,2,2,2,2,2,
  28. 1,1,1,1,1,1,1,1,1,
  29. 3,3,3,3,3,4,5,4,5,
  30. 3,3,3,3,3,5,4,5,4,
  31. }
  32.  
  33. --[[
  34.  
  35. Targets table
  36.  
  37. Key = X,Y,Z (string)
  38. Value = table
  39.  
  40. ----------------
  41.  
  42. A target table e.g. targets["2,1,-3"]
  43.  
  44. Key = Name
  45. RawName
  46. Position
  47.  
  48. Value = any string e.g. "Nuclear Reactor"
  49. any string e.g. "ic2.blocknuclearreactor"
  50. table
  51.  
  52. ----------------
  53.  
  54. A position table
  55.  
  56. Key = X, Y, Z (a string, like "X")
  57. Value = 2 (a number, like -3)
  58.  
  59. ----------------
  60.  
  61. Sensor.getTargetDetails table
  62.  
  63. Key = Name
  64. RawName
  65. Position
  66. Slots
  67.  
  68. Value = any string e.g. "Nuclear Reactor"
  69. any string e.g. "ic2.blocknuclearreactor"
  70. table
  71. table
  72.  
  73. ----------------
  74.  
  75. Slots table
  76.  
  77. Key = any valid number (between 1 and the number of slots)
  78.  
  79. Value = table
  80.  
  81. ----------------
  82.  
  83. Item table
  84.  
  85. Key = Size
  86. MaxStack
  87. DamageValue
  88. RawName
  89. Name
  90.  
  91. Value = any number
  92. any number e.g. between 1 and 64
  93. any number e.g. between 1 and 9999
  94. any string e.g. "item.reactorcondensatorlap"
  95. any string e.g. "LZH-Condensator"
  96.  
  97.  
  98.  
  99.  
  100. ]]--
  101.  
  102. -- Utility methods
  103. function split(sstr, pattern)
  104. local t = {}
  105. local fpat = "(.-)" .. pattern
  106. local last_end = 1
  107. local s, e, cap = sstr:find(fpat, 1)
  108. while s do
  109. if s ~= 1 or cap ~= "" then
  110. table.insert(t,cap)
  111. end
  112. last_end = e+1
  113. s, e, cap = sstr:find(fpat, last_end)
  114. end
  115. if last_end <= #sstr then
  116. cap = sstr:sub(last_end)
  117. table.insert(t, cap)
  118. end
  119. return t
  120. end
  121.  
  122. function sendMessage(id, messageID, message)
  123. rednet.send(id, "RR " .. messageID .. " " .. message)
  124. end
  125.  
  126. function itemName(number)
  127. if number == 1 then
  128. return lzhName
  129. elseif number == 2 then
  130. return cellName
  131. elseif number == 3 then
  132. return nil
  133. elseif number == 4 then
  134. return nil
  135. elseif number == 5 then
  136. return nil
  137. else
  138. return nil
  139. end
  140. end
  141.  
  142. function itemCmd(reactor, cmd, slot, item)
  143.  
  144. t = is.getTargetDetails(turtles[reactor][2])
  145. local slots2 = t["Slots"]
  146. for k = 1, #slots2, 1 do
  147.  
  148. local it = slots2[k]
  149.  
  150. if it["RawName"] == item then
  151.  
  152. sendMessage(turtles[reactor][1], cmd, item .. " FROM " .. (k-1) .. " TO " .. (slot-1))
  153.  
  154. end
  155.  
  156. end
  157. end
  158.  
  159. -- Startup
  160. os.loadAPI("ocs/apis/sensor")
  161. is = sensor.wrap(itemSensorPlace)
  162. targets = is.getTargets()
  163. rednet.open(modemPlace)
  164.  
  165. -- Get the list of reactors
  166. for k,v in pairs(targets) do
  167. for o,p in pairs(v) do
  168. if o == "RawName" and p == reactorName then
  169. table.insert(reactors, k)
  170. end
  171. end
  172. end
  173.  
  174. -- Loop foreach item in the reactor
  175. for i = 1, #reactors, 1 do
  176.  
  177. key = reactors[i]
  178. details = is.getTargetDetails(key)
  179. slots = details["Slots"]
  180. for k = 1, #slots, 1 do
  181.  
  182. item = slots[k]
  183. if item["RawName"] == lzhName then
  184.  
  185. if item["DamageValue"] > 9900 then
  186. print("broken lzh")
  187. itemCmd(key, "REPLACE", k, lzhName)
  188. end
  189.  
  190. elseif item["Name"] == "empty" then
  191.  
  192. elseif item["RawName"] == cellEmptyName then
  193.  
  194. end
  195. end
  196. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement