Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --WuffGate V1.01
- --written in 09/2025 by Kay Michaelsen
- --
- --vardef
- --
- monitor = {}
- monitor[1] = peripheral.wrap("monitor_20")
- monitor[2] = peripheral.wrap("monitor_22")
- aMoni = #monitor
- gate = peripheral.wrap("advanced_crystal_interface_2")
- trans = peripheral.wrap("transceiver_0")
- --
- l = 0
- m = 0
- atext = ""
- ax = 0
- gIsConn = false
- gConnTo = "not connected"
- gConnName = "-"
- gConnNo = 0
- gDialed = false
- dPage = 1
- dMax = 0
- gName = {}
- gAddress = {}
- gWorld = {}
- toDial = {}
- aGates = 0
- iGate = false
- iIris = false
- iShield = false
- function getShieldStatus(fLesen)
- local fColor = (colors.red) and (redstone.getBundledInput("bottom"))
- if fColor == colors.red then
- iShield = false
- else
- iShield = true
- end
- end
- function getIrisStatus(fLesen)
- local fIris = gate.getIrisProgress()
- if fIris == 0 then
- iIris = false
- else
- iIris = true
- end
- end
- function toggleIris(fLesen)
- local fIris = gate.getIrisProgress()
- if fIris == 0 then
- gate.closeIris()
- iIris = true
- else
- gate.openIris()
- iIris = false
- end
- end
- function toggleShield(fLesen)
- local fColor = (colors.red) and (redstone.getBundledInput("bottom"))
- if fColor == colors.red then
- redstone.setBundledOutput("bottom",0)
- iShield = true
- else
- redstone.setBundledOutput("bottom", colors.red)
- iShield = false
- end
- end
- function gatesDefault(fLesen)
- gName[1] = "Wuffgate Center"
- gAddress[1] = "-21-1-6-15-34-9-27-5-"
- gWorld[1] = "Overworld"
- gName[2] = "Lost Cities"
- gAddress[2] = "-15-29-27-5-16-24-"
- gWorld[2] = "Overworld"
- gName[3] = "Nether"
- gAddress[3] = "-27-23-4-34-12-28-"
- gWorld[3] = "Nether"
- gName[4] = "Abydos"
- gAddress[4] = "-26-6-14-31-11-29-"
- gWorld[4] = "Pegasus"
- gName[5] = "Cavum"
- gAddress[5] = "-18-7-3-36-25-15-"
- gWorld[5] = "Pegasus"
- gName[6] = "Lantea"
- gAddress[6] = "-18-20-1-15-14-7-19-"
- gWorld[6] = "Pegasus"
- gName[7] = "Chulak"
- gAddress[7] = "-8-1-22-14-36-19-"
- gWorld[7] = "Milchstrasse"
- aGates = #gName
- gatesSchreiben(true)
- end
- function identGate(fadd)
- local fi = 0
- local fj = -1
- local ft = "-"
- for fi = 1, #fadd do
- ft = ft..string.format("%i", fadd[fi]).."-"
- end
- for fi = 1, aGates do
- if ft == gAddress[fi] then
- fj = fi
- end
- end
- if fj == -1 then
- fj = aGates + 1
- gName[fj] = "unknown"
- gAddress[fj] = ft
- gWorld[fj] = "n/a"
- aGates = fj
- --gatesSchreiben(true)
- end
- return fj
- end
- function gatesLesen(fLesen)
- local fName = "gatedef.dat"
- local vars = {}
- local line = ""
- datei = fs.open(fName, "r")
- if not (datei == nil) then
- local tableString = datei.read()
- while not(line == nil) do
- line = datei.read()
- if line == nil then
- break
- end
- tableString = tableString..line
- end
- datei.close()
- vars = textutils.unserialise(tableString)
- aGates = vars.aGates
- gName = vars.gName
- gAddress = vars.gAddress
- gWorld = vars.gWorld
- else
- print("Fehler: Datei nicht lesbar")
- end
- end
- function gatesSchreiben(fLesen)
- local fName="gatedef.dat"
- local vars = {}
- vars.aGates = aGates
- vars.gName = gName
- vars.gAddress = gAddress
- vars.gWorld = gWorld
- local tableString = textutils.serialise(vars)
- datei = fs.open(fName, "w")
- datei.write(tableString)
- datei.close()
- end
- function dialAddress(fString)
- local fAddress = {}
- local i = 0
- local j = 0
- local k = 0
- local aAdr = 0
- local m = ""
- for i = 1, string.len(fString) do
- m = string.sub(fString, i ,i)
- if not(m == "-") then
- if not(j == 0) then
- k = (j * 10) + tonumber(m)
- aAdr = aAdr +1
- fAddress[aAdr] = k
- j = 0
- else
- j = tonumber(m)
- end
- else
- if not(j == 0) then
- aAdr = aAdr + 1
- fAddress[aAdr] = j
- j = 0
- end
- end
- end
- aAdr = aAdr + 1
- fAddress[aAdr] = 0
- gate.disconnectStargate()
- for i = 1, aAdr do
- gate.engageSymbol(fAddress[i])
- end
- end
- function Monitore(fLesen)
- for i = 1, aMoni do
- MonAufbau(monitor[i])
- end
- end
- function UserCommand( xpos, ypos)
- local gNr = 0
- print("UC" ,xpos ,ypos)
- if ypos == 23 then
- if (xpos>42) and (xpos<54) then
- if automat == true then
- automat = false
- else
- automat = true
- end
- end
- elseif ypos == 1 then
- if (xpos<5) then
- --prev page
- if dPage > 1 then
- dPage = dPage -1
- end
- elseif (xpos>7) and (xpos<12) then
- if dPage < dMax then
- dPage = dPage +1
- end
- end
- elseif (ypos == 4) or (ypos == 7) or (ypos == 10) or (ypos == 13) or (ypos == 16) or (ypos == 19) then
- if (xpos >= 28) and (xpos <= 33) then
- gNr = (dPage - 1) * 6 + ((ypos-1) / 3)
- print(gAddress[gNr])
- dialAddress(gAddress[gNr])
- end
- elseif (ypos == 3) and (xpos >= 49) then
- gate.disconnectStargate()
- elseif (ypos == 6) and (xpos >= 49) then
- toggleIris(true)
- elseif (ypos == 9) and (xpos >= 49) then
- toggleShield(true)
- end
- Monitore(true)
- end
- function startMonitors(fLesen)
- local i = 0
- local fmoni = monitor[1]
- for i = 1, (aMoni) do
- if not (monitor[i] == nil) then
- fmoni = monitor[i]
- fmoni.setTextScale(0.5)
- fmoni.setBackgroundColor(colors.black)
- fmoni.clear()
- fmoni.setBackgroundColor(colors.red)
- fmoni.setTextColor(colors.white)
- fmoni.setCursorPos(2,2)
- fmoni.write(" Initialisiere Systeme ... ")
- end
- end
- sleep(3)
- end
- function MonAufbau(moni)
- local i = 0
- local k = 0
- local pr = 0
- local py = 0
- if not(moni == nil) then
- moni.setTextScale(0.5)
- moni.setBackgroundColor(colors.black)
- moni.clear()
- moni.setBackgroundColor(colors.blue)
- moni.setTextColor(colors.orange)
- moni.setCursorPos(13,1)
- moni.write(" *** Wuffelz Stargate Control *** ")
- moni.setCursorPos(1,1)
- if dPage > 1 then
- moni.setBackgroundColor(colors.orange)
- moni.setTextColor(colors.black)
- else
- moni.setBackgroundColor(colors.black)
- moni.setTextColor(colors.orange)
- end
- moni.write(" << ")
- moni.setCursorPos(6,1)
- moni.setBackgroundColor(colors.black)
- moni.setTextColor(colors.orange)
- moni.write(string.format("%1d", dPage))
- moni.setCursorPos(8,1)
- if dPage < dMax then
- moni.setBackgroundColor(colors.orange)
- moni.setTextColor(colors.black)
- else
- moni.setBackgroundColor(colors.black)
- moni.setTextColor(colors.orange)
- end
- moni.write(" >> ")
- for i = 1,6 do
- k = (i-1) * 3 + 1
- moni.setBackgroundColor(colors.black)
- moni.setTextColor(colors.blue)
- py = k + 2
- pr = ((dPage -1) * 6) + i
- if pr <= aGates then
- moni.setCursorPos(1,py)
- moni.write(gName[pr].." ("..gWorld[pr]..")")
- moni.setCursorPos(1,(py + 1))
- moni.setTextColor(colors.orange)
- moni.write("("..gAddress[pr]..")")
- moni.setCursorPos(28,(py+1))
- moni.setBackgroundColor(colors.blue)
- moni.write(" Dial ")
- end
- end
- moni.setBackgroundColor(colors.black)
- moni.setTextColor(colors.blue)
- moni.setCursorPos(35,3)
- moni.write("Gate ")
- moni.setCursorPos(41,3)
- if gIsConn == true then
- moni.write("active")
- else
- moni.write("idle")
- end
- moni.setCursorPos(49,3)
- moni.setBackgroundColor(colors.orange)
- moni.setTextColor(colors.blue)
- moni.write(" Reset ")
- moni.setCursorPos(35,6)
- moni.setBackgroundColor(colors.black)
- moni.setTextColor(colors.blue)
- moni.write("Iris")
- moni.setCursorPos(41,6)
- if iIris == true then
- moni.write("closed")
- else
- moni.write("open")
- end
- moni.setCursorPos(49,6)
- moni.setBackgroundColor(colors.orange)
- moni.setTextColor(colors.blue)
- if iIris == true then
- moni.write(" open ")
- else
- moni.write(" close ")
- end
- moni.setCursorPos(35,9)
- moni.setBackgroundColor(colors.black)
- moni.setTextColor(colors.blue)
- moni.write("Armor")
- moni.setCursorPos(41,9)
- if iShield == true then
- moni.write("closed")
- else
- moni.write("open")
- end
- moni.setCursorPos(49,9)
- moni.setBackgroundColor(colors.orange)
- moni.setTextColor(colors.blue)
- if iShield == true then
- moni.write(" open ")
- else
- moni.write(" close ")
- end
- moni.setCursorPos(35,12)
- moni.setBackgroundColor(colors.black)
- moni.setTextColor(colors.red)
- if gIsConn == false then
- moni.write("not connected")
- else
- moni.write("connected to")
- moni.setCursorPos(35,14)
- moni.write(gConnTo)
- moni.setCursorPos(35,16)
- moni.write("("..gConnName..")")
- moni.setCursorPos(35,18)
- moni.setTextColor(colors.blue)
- if gDialed == true then
- moni.write("Outgoing connection")
- else
- moni.write("Incoming connection")
- end
- end
- end
- end
- --Main
- startMonitors(true)
- gatesLesen(true)
- if (aGates < 1) then
- gatesDefault(true)
- end
- aGates = #gName
- dMax = math.floor(aGates / 6) +1
- dPage = 1
- print(aGates, dMax)
- getIrisStatus(true)
- getShieldStatus(true)
- while true do
- Monitore(true)
- event, button, x, y = os.pullEventRaw()
- if event == "terminate" then
- break
- elseif (button == "transceiver_0") then
- print(button, event, x, y)
- if (event == "transceiver_transmission_received") then
- if (x == 1230) then
- if iIris == true then
- print("open iris")
- toggleIris(true)
- end
- end
- end
- elseif event == "redstone" then
- --neuer Durchlauf
- elseif (event == "monitor_touch") and (button == "monitor_20") then
- UserCommand( x, y)
- elseif (event == "monitor_touch") and (button == "monitor_22") then
- UserCommand( x, y)
- elseif event == "stargate_reset" then
- iGate = false
- gIsConn = false
- gConnTo = "not connected"
- gConnName = "-"
- gConnNo = 0
- elseif event == "stargate_disconnected" then
- iGate = false
- gIsConn = false
- gConnTo = "not connected"
- gConnName = "-"
- gConnNo = 0
- elseif event == "stargate_incoming_wormhole" then
- gConnNo = identGate(x)
- iGate = true
- gIsConn = true
- gConnTo = gAddress[gConnNo]
- gConnName = gName[gConnNo]
- gDialed = false
- elseif event == "stargate_outgoing_wormhole" then
- gConnNo = identGate(x)
- iGate = true
- gIsConn = true
- gConnTo = gAddress[gConnNo]
- gConnName = gName[gConnNo]
- gDialed = true
- else
- print(event, button, x, y)
- print(" ")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment