Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = "1.0"
- local results = {}
- local sides = peripheral.getNames()
- local modem
- local data
- if not term.isColor or not term.isColor() then
- error("FoF v"..version.." Requires an Advanced (gold) Computer!")
- end
- function splitString(inputstr, sep)
- if(sep == nil) then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function clearTable(tab)
- if(tab ~= nil) then
- for k in pairs (tab) do
- tab [k] = nil
- end
- end
- end
- if(fs.exists("fof.config") == false) then
- term.clear()
- term.setCursorPos(1, 1)
- print("Welchome to the Friends or Foe scanning System Setup")
- print("Thanks for your trust in Lupus Space Industries")
- print("Enter Ship Name: ")
- shipName = read()
- print("Enter Ship Owner: ")
- shipOwner = read()
- print("Enter Faction: ")
- shipFaction = read()
- file = fs.open("fof.config", "w")
- data = shipName..":"..shipOwner..":"..shipFaction
- file.write(data)
- file.close()
- else
- file = fs.open("fof.config", "r")
- data = file.readLine()
- file.close()
- end
- for _, side in pairs(sides) do
- if peripheral.getType(side) == "modem" then
- print("Wrapping "..side)
- modem = peripheral.wrap(side)
- rednet.open(side)
- end
- end
- if(modem == nil) then
- error("FoF v"..version.." Requires an Modem!")
- end
- function interface()
- local isRunning = true
- while isRunning do
- term.clear()
- term.setCursorPos(1, 1)
- print("Welchome to the Friends or Foe scanning System v"..version.." from Lupus Space Industries\n")
- table.foreach(results, print)
- print("\n\n")
- print("Press S to Scan neaby ships")
- local params = {os.pullEventRaw()}
- local eventName = params[1]
- if(eventName == "modem_message") then
- if(params[5].message ~= nil) then
- local messages = splitString(params[5].message, ":")
- if(string.match(messages[1], "ping")) then
- os.sleep(1)
- os.sleep(1)
- if(params[6] <= 64) then
- rednet.send(params[4], "pong:"..data)
- end
- end
- if(string.match(messages[1], "pong")) then
- if(params[6] <= 64) then
- table.insert(results, "Shipname: "..messages[2].."\n Owner: "..messages[3].."\n Faction: "..messages[4].."\n Distance: "..params[6])
- interface()
- end
- end
- end
- elseif(eventName == "key") then
- if(params[2] == 31) then
- rednet.broadcast("ping")
- clearTable(results)
- else
- print("Wrong Key, try S for Scan")
- end
- end
- os.sleep(1)
- end
- end
- interface()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement