Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Program created by Skip_21
- -- Require PeripheralsPlusOne
- -- Added multiple players handling
- version = "alpha 1.5"
- knownprotocols = {"handshake","reactor","matrix","IDSU", "ic2"}
- icons = {}
- function readablenumber(n)
- if n >= 10000000000 then return ""..(math.floor((n/1000000000)+0.5)).." G" end
- if n >= 1000000000 then return ""..(math.floor((n/100000000)+0.5)/10).." G" end
- if n >= 10000000 then return ""..(math.floor((n/1000000)+0.5)).." M" end
- if n >= 1000000 then return ""..(math.floor((n/100000)+0.5)/10).." M" end
- if n >= 10000 then return ""..(math.floor((n/1000)+0.5)).." k" end
- if n >= 1000 then return ""..(math.floor((n/100)+0.5)/10).." k" end
- if n >= 100 then return ""..math.floor((n)+0.5).." " end
- return ""..(math.floor((n*10)+0.5)/10).." "
- end
- function guiConfig()
- print("Test")
- end
- function searchlist(searchfor,list)
- for i=1,#list do
- if list[i]==searchfor then return true end
- end
- return false
- end
- function mysplit(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function netevent(p1, p2, p3)
- hud.clear()
- hud.sync()
- sender = p1
- message = p2
- protocol = p3
- psplit = mysplit(protocol,"/")
- protocol = psplit[1]
- if not searchlist(protocol,knownprotocols) then return end
- pid = psplit[2]
- if protocol=="handshake" then
- print("Received handshake request from client "..sender)
- return
- end
- if protocol == "reactor" then
- reactor(message)
- end
- if protocol == "matrix" then
- matrix(message)
- end
- if protocol == "IDSU" then
- idsu(message)
- end
- if protocol == "ic2" then
- ic2(message)
- end
- end
- function reactor(n)
- draw(5, (y-215), 35, (y-115), green, red)
- if n[7] < 100 then
- draw(5, (y-215), 35, (y-115-n[7]), black, black)
- end
- writings(("Energy Stored : " .. readablenumber(n[1]) .. "RF"), 40, (y-215))
- writings(("Maximum Capacity : " .. readablenumber(n[2]) .. "RF"), 40, (y-205))
- writings(("Energy Production : " .. readablenumber(n[3]) .. "RF/t"), 40, (y-195))
- writings(("Casing Heat : " .. n[4] .. "°C"), 40, (y-185))
- writings(("Fuel Consumption : " .. n[5] .. "mb/t"), 40, (y-175))
- writings(("Rod Insertion Level : " .. n[6] .. "%"), 40, (y-165))
- hud.add()
- end
- function matrix(n)
- local percent = (n[2]/n[1])*100
- draw(5, (y-105), 35, (y-5), green, red)
- if percent < 100 then
- draw(5, (y-105), 35, (y-5-percent), black, black)
- end
- local estor = n[2]
- local emax = n[1]
- local ein = n[3]
- local eout = n[4]
- writings(("Energy Stored : " .. readablenumber(estor) .. "J"), 40, (y-105))
- writings(("Maximum Capacity : " .. readablenumber(emax) .. "J"), 40, (y-95))
- writings(("Energy Input : " .. readablenumber(ein) .. "J/t"), 40, (y-85))
- writings(("Energy Output : " .. readablenumber(eout) .. "J/t"), 40, (y-75))
- hud.add()
- end
- function idsu(n)
- local percent = (n[2]/n[1])*100
- draw(5, (y-325), 35, (y-225), green, red)
- if percent < 100 then
- draw(5, (y-325), 35, (y-225-percent), black, black)
- end
- local estor = n[2]
- local emax = n[1]
- writings(("Energy Stored : " .. readablenumber(estor) .. "EU"), 40, (y-325))
- writings(("Maximum Capacity : " .. readablenumber(emax) .. "EU"), 40, (y-315))
- hud.add()
- end
- function ic2(n)
- local percent = (n[2]/n[1])*100
- draw(5, (y-325), 35, (y-225), green, red)
- if percent < 100 then
- draw(5, (y-325), 35, (y-225-percent), black, black)
- end
- local estor = n[2]
- local emax = n[1]
- writings(("Energy Stored : " .. readablenumber(estor) .. "EU"), 40, (y-325))
- writings(("Maximum Capacity : " .. readablenumber(emax) .. "EU"), 40, (y-315))
- hud.add()
- end
- function draw(a, b, c, d, e, f)
- hud.drawRectangle(a, b, c, d, e, f)
- end
- function writings(txt, x, y)
- hud.drawString(txt, x, y)
- end
- function chatcommand(player, command)
- for i = 1, #ant.getPlayers() do
- if player == ant.getPlayers()[i] then
- if command[1] == "open" then
- guiConfig()
- elseif command[1] == "reboot" then
- rednet.broadcast(command, "shserver")
- rednet.close(modemside)
- os.reboot()
- elseif command[1] == "br" then
- if command[2] == nil then
- chb.tell(players[1], "Correct Usage : br on/off")
- elseif command[2] == "on" then
- rednet.broadcast(command, "shserver")
- elseif command[2] == "off" then
- rednet.broadcast(command, "shserver")
- end
- elseif command[1] == "help" then
- chb.tell(player, "List of commands : \nbr on/off - Turns ExtremeReactors on or off \nopen - Turns on your GUI \nreboot - Reboot the SH server and clients")
- end
- end
- end
- end
- function max(a,b)
- if a>b then
- return a
- else
- return b
- end
- end
- function eventlistener()
- local event, p1, p2, p3 = os.pullEvent()
- if event == "rednet_message" then netevent(p1, p2, p3)
- elseif event == "command" then
- chatcommand(p1, p2)
- end
- end
- -- Init
- term.clear()
- term.setCursorPos(1,1)
- print("Skip_21's Smart Helmet "..version.." running !")
- if (os.getComputerLabel()==nil) then
- print("Setting computer label to 'SHServer'.")
- os.setComputerLabel("SHServer")
- end
- sides = peripheral.getNames()
- antennahere = false
- chatboxhere = false
- modemhere = false
- for i = 1, #sides do
- thistype = peripheral.getType(sides[i])
- if thistype == "antenna" then
- print("Antenna found on " .. sides[i] .. ", connecting...")
- ant = peripheral.wrap(sides[i])
- antennahere = true
- end
- if thistype == "chatBox" then
- print("ChatBox found on " .. sides[i] .. ", connecting...")
- chb = peripheral.wrap(sides[i])
- chatboxhere = true
- end
- if thistype == "modem" then
- print("Modem found on " .. sides[i] .. ", connecting...")
- rednet.open(sides[i])
- modemside = sides[i]
- modemhere = true
- end
- end
- if not antennahere then error("Please connect an antenna from PeripheralsPlusOne mod") end
- if not chatboxhere then error("Please connect a chatbox from PeripheralsPlusOne mod") end
- if not modemhere then error("Please connect a Wireless Modem") end
- rednet.host("shserver","shserver")
- print("Running ...")
- players = ant.getPlayers()
- hud = ant.getHUD(players[1])
- x,y = hud.getResolution()
- gui = hud.getGUI(players[1])
- red = hud.getColorFromRGB(255,0,0)
- green = hud.getColorFromRGB(0,255,0)
- black = hud.getColorFromRGB(0,0,0)
- hud.clear()
- -- main loop
- while true do
- eventlistener()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement