Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Program created by Skip_21
- -- Require Advancedperipherals
- version = "alpha 0.1"
- knownprotocols = {"dns", "matrix"}
- -- Defining resolution values
- x = 1600
- y = 900
- icons = {}
- function readablenumber(n)
- if n >= 10000000000000000 then
- return "" .. (math.floor((n / 1000000000000000) + 0.5)) .. " P"
- end
- if n >= 1000000000000000 then
- return "" .. (math.floor((n / 100000000000000) + 0.5) / 10) .. " P"
- end
- if n >= 10000000000000 then
- return "" .. (math.floor((n / 1000000000000) + 0.5)) .. " T"
- end
- if n >= 1000000000000 then
- return "" .. (math.floor((n / 100000000000) + 0.5) / 10) .. " T"
- end
- 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 searchlist(searchfor, list)
- for i = 1, #list do
- if list[i] == searchfor then
- return true
- end
- end
- return false
- end
- function netevent(p1, p2, p3)
- local sender = p1
- local message = p2
- local protocol = p3
- if not searchlist(protocol, knownprotocols) then
- return
- end
- if protocol == "dns" then
- print("Received handshake request from client " .. sender)
- elseif protocol == "matrix" then
- local estor = message[2]/2.5
- local emax = message[1]/2.5
- local ein = message[3]/2.5
- local eout = message[4]/2.5
- local percent = message[5]
- ant.fillGradientWithId("energybar", 2, 10, 32, 110, 0x00FF00, 0xFF0000)
- ant.fillWithId("energyhide", 2, 10, 32, (110-percent), 0x000000)
- ant.drawStringWithId("estor", ("Energy Stored : " .. readablenumber(estor) .. "RF"), 33, 10, 0xFFFFFF)
- ant.drawStringWithId("emax", ("Maximum Capacity : " .. readablenumber(emax) .. "RF"), 33, 20, 0xFFFFFF)
- ant.drawStringWithId("ein", ("Energy Input : " .. readablenumber(ein) .. "RF/t"), 33, 30, 0xFFFFFF)
- ant.drawStringWithId("eout", ("Energy Output : " .. readablenumber(eout) .. "RF/t"), 33, 40, 0xFFFFFF)
- end
- return
- 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)
- end
- end
- -- Init
- term.clear()
- term.setCursorPos(1, 1)
- print("Skip_21's Smart Helmet " .. version .. " running !")
- print("I'm still working on it so expect a lot of bugs")
- if (os.getComputerLabel() == nil) then
- print("Setting computer label to 'ARServer'.")
- os.setComputerLabel("ARServer")
- end
- sides = peripheral.getNames()
- antennahere = false
- chatboxhere = false
- modemhere = false
- for i = 1, #sides do
- thistype = peripheral.getType(sides[i])
- if thistype == "arController" then
- print("AR Controller 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 AR Controller from Advanced Peripherals mod")
- end
- if not chatboxhere then
- error("Please connect a chatbox from Advanced Peripherals mod")
- end
- if not modemhere then
- error("Please connect a Wireless Modem")
- end
- rednet.host("arserver", "arserver")
- print("Running ...")
- ant.clear()
- ant.setRelativeMode(true, x, y)
- -- main loop
- while true do
- eventlistener()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement