Advertisement
dragontamerfred

ComputerCraft Program: Glasses

Jun 25th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. --config
  2. capacitorNum = 2 --the number of capicitorbanks.
  3. glass = peripheral.find("openperipheral_bridge")--id or side of bridge.
  4. capacitor = peripheral.find("tile_blockcapacitorbank_name") --id or side of capacitorbank.
  5. pName = "dragontamerfred"--put your name here.(not in use now)
  6.  
  7. --functions
  8. --dont edit expert only
  9.  
  10. function timeDis()--draw text
  11.   time = textutils.formatTime(os.time(),true)
  12.   glass.addText(630,2,time,0xFF0000)
  13. end
  14.  
  15. function chatCommand()
  16.     while true do
  17.         local event, side, name, uuid, msg = os.pullEvent()
  18.         if event == "glasses_chat_command" then
  19.             if msg == "energy on" then
  20.                 energy = "true"
  21.             elseif msg == "energy off" then
  22.                 energy = "false"
  23.        end
  24.     end
  25.     end
  26. end
  27.  
  28. function drawHud()--draw the hud
  29.     glass.addBox(1,1,677,10,0xFFFFFF,0.2)
  30.     if energy == "true" then--draw the energy bar
  31.         glass.addBox(1,30,50,125,0x000001,0.2)
  32.         local sEnergy = capacitor.getEnergyStored("UNKNOWN")
  33.         local sEnergy = sEnergy*capacitorNum
  34.         local mEnergy = capacitor.getMaxEnergyStored("UNKNOWN")
  35.         local mEnergy = mEnergy*capacitorNum
  36.         local pEnergy = math.floor((sEnergy/mEnergy)*100)
  37.         print ("energy stored: "..pEnergy.."%")
  38.         glass.addText(6,140,pEnergy.."%",0x09FF00)
  39.         glass.addBox(6,35,15,100-pEnergy,0xFDFF00,0.2)
  40.         glass.addBox(6,35,15,100,0x990000,0.5)
  41.     end
  42. end
  43.  
  44. --main loop
  45. function start()
  46.   while true do
  47.     glass.clear()
  48.     drawHud()
  49.     timeDis()
  50.     glass.sync()
  51.     sleep(.1)
  52.   end
  53. end
  54.  
  55. --the program
  56. parallel.waitForAll(start, chatCommand)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement