Advertisement
szymski

Untitled

Jul 21st, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. print("Starting kiosk...")
  2.  
  3. local screenWidth, screenHeight = term.getSize()
  4.  
  5. function initKiosk()
  6. term.setBackgroundColor(colors.white)
  7.  
  8. term.clear()
  9.  
  10. term.setTextColor(colors.black)
  11. term.setCursorPos(2, 2)
  12. term.write("Szymekk's Kiosk - super gazety w super cenie!")
  13. end
  14.  
  15. function initPeripherals()
  16. energyCube = peripheral.wrap("mekanism_machine_0")
  17. sensor = peripheral.wrap("openperipheral_sensor_0")
  18. noteBlock = peripheral.wrap("note_block_0")
  19. end
  20.  
  21. function drawProgressBar(y, text, factor, centerText)
  22. centerText = centerText or ""
  23.  
  24. local offset = 1
  25. local barColor1 = "5"
  26. local barColor2 = "e"
  27.  
  28. term.setTextColor(colors.black)
  29. term.setCursorPos(1 + offset, y)
  30. term.write(text)
  31.  
  32. local barWidth = math.floor(screenWidth * 0.75)
  33.  
  34. local blitText = { }
  35. local blitFgStr = { }
  36. local blitBgStr = { }
  37. for i = 0, barWidth do
  38. blitText[#blitText + 1] = " "
  39. blitFgStr[#blitFgStr + 1] = "f"
  40. blitBgStr[#blitBgStr + 1] = (i / barWidth) <= factor + 0.01 and barColor1 or barColor2
  41. end
  42.  
  43. for i = 1, #centerText do
  44. local textOffset = math.floor((barWidth / 2) - (#centerText / 2))
  45. blitText[textOffset + i] = string.sub(centerText, i, i)
  46. end
  47.  
  48. blitText = table.concat(blitText)
  49. blitBgStr = table.concat(blitBgStr)
  50. blitFgStr = table.concat(blitFgStr)
  51.  
  52. term.setCursorPos(screenWidth - offset - barWidth, y)
  53. term.blit(blitText, blitFgStr, blitBgStr)
  54. end
  55.  
  56. function enterLoop()
  57. while true do
  58. loop()
  59. os.sleep(1)
  60. end
  61. end
  62.  
  63. function loop()
  64. -- Energy cube
  65.  
  66. local energyCur = energyCube.getEnergyStored()
  67. local energyMax = energyCube.getMaxEnergyStored()
  68.  
  69. drawProgressBar(4, "Energia", energyCur / energyMax, energyCur .. " / " .. energyMax .. " RF")
  70.  
  71. drawProgressBar(6, "Drama", 0.2, "Low")
  72.  
  73. -- Sensor
  74.  
  75. local players = sensor.getPlayers()
  76.  
  77. local foundPly = false
  78. for k, v in pairs(players) do
  79. if(v.name == "szymski") then
  80. foundPly = true
  81. break
  82. end
  83. end
  84. local foundSomeoneElse = not foundPly and #players ~= 0
  85.  
  86. if foundPly then
  87. term.setCursorPos(2, 8)
  88. term.write("Czesc, Szymekk!")
  89. else
  90. term.setCursorPos(2, 8)
  91. term.write(" ")
  92. end
  93.  
  94. if foundSomeoneElse then
  95. noteBlock.playSound("random.levelup", 0.7, 1)
  96. os.sleep(0.5)
  97. noteBlock.playSound("random.levelup", 0.3, 1)
  98. os.sleep(0.5)
  99. noteBlock.playSound("random.levelup", 0.1, 1)
  100.  
  101. term.setCursorPos(2, 8)
  102. term.write("Wynocha, " .. players[1].name .. "!")
  103. end
  104. end
  105.  
  106. initKiosk()
  107. initPeripherals()
  108. enterLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement