- As i always say, my english isn't perfect, i'm french, please don't blame me <3
- You can reuse anything i did, but please, just say in your post when you do ^^
- I'm new in Lua (i know CC since july 2012 … but didn't expect that was so funny till i found something to do ^^)
- I'm not a programmer or whatever in real life
So now …
"NUP", this weird name come from someone on my server (ultimate pack) who said (dixit): "Neekow, j'ai besoin de ton utilitaire" ("Neekow, i need you utility", if i'm not wrong). So i just take it and create my first real programs under the name of "Neekow Utility Program".
So NUP is a program for people who want play with sensor cards and reader, but don't know a bit in Lua (like every player on my server ^^), i want to do something what they just need to do "pastebin get blablabla" and they have the whole programs ready to use, easy to configurate, easy to understand … sort of advanded nuclear panel for who wants it ;)/>.
My own code is separated by some things, like every colors are at top, batboxes, MFEs and other are called "storage" … i won't list every thing, but if you don't understand something, ask me ;)/>
For Storage: Amps = EUs in the MFSu, Flux = Input-Output. As the bar is calculated with percentage, you will see the "Flux" with Batboxes, MFEs, MFSUs ;)/>
For Reactors: need to explain? ^^. Ya, a little thing you will find in my code: MaxAdmissibleHeat, this is 40% of the max heat, so if the right is all red, problems will come, under the max, everythings is ok. And as you can notice, there's "Test", this is the name of the card ;)/>
(Note: i just inverted the greens, now when time is full, it's lime, when 5% passed, it's green)
Before the code and pastebin, what NUP does at the moment:
- Wrap peripherals whatever their side, but if you break reader or monitor, it will stop. But you can change the card without any problems
- Works for Reactor and Storage, no tank now …
- Have beautifull customizable colors (just change in the head) and beautifull bars(?) but you cant change the color of them easly.
- Have a display error on the Reactor's Output when it on then off …
Pastebin
Spoiler
--- couleurs ---
--- couleurs des cadres ---
couleurCadreBase = colors.blue
couleurCadrePassword = colors.lime
--- couleurs des boutons password ---
couleurButtonPassNum = colors.gray
couleurButtonPassVal = colors.lime
couleurButtonPassCor = colors.red
--- couleurs des titres page principale ---
couleurTitrePage = colors.lightGray
couleurCarPage = colors.lightGray
couleurCarVar = colors.gray
--- initialisation fonctions ---
--- fonction peripherals --
mon = nil
monSide = nil
reader = nil
readerSide = nil
card = nil
--- fonction page principale ---
PagePrin = nil
--- fonction barre nucleaire ---
timeb = 10000
--- fonction barre storage ---
Stor1 = 0
Stor2 = 0
--- fonctions ---
function peripherals()
for i, side in pairs(rs.getSides()) do
if peripheral.getType(side) == "monitor" then
mon = peripheral.wrap(side)
monSide = side
end
if peripheral.getType(side) == "nuclearReader" then
reader = peripheral.wrap(side)
readerSide = side
end
if reader ~= nil then
uid,state,title,data= reader.get(1)
if data == nil then
sleep(1)
peripherals()
else
for i,j in pairs(data) do
if i == "liquidMeta" then card = 0 end
if i == "heat" then card = 1 end
if i == "energyL" then card = 2 end
end
end
end
end
end
function cadreBase()
local cadreBase = {
' _______ _______ ',
'| || |',
'| ____||____ |',
'| | | |',
'| |__________| |',
'| | | |',
'| | | |',
'| | | |',
'| | | |',
'| |____ ____| |',
'| | || | |',
'|__|____||____|__|'}
for i = 1, #cadreBase do
mon.setTextColor(couleurCadreBase)
mon.setCursorPos(1,i)
mon.write(cadreBase[i])
end
end
function cadrePassword()
local x = 0
local cadrePassord = {
'| || || || |',
'|_||_||_||_|',
'| || || || |',
'|_||_||_||_|',
' | || | ',
' _|_||_|_',
'| || |',
'|___||___|'}
for i = 1, #cadrePassword do
if i<5 then x = 0 else x = 1 end
mon.setTextColor(couleurPassword)
mon.setCursorPos(4+x,i+3)
mon.write(cadrePassword[i])
end
mon.setCursorPos(9,12)
mon.setTextColor(couleurCadreBase)
mon.write("__")
end
function buttonPassword()
-- numButton, name, PosX, PosY, Couleur, Xmax
buttonsPassword={
{1 ,"1" ,5 ,4 ,couleurButtonPassNum ,5 },
{2 ,"2" ,8 ,4 ,couleurButtonPassNum ,8 },
{3 ,"3" ,11 ,4 ,couleurButtonPassNum ,11},
{4 ,"4" ,14 ,4 ,couleurButtonPassNum ,14},
{5 ,"5" ,5 ,6 ,couleurButtonPassNum ,5 },
{6 ,"6" ,8 ,6 ,couleurButtonPassNum ,8 },
{7 ,"7" ,11 ,6 ,couleurButtonPassNum ,11},
{8 ,"8" ,14 ,6 ,couleurButtonPassNum ,14},
{9 ,"9" ,8 ,8 ,couleurButtonPassNum ,8 },
{10,"0" ,11 ,8 ,couleurButtonPassNum ,11},
{11,"Val" ,6 ,10 ,couleurButtonPassVal ,8 },
{12,"Cor" ,11 ,10 ,couleurButtonPassCor ,13}}
for n,buttonP in ipairs(buttonsPassword) do
mon.setCursorPos(buttonP[3],buttonP[4])
mon.setTextColor(buttonP[5])
-----------------------------------------------------------------------mettre le changement "Cor">"Ret" si le pin == nil
mon.write(buttonP[2])
end
end
function buttonPagePrin()
datas()
if card == 2 then
datas()
if tonumber(tostring(data["maxStorageL"])) == 10000000 then
typestorage = " MFSu "
storageOutput = " 512 "
end
if tonumber(tostring(data["maxStorageL"])) == 600000 then
typestorage = " MFE "
storageOutput = " 128 "
end
if tonumber(tostring(data["maxStorageL"])) == 40000 then
typestorage = " Bat Box "
storageOutput = " 32 "
end
else
typestorage = " "
storageOutput = " "
end
-- nameTank, nameReactor, nameStorage PosX, PosY, couleur
buttonsPagePrin={
{"Flux","Time","Flux",5,2,couleurTitrePage},
{"Tank","Heat","Amps",11,2,couleurTitrePage},
{title,title,title,5,4,couleurTitrePage},
{" Type "," Max Heat "," Type ",5,6,couleurCarPage},
{typetank," "..maxHeat,typestorage,5,7,couleurCarVar},
{" Capacity "," Output "," Output ",5,8,couleurCarPage},
{capaTank," "..output,storageOutput,5,9,couleurCarVar}
}
for n,buttonPage in ipairs(buttonsPagePrin) do
mon.setCursorPos(buttonPage[4],buttonPage[5])
mon.setTextColor(buttonPage[6])
mon.write(buttonPage[1+card])
end
end
function datas()
uid, state, title, data = reader.get(1)
if state== "OK" then
if card == 0 then
liquideMeta = tostring(data["liquidMeta"])
capacity = tostring(data["capacity"])
liquidId = tostring(data["liquidId"])
amount = tostring(data["amount"])
heat = 0
isSteam = 0
reactorPoweredB = 0
maxHeat = 0
timeLeft = 0
output = 0
maxAdmissibleHeat = 0
energyL = 0
maxStorageL = 0
end
if card == 1 then
liquideMeta = 0
capacity = 0
liquidId = 0
amount = 0
heat = tostring(data["heat"])
isSteam = tostring(data["isSteam"])
reactorPoweredB = tostring(data["reactorPoweredB"])
maxHeat = tostring(data["maxHeat"])
timeLeft = tostring(data["timeLeft"])
output = tostring(data["output"])
maxAdmissibleHeat = (maxHeat/100*40)
energyL = 0
maxStorageL = 0
end
if card == 2 then
liquideMeta = 0
capacity = 0
liquidId = 0
amount = 0
heat = 0
isSteam = 0
reactorPoweredB = 0
maxHeat = 0
timeLeft = 0
output = 0
maxAdmissibleHeat = 0
energyL = tostring(data["energyL"])
maxStorageL = tostring(data["maxStorageL"])
end
else
peripherals()
end
end
--- fonctions barres --
function Barres()
if card == 0 then print("tralala")
end
if card == 1 then
barreTime()
barreHeat()
end
if card == 2 then print("tralala")
barreStorage()
barreStorageFlux()
end
end
function barreTime()
if tonumber(timeLeft) > 0 then
for i = 1,20 do
if 100*timeLeft/timeb > math.abs(i-21)*5 then
mon.setCursorPos(2,math.ceil(i/2)+1)
mon.setTextColor(colors.lime)
mon.setBackgroundColor(colors.lime)
mon.write("##")
else
if 100*timeLeft/timeb < math.abs(i-21)*5 and 100*timeLeft/timeb > math.abs(i-20)*5 then
mon.setCursorPos(2,math.ceil(i/2)+1)
mon.setTextColor(colors.green)
mon.setBackgroundColor(colors.green)
mon.write("##")
else
mon.setCursorPos(2,math.ceil(i/2)+1)
mon.setTextColor(colors.black)
mon.setBackgroundColor(colors.black)
mon.write(" ")
end
end
end
end
mon.setBackgroundColor(colors.black)
end
function barreHeat()
for i = 1,20 do
if math.abs(i-21)*maxAdmissibleHeat/20 < tonumber(heat) and math.abs(i-22)*maxAdmissibleHeat/20 > tonumber(heat) then
mon.setCursorPos(16,math.ceil(i/2)+1)
mon.setTextColor(colors.orange)
mon.setBackgroundColor(colors.orange)
mon.write("##")
else
if math.abs(i-21)*maxAdmissibleHeat/20 < tonumber(heat) and math.abs(i-22)*maxAdmissibleHeat/20 < tonumber(heat) then
mon.setCursorPos(16,math.ceil(i/2)+1)
mon.setTextColor(colors.red)
mon.setBackgroundColor(colors.red)
mon.write("##")
else
mon.setCursorPos(16,math.ceil(i/2)+1)
mon.setTextColor(colors.black)
mon.setBackgroundColor(colors.black)
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.black)
end
function barreStorage()
for i = 1,20 do
if energyL/maxStorageL*100 > math.abs(i-21)*5 and energyL/maxStorageL*100 < math.abs(i-22)*5 then
mon.setCursorPos(16,math.ceil(i/2)+1)
mon.setTextColor(colors.lightBlue)
mon.setBackgroundColor(colors.lightBlue)
mon.write("##")
else
if energyL/maxStorageL*100 >= math.abs(i-21)*5 and energyL/maxStorageL*100 >= math.abs(i-22)*5 then
mon.setCursorPos(16,math.ceil(i/2)+1)
mon.setTextColor(colors.cyan)
mon.setBackgroundColor(colors.cyan)
mon.write("##")
else
mon.setCursorPos(16,math.ceil(i/2)+1)
mon.setTextColor(colors.black)
mon.setBackgroundColor(colors.black)
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.black)
end
function barreStorageFlux()
if tonumber(maxStorageL) == 10000000 then storOutput = 512 end
if tonumber(maxStorageL) == 600000 then storOutput = 128 end
if tonumber(maxStorageL) == 40000 then storOutput = 32 end
Stor2 = tonumber(energyL)
PercStor = (Stor2-Stor1)/20
PercStorOutput = ((PercStor/storOutput)*100)
--- flux positif
for i = 1,10 do
if PercStorOutput > 0 and PercStorOutput > math.abs(i-11)*10 and PercStorOutput < math.abs(i-12)*10 then
mon.setCursorPos(2,math.ceil(i/2)+1)
mon.setTextColor(colors.lime)
mon.setBackgroundColor(colors.lime)
mon.write("##")
else
if PercStorOutput > 0 and PercStorOutput > math.abs(i-11)*10 and PercStorOutput > math.abs(i-12)*10 then
mon.setCursorPos(2,math.ceil(i/2)+1)
mon.setTextColor(colors.green)
mon.setBackgroundColor(colors.green)
mon.write("##")
else
mon.setCursorPos(2,math.ceil(i/2)+1)
mon.setTextColor(colors.black)
mon.setBackgroundColor(colors.black)
mon.write(" ")
end
end
end
--- flux negatif
for i = 1,10 do
if PercStorOutput < 0 and math.abs(PercStorOutput) > i*10 and math.abs(PercStorOutput) < (i+1)*10 then
mon.setCursorPos(2,math.ceil(i/2)+6)
mon.setTextColor(colors.orange)
mon.setBackgroundColor(colors.orange)
mon.write("##")
else
if PercStorOutput < 0 and math.abs(PercStorOutput) > i*10 and math.abs(PercStorOutput) > (i+1)*10 then
mon.setCursorPos(2,math.ceil(i/2)+6)
mon.setTextColor(colors.red)
mon.setBackgroundColor(colors.red)
mon.write("##")
else
mon.setCursorPos(2,math.ceil(i/2)+6)
mon.setTextColor(colors.black)
mon.setBackgroundColor(colors.black)
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.black)
Stor1 = Stor2
end
--- Programme ---
peripherals()
cadreBase()
while true do
peripherals()
datas()
buttonPagePrin()
Barres()
sleep(1)
end
What the program should do (in future versions):
- Correct the "Output" of reactor when it falls at 0
- Get monitor, reader and sensor card, whatever their side/kind, don't bug if one is removed.
- Adjust tables if there's more than 2*2 monitor, do a configurable option.
- Implement the Password option.
- Extend to GregTech sensor card.
- Add "on/off" for nuclear reactor, "1/2" for storage to choose circuits you want to connect, don't know now what i wanna do for tanks.
- Find a way to get the lenght of words to automaticly put it in the center
- The programs causes some lags for low computer, so i'll cut it in some parts, think one part by kind of card + the main.
Hope you will enjoy and feedback =)
[right]phew, for a 4 or 5th post … long one![/right]