nomnuggetnom

Exerpimental

Sep 25th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.94 KB | None | 0 0
  1. --local modem = peripheral.wrap("right") modem.open(1)
  2. local terminalBridge = peripheral.wrap("back") terminalBridge.clear()
  3. local sysBridge = peripheral.wrap("right")
  4. local controller = peripheral.wrap("bottom")
  5. local modem = peripheral.wrap("top") for i=1, 51 do modem.open(i) end
  6.  
  7. -- AE Storage
  8. calcUsage = (controller.getUsedBytes()) / (controller.getTotalBytes())
  9. calcDisplay = math.floor(calcUsage * 75)
  10. calcPercent = math.floor(calcUsage * 100)
  11.  
  12. -- addBox(x,y,width,height,hexcolor,opacity)
  13. -- addText(x,y,text,color)
  14. function displayAE()
  15. terminalBridge.clear()
  16. local meter = terminalBridge.addBox(calcDisplay, 244, 1, 7, 0x000000, 1.0)
  17. local box = terminalBridge.addBox(5, 245, 75, 5, 0xB3150C, 0.5)
  18. box.setGradient(2)
  19. box.setColor2(0x1A991C)
  20. local meter = terminalBridge.addBox(calcDisplay, 244, 1, 7, 0x000000, 1.0)
  21. local percentDisplay = terminalBridge.addText(83, 244, "" ..tostring(calcPercent).. "%", 0xFFFFFF)
  22. end
  23.  
  24. ---------------------------------------------------
  25. ----------------[[ Item System ]]------------------
  26. ---------------------------------------------------
  27. itemIndex = {}
  28. -- itemIndex[name] = id
  29. idIndex = {}
  30. -- idIndex[id] = name
  31. itemStock = {}
  32. -- itemStock[id] = number
  33.  
  34. function retrieveCrafts()
  35. canCraft = sysBridge.listCraft()
  36. end
  37.  
  38. function retrieveStorage()
  39. itemStock = sysBridge.listItems()
  40. end
  41.  
  42. function retrieveIDs()
  43. fileRead = fs.open("itemIndex", "r")
  44. lineText = fileRead.readLine()
  45. while lineText ~= nil do
  46. _, _, key, value = string.find(lineText, "(%a+)%s*=%s*(%d+)")
  47. itemIndex[key]= tonumber(value)
  48. _, _, key, value = string.find(lineText, "(%a+)%s*=%s*(%d+)")
  49. idIndex[tonumber(value)]=key
  50. lineText = fileRead.readLine()
  51. end
  52. fileRead.close()
  53. end
  54.  
  55. retrieveIDs()
  56.  
  57. function isIndexed(itemID)
  58. if itemIndex[itemID] == nil then return false
  59. else return true end
  60. end
  61.  
  62. function craftItem(reqID, reqQty, transfer)
  63. sysBridge.craft(reqID, reqQty)
  64. if idIndex[reqID] ~= nil then
  65. sysStatus = "Crafting.."
  66. displayText("Crafting " ..tostring(reqQty).. " " ..tostring(idIndex[reqID]).. "...")
  67. else
  68. sysStatus = "Crafting.."
  69. displayText("Crafting " ..tostring(reqQty).. " " ..tostring(reqID).. "...")
  70. end
  71. if transfer ~= "n" then
  72. print("Transfer command")
  73. transferItem(reqID,reqQty, false)
  74. end
  75. end
  76.  
  77. function indexID(itemName, itemID)
  78. if itemIndex[itemName] == nil then
  79. fileWrite = fs.open("itemIndex", "a")
  80. fileWrite.writeLine(tostring(itemName).. "=" ..tonumber(itemID))
  81. displayText("Item '" ..tostring(itemName).. "' indexed (" ..tostring(itemID) .. ").")
  82. fileWrite.close()
  83. retrieveIDs()
  84. elseif itemIndex[itemName] ~= nil and itemID == itemIndex[itemName] then
  85. displayText("Item already exists.")
  86. end
  87. end
  88.  
  89.  
  90.  
  91. function displayText(textInput)
  92. sysStatus = "dispText" terminalBridge.clear() displayAE()
  93. stringL = math.floor(terminalBridge.getStringWidth(tostring(textInput)))
  94. boxW = stringL + 10
  95. -- addBox x, y, w, h, color, opacity
  96. -- Fade In
  97. dispLine = terminalBridge.addBox(7, 7, 1, 15, 0x347D0A, 0.0)
  98. for i = 0, 1, 0.00003 do dispLine.setOpacity(i) end
  99. dispBox = terminalBridge.addGradientBox(8, 7, boxW, 15, 0x000000, 0.0, 0x000000, 0.0, 2)
  100. for i = 0, boxW, boxW/30000 do dispBox.setWidth(i) dispBox.setOpacity2((i/dispBox.getWidth())/2.5) end
  101. dispText = terminalBridge.addText(13, 11, tostring(textInput), 0xFFFFFF)
  102. dispText.setZIndex(1)
  103. --sleep(2)
  104. --print("About to start the timer.")
  105. end
  106.  
  107. function fadeIn(textInput, ypos)
  108. sysStatus = "dispText" terminalBridge.clear() displayAE()
  109. stringL = math.floor(terminalBridge.getStringWidth(tostring(textInput)))
  110. boxW = stringL + 10
  111. dispLine = terminalBridge.addBox(7, 7, 1, 15, 0x347D0A, 0.0)
  112. for i = 0, 1, 0.00003 do dispLine.setOpacity(i) end
  113. dispBox = terminalBridge.addGradientBox(8, 7, boxW, 15, 0x000000, 0.0, 0x000000, 0.0, 2)
  114. for i = 0, boxW, boxW/30000 do dispBox.setWidth(i) dispBox.setOpacity2((i/dispBox.getWidth())/2.5) end
  115. dispText = terminalBridge.addText(13, 11, tostring(textInput), 0xFFFFFF)
  116. dispText.setZIndex(1)
  117. end
  118.  
  119. function fadeOut(opacity)
  120. dispText.setText("")
  121. for i = (dispBox.getOpacity2()), 0, -0.00006 do dispBox.setOpacity2(i) dispLine.setOpacity(i) end
  122. sysStatus = "idle"
  123. end
  124.  
  125. --[[
  126. function displayText(textInput, fade)
  127. if fade ~= "out" then
  128. sysStatus = "dispText" terminalBridge.clear() displayAE()
  129. stringL = math.floor(terminalBridge.getStringWidth(tostring(textInput)))
  130. boxW = stringL + 10
  131. -- addBox x, y, w, h, color, opacity
  132. -- Fade In
  133. dispLine = terminalBridge.addBox(7, 7, 1, 15, 0x347D0A, 0.0)
  134. for i = 0, 1, 0.00003 do dispLine.setOpacity(i) end
  135. dispBox = terminalBridge.addGradientBox(8, 7, boxW, 15, 0x000000, 0.0, 0x000000, 0.0, 2)
  136. for i = 0, boxW, boxW/30000 do dispBox.setWidth(i) dispBox.setOpacity2((i/dispBox.getWidth())/2.5) end
  137. dispText = terminalBridge.addText(13, 11, textInput ,0xFFFFFF)
  138. dispText.setZIndex(1)
  139. --sleep(2)
  140. os.startTimer(2)
  141. else
  142. print("fadeOut")
  143. dispText.setText("")
  144. for i = 1, 0, -0.00003 do dispBox.setOpacity2(i/2.5) dispLine.setOpacity(i) end
  145. end
  146. end]]--
  147.  
  148. function transferItem(itemID, itemQty, doCraft)
  149. retrieveStorage()
  150. --print("ID: " ..tostring(itemID).. ". Req. Num: " ..tostring(itemQty).. ". Craft? "..tostring(doCraft).. ".")
  151. if doCraft then
  152. if itemStock[itemID] == nil then storedItems = 0 else storedItems = itemStock[itemID] end
  153. neededItems = itemQty - storedItems
  154. --print("In stock: "..tostring(storedItems).. ". Needed: "..tostring(itemQty-storedItems)..".")
  155. orderedCraft = false
  156. if neededItems > 0 then -- We'll need to craft some items.
  157. if not orderedCraft then
  158. --print("I'll need to order some crafting.")
  159. sysBridge.craft(itemID, itemQty)
  160. orderedCraft = true
  161. displayText("Crafting "..tostring(neededItems).." of "..tostring(itemQty).." '"..tostring(idIndex[itemID]).."'...")
  162. while neededItems > 0 do -- Already ordered crafting. Waiting.
  163. retrieveStorage()
  164. if itemStock[itemID] == nil then storedItems = 0 else storedItems = itemStock[itemID] end
  165. neededItems = itemQty - storedItems
  166. print(storedItems)
  167. sleep(.5)
  168. end
  169. -- Once we get here, we have enough items.
  170. sysBridge.retrieve(itemID, itemQty, 4)
  171. displayText("Finished crafting, moved "..tostring(itemQty).." '"..tostring(idIndex[itemID]).."'.")
  172. end
  173. else -- No need to craft, we have enough.
  174. sysBridge.retrieve(itemID, itemQty, 4)
  175. displayText("Moved "..tostring(itemQty).. " '"..tostring(idIndex[itemID]).."'.")
  176. end
  177. else
  178. itemsMoved = sysBridge.retrieve(itemID, 1728, 4)
  179. displayText("Moved "..tostring(itemsMoved).." '"..tostring(idIndex[itemID]).."'.")
  180. end
  181. end
  182.  
  183. retrieveIDs()
  184. retrieveCrafts()
  185. retrieveStorage()
  186. -------------
  187. while true do
  188. -------------
  189. local event, p1, p2, p3, p4 = os.pullEvent()
  190. displayAE()
  191.  
  192. --[[ Input Handling ]]--
  193. --[[
  194. local chatEvent, input = os.pullEvent("chat_command")
  195. local userInput = {}
  196. for i in string.gmatch(input, "%S+") do
  197. table.insert(userInput, i)
  198. end
  199. ]]--
  200.  
  201. local userInput = {}
  202. if event == "chat_command" then
  203. for i in string.gmatch(p1, "%S+") do
  204. table.insert(userInput, i)
  205. end
  206. elseif event == "timer" and sysStatus == "dispText" then
  207. fadeOut()
  208. end
  209.  
  210. --[[
  211. if event == "timer" and sysStatus == "dispText" then
  212. fadeOut()
  213. end]]--
  214.  
  215.  
  216.  
  217. --[[ Crafting Handling ]]--
  218. if userInput[1] == "craft" or userInput[1] == "make" then
  219. -- userInput[2] is quantity
  220. -- userInput[3] is item
  221. -- userInput[4] is optional, for transferring items
  222. if not tonumber(userInput[3]) then -- Received text input
  223. if itemIndex[userInput[3]] ~= nil then
  224. craftItem(tonumber(itemIndex[userInput[3]]), tonumber(userInput[2]), userInput[4])
  225. else
  226. displayText("Item '" ..tostring(userInput[3]).. "' not recognized.")
  227. end
  228. else
  229. craftItem(tonumber(userInput[3]), tonumber(userInput[2]), userInput[4])
  230. end
  231. --[[ Transfer Handling ]]--
  232.  
  233. --[[ Item Transferring ]]
  234. elseif userInput[1] == "transfer" or userInput[1] == "move" then
  235. -- userInput[2] is quantity, or all
  236. -- userInput[3] is item name
  237. if not tonumber(userInput[3]) then -- Received text input
  238. if itemIndex[userInput[3]] ~= nil then
  239. if userInput[2] == "all" then
  240. transferItem(tonumber(itemIndex[userInput[3]]), tonumber(userInput[2]), false)
  241. elseif tonumber(userInput[2]) then
  242. transferItem(tonumber(itemIndex[userInput[3]]), tonumber(userInput[2]), true)
  243. end
  244. else
  245. displayText("Item '" ..tostring(userInput[3]).. "' not recognized.")
  246. end
  247. else
  248. transferItem(tonumber(userInput[3]), tonumber(userInput[2]), true)
  249. end
  250. --[[ Manual Item Indexing ]]--
  251.  
  252. --[[ Item Indexing ]]--
  253. elseif userInput[1] == "index" then
  254. -- userInput[2] is name
  255. -- userInput[3] is ID
  256. -- userInput[4] is metadata
  257. if tonumber(userInput[2]) then displayText("Wrong format, second input should be the item name.")
  258. elseif not tonumber(userInput[3]) then displayText("Wrong format, third input should be the item ID.")
  259. elseif not tonumber(userInput[4]) and userInput[4] ~= nil then displayText("Wrong format, fourth input should be (optional) metadata.")
  260. elseif userInput[4] == nil then
  261. indexID(userInput[2],tonumber(userInput[3]))
  262. retrieveIDs()
  263. elseif userInput[4] ~= nil then
  264. indexID(userInput[2], (tonumber(userInput[4]) * 32768)+userInput[3])
  265. retrieveIDs()
  266. --else
  267. --indexID(userInput[2],tonumber(userInput[3]))
  268. --retrieveIDs()
  269. end
  270.  
  271.  
  272. elseif userInput[1] == "check" or userInput[1] == "num" or userInput[1] == "stock" then
  273. -- userInput[2] is name or ID
  274. retrieveStorage()
  275. if not tonumber(userInput[2]) then -- Received text
  276. if isIndexed(userInput[2]) then
  277. displayText("Currently " ..tostring(itemStock[itemIndex[userInput[2]]]).. " '" ..tostring(userInput[2]).. "' stored.")
  278. else
  279. displayText("Item '" ..tostring(userInput[2]).. "' not recognized.")
  280. end
  281. end
  282.  
  283. --[[ Multiplacation ]]--
  284. elseif userInput[1] == "math" then
  285. local eval, error = loadstring("return " ..userInput[2])
  286. if error then
  287. displayText("Error processing '" ..tostring(userInput[2]).. "'.")
  288. else
  289. displayText(eval())
  290. end
  291.  
  292. --[[ Display Request ]]--
  293. elseif userInput[1] == "display" then
  294. for i in string.gmatch(p1, "display(.+)") do
  295. fadeIn(i, 15)
  296. os.startTimer(2)
  297. end
  298.  
  299. --[[ Modem Handling ]]--
  300. elseif userInput[1] == "toggle" or userInput[1] == "t" then
  301. modem.transmit(50, 50, tostring(userInput[2]))
  302. local modemMessage, p1, p2, p3, p4 = os.pullEvent("modem_message")
  303. if p4 then spawnerStatus = "off" else spawnerStatus = "on" end
  304. displayText("Toggled '"..tostring(userInput[2]).."' to "..tostring(spawnerStatus)..".")
  305.  
  306. --[[ Enderchest Clear ]]--
  307. elseif userInput[1] == "clear" or userInput[1] == "empty" then
  308. modem.transmit(51, 51, "go")
  309. displayText("Clearing, please wait for a few seconds...")
  310. sleep(.5)
  311. modem.transmit(51, 51, "stop")
  312. local modemMessage, p1, p2, p3, p4 = os.pullEvent("modem_message")
  313. if p4 == "cleared" then displayText("Cleared the enderchest.") end
  314. retrieveStorage()
  315. end -- End of first if
  316. ---
  317. end
  318. ---
Advertisement
Add Comment
Please, Sign In to add comment