Advertisement
BeefyMuscle

Beef's Porta-Matrix Pocket-Computer Script

Oct 23rd, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. --Beef's Porta-Matrix Pocket-Computer Script--
  2.  
  3.  
  4. --wrapping the ender modem behind the Pocket Comptuer--
  5. local m = peripheral.wrap("back")
  6.  
  7.  
  8. --listening on channel 241--
  9. m.open(241)
  10.  
  11.  
  12. --refresh monitor
  13. term.clear()
  14.  
  15.  
  16. --setting universal variables--
  17. monX, monY = term.getSize()
  18. local mult = 10^2
  19. local center = math.floor(monX/2)
  20.  
  21. while (true)
  22. do
  23. --reading for message events--
  24. local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  25.  
  26.  
  27. --unserializing the table from message-- MASSIVE thanks to Fatboychummy on discord for helping me understand wireless events and tables.
  28. local mD = textutils.unserialise(message)
  29.  
  30. --create power bar math
  31. local charge = math.floor(mD.curPow / mD.maxPow * 100 + 0.5)
  32. local tUse = math.floor((mD.curIn+mD.curOut)/mD.tfCap * 100 + 0.5)
  33.  
  34.  
  35. --set title--
  36. term.clear()
  37. term.setCursorPos(center-7,1)
  38. term.setBackgroundColor(colors.white)
  39. term.setTextColor(colors.black)
  40. print(" Porta-Matrix ")
  41.  
  42.  
  43. --draw labels--
  44. term.setBackgroundColor(colors.black)
  45. term.setTextColor(colors.orange)
  46. term.setCursorPos(center-5,3)
  47. print("Max Power:")
  48. term.setCursorPos(center-7,5)
  49. print("Current Power:")
  50. term.setCursorPos(center-3,7)
  51. print("Input:")
  52. term.setCursorPos(center-3,9)
  53. print("Output:")
  54. term.setCursorPos(center-6,11)
  55. print("Transfer Cap:")
  56. term.setCursorPos(2,14)
  57. print("Charge:")
  58. term.setCursorPos(2,17)
  59. print("Transfer Usage:")
  60.  
  61.  
  62.  
  63. --format power level text--
  64. term.setBackgroundColor(colors.black)
  65. term.setTextColor(colors.white)
  66.  
  67.  
  68. --write max power--
  69. term.setTextColor(colors.white)
  70. term.setCursorPos(center-4, 4)
  71. e = mD.maxPow
  72. if e >= 1000 and e < 1000000 then
  73. term.write(string.format("%.0f", math.floor(e/1000 * mult + 0.5)/mult))
  74. term.write("kRF")
  75. elseif e >= 1000000 and e < 1000000000 then
  76. term.write(string.format("%.0f", math.floor(e/1000000 * mult + 0.5)/mult))
  77. term.write("mRF")
  78. elseif e >= 1000000000 and e < 1000000000000 then
  79. term.write(string.format("%.0f", math.floor(e/1000000000 * mult + 0.5)/mult))
  80. term.write("gRF")
  81. else
  82. term.write(tostring(mD.maxPow))
  83. term.write("RF")
  84. end
  85.  
  86.  
  87. --write current power--
  88. term.setTextColor(colors.white)
  89. term.setCursorPos(center-4, 6)
  90. e = mD.curPow
  91. if e >= 1000 and e < 1000000 then
  92. term.write(string.format("%.0f", math.floor(e/1000 * mult + 0.5)/mult))
  93. term.write("kRF")
  94. elseif e >= 1000000 and e < 1000000000 then
  95. term.write(string.format("%.0f", math.floor(e/1000000 * mult + 0.5)/mult))
  96. term.write("mRF")
  97. elseif e >= 1000000000 and e < 1000000000000 then
  98. term.write(string.format("%.0f", math.floor(e/1000000000 * mult + 0.5)/mult))
  99. term.write("gRF")
  100. else
  101. term.write(tostring(mD.curPow))
  102. term.write("RF")
  103. end
  104.  
  105.  
  106. --write input--
  107. term.setTextColor(colors.white)
  108. term.setCursorPos(center-5, 8)
  109. e = mD.curIn
  110. if e >= 1000 and e < 1000000 then
  111. term.setCursorPos(center-4, 8)
  112. term.write(string.format("%.0f", math.floor(e/1000 * mult + 0.5)/mult))
  113. term.write("kRF/t")
  114. elseif e >= 1000000 and e < 1000000000 then
  115. term.write(string.format("%.0f", math.floor(e/1000000 * mult + 0.5)/mult))
  116. term.write("mRF/t")
  117. elseif e >= 1000000000 and e < 1000000000000 then
  118. term.write(string.format("%.0f", math.floor(e/1000000000 * mult + 0.5)/mult))
  119. term.write("gRF/t")
  120. else
  121. term.setCursorPos(center-2, 8)
  122. term.write("0RF/t")
  123. end
  124.  
  125.  
  126. --write output--
  127. term.setTextColor(colors.white)
  128. term.setCursorPos(center-4, 10)
  129. e = mD.curOut
  130. if e >= 1000 and e < 1000000 then
  131. term.write(string.format("%.0f", math.floor(e/1000 * mult + 0.5)/mult))
  132. term.write("kRF/t")
  133. elseif e >= 1000000 and e < 1000000000 then
  134. term.write(string.format("%.0f", math.floor(e/1000000 * mult + 0.5)/mult))
  135. term.write("mRF/t")
  136. elseif e >= 1000000000 and e < 1000000000000 then
  137. term.write(string.format("%.0f", math.floor(e/1000000000 * mult + 0.5)/mult))
  138. term.write("gRF/t")
  139. else
  140. term.setCursorPos(center-2, 10)
  141. term.write("0RF/t")
  142. end
  143.  
  144.  
  145. --write transfer cap--
  146. term.setTextColor(colors.white)
  147. term.setCursorPos(center-5, 12)
  148. e = mD.tfCap
  149. if e >= 1000 and e < 1000000 then
  150. term.write(string.format("%.0f", math.floor(e/1000 * mult + 0.5)/mult))
  151. term.write("kRF/t")
  152. elseif e >= 1000000 and e < 1000000000 then
  153. term.write(string.format("%.0f", math.floor(e/1000000 * mult + 0.5)/mult))
  154. term.write("mRF/t")
  155. elseif e >= 1000000000 and e < 1000000000000 then
  156. term.write(string.format("%.0f", math.floor(e/1000000000 * mult + 0.5)/mult))
  157. term.write("gRF/t")
  158. else
  159. term.write(tostring(mD.tfCap))
  160. term.write("RF/t")
  161. end
  162.  
  163.  
  164. --write graph percentages--
  165. term.setCursorPos(10,14)
  166. print(charge.."%")
  167. term.setCursorPos(18,17)
  168. print(tUse.."%")
  169.  
  170.  
  171. --calculate graph fill--
  172. powBar = math.floor((mD.curPow/mD.maxPow)*(monX-2)+0.5)
  173. tBar = math.floor(((mD.curIn+mD.curOut)/mD.tfCap)*(monX-2)+0.5)
  174.  
  175.  
  176. --draw power bar--
  177. term.setBackgroundColor(colors.purple)
  178. term.setCursorPos(2,15)
  179. term.write(string.rep(" ",(monX-2)))
  180.  
  181. term.setBackgroundColor(colors.lime)
  182. term.setCursorPos(2,15)
  183. term.write(string.rep(" ",powBar))
  184.  
  185.  
  186. --draw transfer bar--
  187.  
  188. term.setBackgroundColor(colors.cyan)
  189. term.setCursorPos(2,18)
  190. term.write(string.rep(" ",(monX-2)))
  191.  
  192. term.setBackgroundColor(colors.red)
  193. term.setCursorPos(2,18)
  194. term.write(string.rep(" ",tBar))
  195.  
  196.  
  197. --reformat background--
  198. term.setBackgroundColor(colors.black)
  199.  
  200.  
  201. end
  202.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement