Advertisement
Muzze77

Animal_Gas_Control

May 16th, 2022 (edited)
989
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("ocs/apis/sensor")
  2. sen = sensor.wrap("top")
  3. mon = peripheral.wrap("back")
  4. mon.setCursorPos(1,1)
  5. mon.setBackgroundColor(colors.black)
  6. mon.clear()
  7. defCol = {colors.black,colors.white}
  8.  
  9.  
  10. gx,gy = mon.getSize()
  11.  
  12. mon.setTextScale(0.5)
  13.  
  14. function cmon(mx,my,text,bcol,tcol)
  15. if bcol == nil then
  16.   bcol = defCol[1]
  17. end
  18. if tcol == nil then
  19.   tcol = defCol[2]
  20. end
  21.  
  22. mon.setBackgroundColor(bcol)
  23. mon.setTextColor(tcol)
  24. mon.setCursorPos(mx,my)
  25. mon.write(text)
  26. mon.setBackgroundColor(defCol[1])
  27. mon.setTextColor(defCol[2])
  28.  
  29. end
  30.  
  31. function cPrint(text,count)
  32.    t = string.format("%" .. count .. "d",text)
  33.    return t
  34. end
  35. function cPrintS(text,count)
  36.   t = string.format("%-" .. count .. "s",text)
  37.    return t
  38. end
  39. fuel = {}
  40. water = {}
  41. steam = {}
  42. tmp = {}
  43. gWater = 4
  44. gFuel = 10
  45. gSteam = 16
  46. tankSize = 100
  47. function tanks(x,y)
  48.    
  49.     for v = -1,tankSize + 1,1 do
  50.         cmon(x+v,y," ",colors.white)
  51.         cmon(x+v,y+2," ",colors.white)
  52.     end
  53.     cmon(x-1,y+1," ",colors.white)
  54.     cmon(x+tankSize + 1,y+1," ",colors.white)
  55. end
  56.  
  57. function fillTank(amount,capacity,x,y,color)
  58.     percent = (100 / capacity * amount)
  59.     percentS = string.format("%d",percent)
  60.     percentR = tankSize / 100 * percentS
  61.    
  62.     for v = 0,percentR,1 do
  63.     cmon(x+v,y," ",colors.black)
  64.     end
  65.     for v = 0,percentR,1 do
  66.     cmon(x+v,y," ",color)
  67.     end
  68.    
  69. end
  70.  
  71.  
  72. while true do
  73.  
  74. s = sen.getTargets()
  75. tmp = {}
  76.  
  77. for v, k in pairs(s) do
  78.     if k.Name == "Iron Tank Wall" then
  79.     tmp = sen.getTargetDetails(v)
  80.     liquid = tmp.Tanks[1]
  81.         if liquid.Name == "Water" then
  82.             water = liquid
  83.             break
  84.         end
  85.     end
  86. end
  87.  
  88. for v, k in pairs(s) do
  89.     if k.Name == "Iron Tank Wall" then
  90.     tmp = sen.getTargetDetails(v)
  91.     liquid = tmp.Tanks[1]
  92.         if liquid.Name == "Animal Gas" then
  93.             fuel = liquid
  94.             break
  95.         end
  96.     end
  97. end
  98.  
  99. for v, k in pairs(s) do
  100.  
  101.     if k.Name == "Iron Tank Wall" then
  102.     tmp = sen.getTargetDetails(v)
  103.     liquid = tmp.Tanks[1]
  104.         if liquid.Name == "Steam" then
  105.             steam = liquid
  106.             break
  107.         end
  108.     end
  109. end
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. if fuel.Name == nil then
  118.     fuel.Name = "Animal Gas"
  119.     fuel.Amount = 0
  120.     fuel.Capacity = 0
  121. end
  122. if steam.Name == nil then
  123.     steam.Name = "Steam"
  124.     steam.Amount = 0
  125.     steam.Capacity = 0
  126. end
  127. if water.Name == nil then
  128.     water.Name = "water"
  129.     water.Amount = 0
  130.     water.Capacity = 0
  131. end
  132.  
  133.  
  134. if fuel.Amount == nil then
  135.   fuel.Amount = 0
  136.   fuel.Capacity = 0
  137. end
  138. if water.Amount == nil then
  139.   water.Amount = 0
  140.   water.Capacity = 0
  141. end
  142. if steam.Amount == nil then
  143.   steam.Amount = 0
  144.   steam.Capacity = 0
  145. end
  146.  
  147.  
  148. waterP = 100 / water.Capacity * water.Amount
  149. fuelP = 100 / fuel.Capacity * fuel.Amount
  150. steamP = 100 / steam.Capacity * steam.Amount
  151.    
  152.  
  153.  
  154. cmon( 2,gWater,cPrintS(water.Name,8),nil,colors.white)
  155. cmon(10,gWater,cPrint(water.Amount,10) .. " | " .. cPrint(water.Capacity,10) .. " |  " .. cPrint(waterP,3) .."%")
  156.  
  157. cmon(2,gFuel,cPrintS(fuel.Name,8),nil,colors.white)
  158. cmon(10,gFuel,cPrint(fuel.Amount,10) .. " | " .. cPrint(fuel.Capacity,10) .. " |  " .. cPrint(fuelP,3).."%")
  159.  
  160. cmon( 2,gSteam,cPrintS(steam.Name,8),nil,colors.white)
  161. cmon(10,gSteam,cPrint(steam.Amount,10) .. " | " .. cPrint(steam.Capacity,10) .. " |  " .. cPrint(steamP,3).."%")
  162.  
  163. if waterP >= 50 then
  164.     cmon(2,gWater,cPrintS(water.Name,8),nil,colors.green)  
  165. else   
  166.     cmon(2,gWater,cPrintS(water.Name,8),nil,colors.red)
  167. end
  168.  
  169.  
  170. if fuelP >= 25 then
  171.     cmon(2,gFuel,cPrintS(fuel.Name,8),nil,colors.green)
  172. else   
  173.     cmon(2,gFuel,cPrintS(fuel.Name,8),nil,colors.red)  
  174. end
  175.  
  176. if steamP <= 25 then
  177.     cmon(2,gSteam,cPrintS(steam.Name,8),nil,colors.red)
  178.     oCol = rs.getBundledOutput("right")
  179.     col = colors.subtract(colors.white,oCol)
  180.     rs.setBundledOutput("right",col)
  181. else
  182.     oCol = rs.getBundledOutput("right")
  183.     col = colors.combine(colors.white,oCol)
  184.     rs.setBundledOutput("right",col)
  185.     cmon(2,gSteam,cPrintS(steam.Name,8),nil,colors.green)  
  186. end
  187.  
  188. bundled = rs.getBundledInput("right")
  189.  
  190.  
  191. if waterP >= 50 and fuelP >= 25 and steamP >= 25 then
  192.  cmon(2,2,"Engine Activated",nil,colors.green)
  193.  oCol = rs.getBundledOutput("right")
  194.  col = colors.combine(colors.blue,colors.green,oCol)
  195.  rs.setBundledOutput("right",col)
  196. else
  197.  cmon(2,2,"Engine Deactivated",nil,colors.red)
  198.  oCol = rs.getBundledOutput("right")
  199.  col = colors.subtract(colors.blue,colors.green,oCol)
  200.  rs.setBundledOutput("right",col)
  201.  
  202. end
  203.  
  204. tanks(4,gWater + 2)
  205. tanks(4,gFuel + 2 )
  206. tanks(4,gSteam + 2)
  207.  
  208. fillTank(water.Amount,water.Capacity,4,gWater+3,colors.blue)
  209. fillTank(fuel.Amount,fuel.Capacity,4,gFuel+3,colors.green)
  210. fillTank(steam.Amount,steam.Capacity,4,gSteam+3,colors.gray)
  211.  
  212. sleep(1)
  213.  
  214. shell.run("clear")
  215. end
  216.  
Advertisement
RAW Paste Data Copied
Advertisement