Advertisement
Sparkybearbomb

Essentials API

Nov 5th, 2016 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.04 KB | None | 0 0
  1. -- Essential Functions API list
  2. -- integrate using os.loadAPI("file-name-here")
  3.  
  4. function monitorSearch()
  5.    local names = peripheral.getNames()
  6.    local i, name
  7.    for i, name in pairs(names) do
  8.       if peripheral.getType(name) == "monitor" then
  9.         test = name
  10.          return peripheral.wrap(name)
  11.       else
  12.          --return null
  13.       end
  14.    end
  15. end
  16.  
  17. function bigReactorSearch()
  18.    local names = peripheral.getNames()
  19.    local i, name
  20.    for i, name in pairs(names) do
  21.       if peripheral.getType(name) == "BigReactors-Reactor" then
  22.          print("reactor")
  23.          return peripheral.wrap(name)
  24.       else
  25.          --return null
  26.       end
  27.    end
  28. end
  29.  
  30. function mekanismMachineSearch()
  31.    local names = peripheral.getNames()
  32.    local i, name
  33.    for i, name in pairs(names) do
  34.       if peripheral.getType(name) == "mekanism_machine" then
  35.         test = name
  36.          return peripheral.wrap(name)
  37.       else
  38.          --return null
  39.       end
  40.    end
  41. end
  42.  
  43. function modemSearch()
  44.    local names = peripheral.getNames()
  45.    local i,  name
  46.    for i,  name in pairs(names) do
  47.       if peripheral.getType(name) == "modem" then
  48.         test = name
  49.          return peripheral.wrap(name)
  50.       else
  51.          --return null
  52.       end
  53.    end
  54. end
  55.  
  56. function clear()
  57.   mon = monitorSearch()
  58.   mon.setBackgroundColor(colors.black)
  59.   mon.clear()
  60.   mon.setCursorPos(1,1)
  61. end
  62.  
  63. --display text on computer's terminal screen
  64. function draw_text_term(x, y, text, text_color, bg_color)
  65.   term.setTextColor(text_color)
  66.   term.setBackgroundColor(bg_color)
  67.   term.setCursorPos(x,y)
  68.   write(text)
  69. end
  70.  
  71. --display text text on monitor, "mon" peripheral
  72. function draw_text(x, y, text, text_color, bg_color)
  73.   mon = monitorSearch()
  74.   mon.setBackgroundColor(bg_color)
  75.   mon.setTextColor(text_color)
  76.   mon.setCursorPos(x,y)
  77.   mon.write(text)
  78. end
  79.  
  80. --draw line on computer terminal
  81. function draw_line(x, y, length, color)
  82.     mon = monitorSearch()
  83.     mon.setBackgroundColor(color)
  84.     mon.setCursorPos(x,y)
  85.     mon.write(string.rep(" ", length))
  86. end
  87.  
  88. --draw line on computer terminal
  89. function draw_line_term(x, y, length, color)
  90.     term.setBackgroundColor(color)
  91.     term.setCursorPos(x,y)
  92.     term.write(string.rep(" ", length))
  93. end
  94.  
  95. -- Round Decimal Numbers
  96. function roundNumber(num, n)
  97.   local mult = 10^(n or 0)
  98.   return math.floor(num * mult + 0.5) / mult
  99. end
  100.  
  101. --create progress bar
  102. --draws two overlapping lines
  103. --background line of bg_color
  104. --main line of bar_color as a percentage of minVal/maxVal
  105. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  106.   draw_line(x, y, length, bg_color) --backgoround bar
  107.   local barSize = math.floor((minVal/maxVal) * length)
  108.   draw_line(x, y, barSize, bar_color) --progress so far
  109. end
  110.  
  111. --create status bar
  112. --draws three overlapping lines
  113. --background line of bg_color
  114. function status_bar(x, y, length, minVal, medVal, maxVal, bar_color1, bar_color2, bg_color)
  115.   draw_line(x, y, length, bg_color) --backgoround bar
  116.   local barSize1 = math.floor((medVal/maxVal) * length)
  117.   local barSize2 = math.floor((minVal/maxVal) * length)
  118.   draw_line(x, y, barSize1, bar_color1) --progress so far
  119.   draw_line(x, y, barSize2, bar_color2) --progress so far
  120. end
  121.  
  122. --same as above but on the computer terminal
  123. function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  124.   draw_line_term(x, y, length, bg_color) --backgoround bar
  125.   local barSize = math.floor((minVal/maxVal) * length)
  126.   draw_line_term(x, y, barSize, bar_color)  --progress so far
  127. end
  128.  
  129. --create button on monitor
  130. function button(x, y, length, text, txt_color, bg_color)
  131.   draw_line(x, y, length, bg_color)
  132.   draw_text((x+2), y, text, txt_color, bg_color)
  133. end
  134.  
  135. function heading(text)
  136.    mon = monitorSearch()
  137.    w, h = mon.getSize()
  138.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  139.    mon.write(text)
  140. end
  141.      
  142. function label(w, h, text, size, colour)
  143.    mon = monitorSearch()
  144.    mon.setCursorPos(w, h)
  145.    mon.setTextScale(size)
  146.    mon.setTextColor(colour)
  147.    mon.write(text)
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement