Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
-- Basic little control program for a passively cooled reactor. This program would not be possible, even in the primitive state it is now, without the inspiration and coding support of lolmer and ScatmanJohn. Will passively detect a reactor and a monitor, either through direct proximity or a wired modem. Please ensure the computer and monitors are the advanced version (it's just gold, not exactly rare in Minecraft), and that the monitor is a 3x2. local progVer = "1.06" local progName = "IC_SimpleNuke" local loopTime = 0.5 -- Time between program loops, in seconds. Increase this value if program somehow causes a lot of lag. Which should not happen on any computers made this century local baseControlRodLevel = 20 -- Put this as close to what you guess the optimum control rod level will be for your reactor, plus a little more local minStoredEnergyPercent = 20 -- Min energy % to store before activating, probably keep it at default (20) local maxStoredEnergyPercent = 60 -- Max energy % to store before shutdown, probably keep it at default (70) -- This program doesn't care about heat anymore, only tried to maintain the internal power buffer, following 2 lines only included for legacy local minReactorTemp = 20 -- Minimum reactor temperature (^C) to maintain local maxReactorTemp = 400 -- Maximum reactor temperature (^C) to maintain ---------- -- Basic side determination for wrapping function getDeviceSide(deviceType) deviceType = deviceType:lower() for i, side in pairs(rs.getSides()) do if (peripheral.isPresent(side)) then if (string.lower(peripheral.getType(side)) == deviceType) then return side; end end end return nil; end -- Peripheral wrapping function function wrapThis(thing, f) local wrapped = nil while wrapped == nil and f <= 100 do wrapped = peripheral.wrap(thing.."_"..f) f = f + 1 end if wrapped == nil then side = getDeviceSide(thing) if side ~= nil then return peripheral.wrap(side) else return nil end else return wrapped end end print("Initializing program...",1,1); -- Initialize the monitor -- If it can't find a monitor, will wait 5 seconds then reboot -- This is needed for server restarts when the computer starts up before the modem does local monitor = wrapThis("monitor", 0) if monitor == nil then sleep(5) finished = true os.reboot() end local monitorx, monitory = monitor.getSize() if monitorx ~= 29 or monitory ~= 12 then print("Monitor is the wrong size! Needs to be 3x2.") sleep(5) finished = true os.reboot() end -- Connect to the big reactor peripheral -- If it can't find a reactor, will wait 5 seconds then reboot -- This is needed for server restarts when the computer starts up before the modem does local reactor = wrapThis("BigReactors-Reactor", 0) if reactor == nil then sleep(5) finished = true os.reboot() end -- Easyprint, saves program space elsewhere local function print(str, x, y) term.setCursorPos(x, y) term.write(str) end -- Move stuff to monitor if monitor then sleep(1) term.clear() term.setCursorPos(1,1) term.write("Display redirected to Monitor. Type r to reboot, or") term.setCursorPos(1,2) term.write("q to quit and return control to this terminal.") term.redirect(monitor) end -- Restore functions to computer terminal function restoreNativeTerminal() repeat term.restore() local w, h = term.getSize() until w == 51 and h == 19 end -- Draw some decorative lines function drawLines() term.setBackgroundColor(colors.black) paintutils.drawLine(1, 2, 29, 2, colors.lightBlue) paintutils.drawLine(1, 7, 29, 7, colors.lightBlue) term.setBackgroundColor(colors.black) end -- Just to make sure they're relatively high before the control program starts if reactor then sleep(1) reactor.setAllControlRodLevels(baseControlRodLevel) else sleep(5) finished = true os.reboot() end -- Draw stuff on the monitor local function drawInfo() statusstring = "Reactor status: " tempstring = "Temperature: " tempstring2 = "deg. C" powerstring = "Power Output: " powerstring2 = "RF/t" rodstring = "Control Rods: " rodstring2 = "%" monitor.setTextColor(colors.green) print(progName,5,1) monitor.setTextColor(colors.red) print("v",19,1) monitor.setTextColor(colors.green) print(progVer,20,1) monitor.setTextColor(colors.white) print(statusstring,1,3) if reactor.getActive() then monitor.setTextColor(colors.green) print(" online",23,3) else monitor.setTextColor(colors.red) print("offline",23,3) end monitor.setTextColor(colors.white) reactortemp = math.floor(reactor.getFuelTemperature()) print(tempstring,1,4) print(reactortemp,16,4) print(tempstring2,24,4) power = math.floor(reactor.getEnergyProducedLastTick()) print(powerstring,1,5) print(power,16,5) print(powerstring2,26,5) rods = reactor.getControlRodLevel(1) print(rodstring,1,6) print(rods,16,6) print(rodstring2,29,6) end -- Draw stuff on the bottom part of the monitor, power bar etc function drawBottomPart() reactivity = math.floor(reactor.getFuelReactivity()) paintutils.drawLine(2, 9, 28, 9, colors.gray) if reactivity > 400 then paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.red) elseif reactivity > 320 then paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.orange) elseif reactivity > 240 then paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.yellow) elseif reactivity > 160 then paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.green) elseif reactivity > 0 then paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.blue) end term.setBackgroundColor(colors.black) print("Fuel Reactivity:",1,8) print(reactivity,24,8) print("%",29,8) term.setBackgroundColor(colors.black) energystorage = reactor.getEnergyStored() storagepercent = math.floor(energystorage/10000000*100) paintutils.drawLine(2, 12, 28, 12, colors.gray) if storagepercent > 4 then paintutils.drawLine(2, 12, math.floor(26*storagepercent/100)+2, 12, colors.yellow) elseif storagepercent > 0 then paintutils.drawPixel(2,12,colors.yellow) end term.setBackgroundColor(colors.black) print("Internal buffer: ",1,11) print(storagepercent,24,11) print("%",29,11) term.setBackgroundColor(colors.black) end -- Controls the reactor, keeping it between configured temps and power storage function control() energystorage = reactor.getEnergyStored() reactortemp = math.floor(reactor.getFuelTemperature()) ediff = (maxStoredEnergyPercent - minStoredEnergyPercent)*100000 ediffper = ediff / 100 if energystorage > maxStoredEnergyPercent*100000 then reactor.setActive(false) reactor.setAllControlRodLevels(95) elseif energystorage < minStoredEnergyPercent*100000 then reactor.setActive(true) reactor.setAllControlRodLevels(5) elseif energystorage > minStoredEnergyPercent*100000 then reactor.setActive(true) blarg = energystorage - minStoredEnergyPercent*100000 blarg2 = math.floor(blarg/(ediffper+1)) reactor.setAllControlRodLevels(blarg2) end end -- Main program function main() while not finished do if reactor.getConnected() then drawLines() drawInfo() drawBottomPart() control() sleep(loopTime) end end end -- Event handler for exiting, editting and debugging function eventHandler() while not finished do event, arg1, arg2, arg3 = os.pullEvent() if event == "char" and not inManualMode then local ch = string.lower(arg1) if ch == "q" then finished = true elseif ch == "r" then finished = true os.reboot() end end end end while not finished do parallel.waitForAny(eventHandler, main) sleep(loopTime) end -- Returns control to the terminal if the program has an error or whatever term.clear() term.setCursorPos(1,1) restoreNativeTerminal() term.clear() term.setCursorPos(1,1)
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
18 hours ago | 0.16 KB
settings
18 hours ago | 0.10 KB
IT & AI
1 day ago | 1.62 KB
Stationeers - Sign Tags from Power Distributi...
HTML | 1 day ago | 2.00 KB
PM: Shopify Client Edits
1 day ago | 0.19 KB
PM: Shopify Assigning Design Task 2
1 day ago | 0.14 KB
PM: Shopify Assigning Design Task 1
1 day ago | 0.32 KB
Commodore Callback 8020
2 days ago | 0.18 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!