Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ LanteaCraft ]]--
- --[[ and SGCraft ]]--
- --[[ Gate Buddy ]]--
- --[[ by Dog ]]--
- --[[ aka HydrantHunter ]]--
- --[[ pastebin 1U2XPPCw ]]--
- local gbVer = "1.5.02"
- --[[
- Tested with/requires:
- - Minecraft 1.7.10
- - LanteaCraft-1.7.10-70 || SGCraft 1.95-mc1.7.10
- - ComputerCraft 1.73, 1.74, 1.75
- - A computer (standard or advanced) with a wireless modem, or a wireless turtle (standard or advanced)
- - A stargate with a CC adapter
- ]]--
- local client, gate, thisGate
- local modemSide = "none"
- local lcGate = false
- local function netReceive()
- local commands = {
- pPull = function() end, --# do nothing, just return
- pPush = function() end, --# do nothing, just return
- QRY = function() sleep(0.1) rednet.send(client, thisGate) end,
- endCall = function() pcall(gate.disconnect) end,
- }
- while true do
- local id, message = rednet.receive()
- if type(message) == "table" and message.program == "pSync" then
- if message.password then
- if not lcGate then
- gate.sendMessage(message.password)
- end
- return
- end
- client = id
- for command, action in pairs(commands) do
- if (message.command and tostring(command) == message.command) or (message.password and tostring(command) == message.password) then
- action()
- return
- end
- end
- if #tostring(message.command) == 7 or #tostring(message.command) == 9 then
- if message.command ~= thisGate then
- if lcGate then
- if gate.isConnected() or gate.isDialing() then
- return
- end
- else
- if gate.stargateState() ~= "Idle" then
- return
- end
- end
- gate.dial(message.command)
- return
- end
- end
- end
- end
- end
- local function charInput()
- while true do
- local _, char = os.pullEvent("char")
- if string.lower(char) == "q" then
- rednet.unhost("pSync")
- rednet.close(modemSide)
- term.clear()
- term.setCursorPos(1, 1)
- term.write("gateBuddy is OFFLINE")
- term.setCursorPos(1, 3)
- return
- end
- end
- end
- local function initError(device)
- term.clear()
- term.setCursorPos(1, 1)
- term.write("No " .. device .. " detected!")
- term.setCursorPos(1, 3)
- term.write("gateBuddy is OFFLINE")
- term.setCursorPos(1, 5)
- return false
- end
- local function initModem()
- for _,side in ipairs(rs.getSides()) do
- if peripheral.getType(side) == "modem" and peripheral.call(side, "isWireless") then
- modemSide = side
- rednet.open(side)
- return true
- end
- end
- return initError("Wireless Modem")
- end
- local function initGate()
- gate = peripheral.find("stargate")
- if type(gate) == "table" then
- lcGate = pcall(gate.getAddress)
- thisGate = lcGate and gate.getAddress() or gate.localAddress()
- return true
- else
- return initError("Stargate")
- end
- end
- local function initMe()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(2, 2)
- term.write("gateBuddy initializing...")
- if not initGate() then return false end
- local ccLabel = os.getComputerLabel()
- if ccLabel == nil or tostring(ccLabel) == "" then
- os.setComputerLabel(thisGate .. " Gate")
- end
- if not initModem() then return false end
- rednet.host("pSync", thisGate)
- term.clear()
- term.setCursorPos(2, 2)
- term.write("gateBuddy " .. gbVer .. " is ONLINE")
- term.setCursorPos(2, 5)
- term.write("This Gate: " .. thisGate)
- term.setCursorPos(2, 8)
- term.write("press 'q' to quit")
- return true
- end
- if not initMe() then return end
- parallel.waitForAny(netReceive, charInput)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement