Advertisement
ebrobertson

Reactor Toolkit Mk1

Jun 2nd, 2023 (edited)
1,206
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.06 KB | Gaming | 0 0
  1. --[[
  2.    Extreme Reactors Utility Script Mk 1
  3.    Author: Evan Robertson
  4.    Created: 2023-06-02
  5.    Updated: 2023-06-02
  6.    A generic utility script to be used with Computer Craft / CC:Tweaked and Extreme Reactors
  7. ]]--
  8.  
  9. --[[
  10.    Globals
  11. ]]
  12.  
  13. local clock = os.clock
  14.  
  15. --[[
  16.    clearScreen
  17.    clears the computer's output
  18. ]]
  19. local function clearScrean()
  20.    for i=1,13 do
  21.       print("")
  22.    end
  23. end
  24.  
  25. local function displayMenu()
  26.    clearScrean()
  27.    print("Reactor Toolkit Mk1")
  28.    print("~~~~~")
  29.    print("WIP!")
  30.    print("~~~~~")
  31.    print("Please Choose an option:")
  32.    print("")
  33.    print("1. Monitor Mode")
  34.    print("")
  35.    print("Type help to view help menu or exit to quit")
  36. end -- function printMenu
  37.  
  38. local function displayHelpMenu()
  39.    clearScrean()
  40.    print("Reactor Toolkit Mk1")
  41.    print("~~~~~")
  42.    print("Choose an option to get help on:")
  43.    print("~~~~~")
  44.    print("Please Choose an option:")
  45.    print("")
  46.    print("1. Monitor Mode")
  47.    print("")
  48.    print("Enter exit to return to main menu")
  49. end -- function printHelpMenu
  50.  
  51. local function displayOptionHelp(option)
  52.    if option == nil then
  53.       print("invalid option!")
  54.       print("Press enter to return")
  55.       read()
  56.       return
  57.    end -- if nil or NaN
  58.  
  59.    if option == 1 then
  60.       clearScrean()
  61.       print("Monitor Mode: ")
  62.       print("~~~~~")
  63.       print("Attach to a reactor's computer port and the computer will monitor the reactor's energy storage.")
  64.       print("When storage is full, turns off the reactor to preserve fuel.")
  65.       print("WIP - Monitoring heat, fuel consumption levels, and compiling data so you can be more informed as to how to improve reactor efficiency.")
  66.       print("Press enter to return")
  67.       read()
  68.    end -- if option 1
  69.  
  70. end -- function displayOptionHelp
  71.  
  72. --[[
  73.    sleep
  74.    makes the program wait n number of seconds
  75. ]]
  76. local function pauseProg(n)  -- seconds
  77.   local t0 = clock()
  78.   while clock() - t0 <= n do end
  79. end -- function sleep
  80.  
  81. --[[
  82.    wrapReactor
  83.    Checks for a reactor peripheral and wraps it onto a global
  84.    returns the wrapped reactor or false if no reactor was found
  85. ]]
  86. local function wrapReactor()
  87.    local wrappedReactor
  88.    wrappedReactor = peripheral.wrap('back')
  89.    if peripheral.getType(wrappedReactor) == "BigReactors-Reactor" then
  90.       return wrappedReactor
  91.    end
  92.    wrappedReactor = peripheral.wrap('left')
  93.    if peripheral.getType(wrappedReactor) == "BigReactors-Reactor" then
  94.       return wrappedReactor
  95.    end
  96.    wrappedReactor = peripheral.wrap('right')
  97.    if peripheral.getType(wrappedReactor) == "BigReactors-Reactor" then
  98.       return wrappedReactor
  99.    end
  100.    wrappedReactor = peripheral.wrap('front')
  101.    if peripheral.getType(wrappedReactor) == "BigReactors-Reactor" then
  102.       return wrappedReactor
  103.    end
  104.    wrappedReactor = peripheral.wrap('top')
  105.    if peripheral.getType(wrappedReactor) == "BigReactors-Reactor" then
  106.       return wrappedReactor
  107.    end
  108.    wrappedReactor = peripheral.wrap('bottom')
  109.    if peripheral.getType(wrappedReactor) == "BigReactors-Reactor" then
  110.       return wrappedReactor
  111.    end
  112.    return false
  113. end -- function wrapReactor
  114.  
  115. --[[
  116.    monitorReactor
  117.    Monitors the reactor's fuel level, energy storage, and toggles the power on/off  
  118. ]]
  119. local function monitorReactor(reactor)
  120.  
  121.    local fuel
  122.    local maxFuel
  123.    local caseTemp
  124.    local energy
  125.    local maxEnergy
  126.    local energyStats
  127.    local fuelStats  
  128.    local isActive
  129.  
  130.    -- to turn on: reactor.setActive()
  131.    fuel        = reactor.getFuelAmount()
  132.    maxFuel     = reactor.getFuelAmountMax()
  133.    energy      = reactor.getEnergyStored()
  134.    maxEnergy   = reactor.getEnergyCapacity()
  135.    caseTemp    = reactor.getCasingTemperature()
  136.    energyStats = reactor.getEnergyStats()
  137.    fuelStats   = reactor.getFuelStats()
  138.    isActive    = reactor.getActive()
  139.  
  140.    if fuel == 0 then
  141.       print("Ran out of fuel!")
  142.       return
  143.    else
  144.       print("Fuel:",fuel)
  145.    end
  146.  
  147.    if energy < maxEnergy then
  148.       if not isActive then
  149.          reactor.setActive(true)
  150.       end
  151.    else
  152.       if isActive then
  153.          reactor.setActive(false)
  154.       end
  155.    end
  156.  
  157.    if isActive then print("Reactor Status: Powered on") else print("Reactor Status: Powered off") end
  158.  
  159.    pauseProg(5)
  160.    sleep(0)
  161.  
  162.    monitorReactor(reactor)
  163.  
  164. end -- monitorReactor
  165.  
  166. -- main program
  167.  
  168. local input
  169. local success
  170. input = ""
  171. while input ~= "exit" do
  172.    displayMenu()
  173.    input = read()
  174.    if input == "1" then
  175.       clearScrean()
  176.       success = wrapReactor()
  177.       if not success then
  178.          print("No reactor found! Ensure a Reactor Computer Port and a working reactor are connected to the computer.")
  179.          return
  180.       end
  181.       monitorReactor(success)
  182.       return
  183.    elseif input == "help" then
  184.       input = ""
  185.       while input ~= "exit" do
  186.          displayHelpMenu()  
  187.          input = read()
  188.          displayOptionHelp(input)
  189.       end      
  190.       input = ""
  191.    end
  192. end
  193.  
  194.  
  195. print("Program exit. Thank you for using Reactor Toolkit Mk1.")
  196.  
  197. --[[
  198.    for key, value in pairs(rea) do print(key) read() end
  199.  
  200. ]]
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement