Guest User

Main Computer

a guest
Sep 12th, 2013
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.63 KB | None | 0 0
  1. -- Num's main base computer + HUD
  2.  
  3. function update()
  4.     while true do
  5.         updateClock()
  6.         updateStatus()
  7.         sleep(0.05)
  8.     end
  9. end
  10.  
  11. function chatEvents()
  12.     while true do
  13.         evt, msg = os.pullEvent("chat_command")
  14.        
  15.         words = {}
  16.         wordCount = 0
  17.         for word in string.gmatch(msg, "%S+") do
  18.             words[wordCount] = word
  19.             wordCount = wordCount + 1
  20.         end
  21.        
  22.         if(words[0]) == "get" then
  23.             if(wordCount == 3 and tonumber(words[1]) ~= nil) then
  24.                 placeItemRequest(tonumber(words[1]), words[2])
  25.             else
  26.                 newStatus("Invalid command!", 3)
  27.             end
  28.         else
  29.             newStatus("Invalid command!", 3)
  30.         end
  31.     end
  32. end
  33.  
  34. function rednetEvents()
  35.     while true do
  36.         id, msg = rednet.receive()
  37.        
  38.         words = {}
  39.         wordCount = 0
  40.         for word in string.gmatch(msg, "%S+") do
  41.             words[wordCount] = word
  42.             wordCount = wordCount + 1
  43.         end
  44.        
  45.         msgColorCode = tonumber(words[0])
  46.         msgText = words[1]
  47.         for i = 2, wordCount-1 do
  48.             msgText = msgText .. " " .. words[i]
  49.         end
  50.        
  51.         newStatus(msgText, msgColorCode)
  52.     end
  53. end
  54.  
  55. function placeItemRequest(num, item)
  56.     if(num <= 0) then
  57.         newStatus("Number too low!", 3)
  58.         return
  59.     end
  60.     if(num > 256) then
  61.         newStatus("Number too high!", 3)
  62.         return
  63.     end
  64.    
  65.     rednet.send(14, num.." "..item, true)
  66. end
  67.  
  68. function updateClock()
  69.     time = os.time()
  70.     clock.setText(textutils.formatTime(time, false))
  71.    
  72.     if(time > 6) then time = time - 6
  73.     else time = time + 18 end
  74.     if(time > 0 and time < 12) then daytime = true
  75.     else daytime = false end
  76.     if(not daytime) then time = time - 12 end
  77.    
  78.     gameHoursTil = 12 - time
  79.     irlSecondsTil = math.floor(gameHoursTil*50)
  80.    
  81.     remainStr = math.floor(irlSecondsTil/60) .. ":"
  82.     if(irlSecondsTil%60 < 10) then remainStr = remainStr .. "0" end
  83.     remainStr = remainStr .. irlSecondsTil%60 .. " IRL until "
  84.     if(daytime) then remainStr = remainStr .. "dusk"
  85.     else remainStr = remainStr .. "dawn" end
  86.    
  87.     remain.setText(remainStr)
  88. end
  89.  
  90. function updateStatus()
  91.     if(statusLife > 0 and not displayingStatus) then activateStatus()
  92.     elseif(statusLife <= 0 and displayingStatus) then deactivateStatus() end
  93.     if(statusLife > 0) then statusLife = statusLife - 1 end
  94. end
  95.  
  96. function newStatus(msg, colorCode)
  97.     statusStr5 = statusStr4
  98.     statusStr4 = statusStr3
  99.     statusStr3 = statusStr2
  100.     statusStr2 = statusStr1
  101.     statusStr1 = msg
  102.     if(colorCode == 1) then status1.setColor(green)
  103.     elseif(colorCode == 2) then status1.setColor(yellow)
  104.     elseif(colorCode == 3) then status1.setColor(red) end
  105.     activateStatus()
  106. end
  107.  
  108. function activateStatus()
  109.     status1.setText(statusStr1)
  110.     status2.setText(statusStr2)
  111.     status3.setText(statusStr3)
  112.     status4.setText(statusStr4)
  113.     status5.setText(statusStr5)
  114.     statusBox.setOpacity2(0.5)
  115.     statusLife = statusLifespan
  116.     displayingStatus = true
  117. end
  118.  
  119. function deactivateStatus()
  120.     status1.setText("")
  121.     status2.setText("")
  122.     status3.setText("")
  123.     status4.setText("")
  124.     status5.setText("")
  125.     statusBox.setOpacity2(0)
  126.     displayingStatus = false
  127. end
  128.  
  129. -----------------------------
  130.  
  131. rednet.open("top")
  132.  
  133. br = peripheral.wrap("left")
  134. br.clear()
  135.  
  136. daytime = true
  137. gameHoursTil = 0
  138. irlSecondsTil = 0
  139. remainStr = "0:00 IRL until dusk"
  140.  
  141. statusLife = 0
  142. statusLifespan = 200
  143. displayingStatus = false
  144. statusStr5 = ""
  145. statusStr4 = ""
  146. statusStr3 = ""
  147. statusStr2 = ""
  148. statusStr1 = ""
  149.  
  150. green = 0x21D928
  151. yellow = 0xF0DE16
  152. red = 0xE00000
  153.  
  154. title = br.addText(5, 15, "Num FTB Unleashed", 0xFFFFFF)
  155. shader = br.addText(5, 25, "Shader pack: Sasukedll7170's v7 Ultra", 0xAAAAAA)
  156. shader.setScale(0.5)
  157. texture = br.addText(5, 30, "Texture pack: Soartex Fanver", 0xAAAAAA)
  158. texture.setScale(0.5)
  159. clock = br.addText(5, 50, "00:00 AM", 0xFFFFFF)
  160. clock.setScale(0.9)
  161. remain = br.addText(5, 60, remainStr, 0xAAAAAA)
  162. remain.setScale(0.5)
  163.  
  164. infoBox = br.addGradientBox(0, 13, br.getStringWidth(shader.getText())*0.5+25, 23, 0x000000, 0, 0x000000, 0.5, 2)
  165. clockBox = br.addGradientBox(0, 48, br.getStringWidth(remain.getText())*0.5+15, 18, 0x000000, 0, 0x000000, 0.5, 2)
  166.  
  167. status5 = br.addText(5, 90, "", 0xAAAAAA)
  168. status5.setScale(0.7)
  169. status4 = br.addText(5, 97, "", 0xAAAAAA)
  170. status4.setScale(0.7)
  171. status3 = br.addText(5, 104, "", 0xAAAAAA)
  172. status3.setScale(0.7)
  173. status2 = br.addText(5, 111, "", 0xAAAAAA)
  174. status2.setScale(0.7)
  175. status1 = br.addText(5, 118, "", 0x21D928)
  176.  
  177. statusBox = br.addGradientBox(0, 88, 140, 39, 0x000000, 0, 0x000000, 0, 2)
  178.  
  179. infoBox.setZIndex(1)
  180. clockBox.setZIndex(1)
  181. statusBox.setZIndex(1)
  182.  
  183. title.setZIndex(2)
  184. shader.setZIndex(2)
  185. texture.setZIndex(2)
  186. clock.setZIndex(2)
  187. remain.setZIndex(2)
  188. status5.setZIndex(2)
  189. status4.setZIndex(2)
  190. status3.setZIndex(2)
  191. status2.setZIndex(2)
  192. status1.setZIndex(2)
  193.  
  194. parallel.waitForAny(update, chatEvents, rednetEvents)
Advertisement
Add Comment
Please, Sign In to add comment