KaychenHH

Wuffgate1

Sep 9th, 2025 (edited)
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.78 KB | Gaming | 0 0
  1. --WuffGate V1.01
  2. --written in 09/2025 by Kay Michaelsen
  3. --
  4. --vardef
  5. --
  6. monitor = {}
  7. monitor[1] = peripheral.wrap("monitor_20")
  8. monitor[2] = peripheral.wrap("monitor_22")
  9.  
  10. aMoni = #monitor
  11.  
  12. gate = peripheral.wrap("advanced_crystal_interface_2")
  13. trans = peripheral.wrap("transceiver_0")
  14.  
  15. --
  16.  
  17. l = 0
  18. m = 0
  19. atext = ""
  20. ax = 0
  21. gIsConn = false
  22. gConnTo = "not connected"
  23. gConnName = "-"
  24. gConnNo = 0
  25. gDialed = false
  26. dPage = 1
  27. dMax = 0
  28.  
  29. gName = {}
  30. gAddress = {}
  31. gWorld = {}
  32.  
  33. toDial = {}
  34.  
  35. aGates = 0
  36.  
  37. iGate = false
  38. iIris = false
  39. iShield = false
  40.  
  41. function getShieldStatus(fLesen)
  42.  
  43.     local fColor = (colors.red) and (redstone.getBundledInput("bottom"))
  44.     if fColor == colors.red then
  45.         iShield = false
  46.     else
  47.         iShield = true
  48.     end
  49.  
  50. end
  51.  
  52. function getIrisStatus(fLesen)
  53.  
  54.     local fIris = gate.getIrisProgress()
  55.     if fIris == 0 then
  56.         iIris = false
  57.     else
  58.         iIris = true
  59.     end
  60.  
  61. end
  62.  
  63. function toggleIris(fLesen)
  64.  
  65.     local fIris = gate.getIrisProgress()
  66.     if fIris == 0 then
  67.         gate.closeIris()
  68.         iIris = true
  69.     else
  70.         gate.openIris()
  71.         iIris = false
  72.     end
  73.  
  74. end
  75.  
  76. function toggleShield(fLesen)
  77.  
  78.     local fColor = (colors.red) and (redstone.getBundledInput("bottom"))
  79.     if fColor == colors.red then
  80.         redstone.setBundledOutput("bottom",0)
  81.         iShield = true
  82.     else
  83.         redstone.setBundledOutput("bottom", colors.red)
  84.         iShield = false
  85.     end
  86.  
  87. end
  88.  
  89. function gatesDefault(fLesen)
  90.  
  91.     gName[1] = "Wuffgate Center"
  92.     gAddress[1] = "-21-1-6-15-34-9-27-5-"
  93.     gWorld[1] = "Overworld"
  94.  
  95.     gName[2] = "Lost Cities"
  96.     gAddress[2] = "-15-29-27-5-16-24-"
  97.     gWorld[2] = "Overworld"
  98.  
  99.     gName[3] = "Nether"
  100.     gAddress[3] = "-27-23-4-34-12-28-"
  101.     gWorld[3] = "Nether"
  102.  
  103.     gName[4] = "Abydos"
  104.     gAddress[4] = "-26-6-14-31-11-29-"
  105.     gWorld[4] = "Pegasus"
  106.  
  107.     gName[5] = "Cavum"
  108.     gAddress[5] = "-18-7-3-36-25-15-"
  109.     gWorld[5] = "Pegasus"
  110.  
  111.     gName[6] = "Lantea"
  112.     gAddress[6] = "-18-20-1-15-14-7-19-"
  113.     gWorld[6] = "Pegasus"
  114.  
  115.     gName[7] = "Chulak"
  116.     gAddress[7] = "-8-1-22-14-36-19-"
  117.     gWorld[7] = "Milchstrasse"
  118.  
  119.     aGates = #gName
  120.  
  121.     gatesSchreiben(true)
  122.  
  123. end
  124.  
  125. function identGate(fadd)
  126.  
  127.     local fi = 0
  128.     local fj = -1
  129.     local ft = "-"
  130.  
  131.     for fi = 1, #fadd do
  132.         ft = ft..string.format("%i", fadd[fi]).."-"
  133.     end
  134.  
  135.     for fi = 1, aGates do
  136.         if ft == gAddress[fi] then
  137.             fj = fi
  138.         end
  139.     end
  140.  
  141.     if fj == -1 then
  142.         fj = aGates + 1
  143.         gName[fj] = "unknown"
  144.         gAddress[fj] = ft
  145.         gWorld[fj] = "n/a"
  146.         aGates = fj
  147.         --gatesSchreiben(true)
  148.     end
  149.  
  150.     return fj
  151.  
  152. end
  153.  
  154. function gatesLesen(fLesen)
  155.  
  156.     local fName = "gatedef.dat"
  157.  
  158.     local vars = {}
  159.     local line = ""
  160.  
  161.     datei = fs.open(fName, "r")
  162.  
  163.     if not (datei == nil) then
  164.  
  165.         local tableString = datei.read()
  166.         while not(line == nil) do
  167.             line = datei.read()
  168.             if line == nil then
  169.                 break
  170.             end
  171.             tableString = tableString..line
  172.         end
  173.         datei.close()
  174.  
  175.         vars = textutils.unserialise(tableString)
  176.  
  177.         aGates = vars.aGates
  178.         gName = vars.gName
  179.         gAddress = vars.gAddress
  180.         gWorld = vars.gWorld
  181.  
  182.     else
  183.         print("Fehler: Datei nicht lesbar")
  184.     end
  185. end
  186.  
  187. function gatesSchreiben(fLesen)
  188.  
  189.     local fName="gatedef.dat"
  190.  
  191.     local vars = {}
  192.  
  193.     vars.aGates = aGates
  194.     vars.gName = gName
  195.     vars.gAddress = gAddress
  196.     vars.gWorld = gWorld
  197.  
  198.     local tableString = textutils.serialise(vars)
  199.     datei = fs.open(fName, "w")
  200.     datei.write(tableString)
  201.     datei.close()
  202.  
  203. end
  204.  
  205. function dialAddress(fString)
  206.  
  207.     local fAddress = {}
  208.     local i = 0
  209.     local j = 0
  210.     local k = 0
  211.     local aAdr = 0
  212.     local m = ""
  213.  
  214.     for i = 1, string.len(fString) do
  215.         m = string.sub(fString, i ,i)
  216.         if not(m == "-") then
  217.             if not(j == 0) then
  218.                 k = (j * 10) + tonumber(m)
  219.                 aAdr = aAdr +1
  220.                 fAddress[aAdr] = k
  221.                 j = 0
  222.             else
  223.                 j = tonumber(m)
  224.             end
  225.         else
  226.             if not(j == 0) then
  227.                 aAdr = aAdr + 1
  228.                 fAddress[aAdr] = j
  229.                 j = 0
  230.             end
  231.         end
  232.     end
  233.  
  234.     aAdr = aAdr + 1
  235.     fAddress[aAdr] = 0
  236.  
  237.     gate.disconnectStargate()
  238.  
  239.     for i = 1, aAdr do
  240.         gate.engageSymbol(fAddress[i])
  241.     end
  242.  
  243. end
  244.  
  245. function Monitore(fLesen)
  246.  
  247.     for i = 1, aMoni do
  248.         MonAufbau(monitor[i])
  249.     end
  250.  
  251. end
  252.  
  253. function UserCommand( xpos, ypos)
  254.  
  255.     local gNr = 0
  256.  
  257.     print("UC" ,xpos ,ypos)
  258.     if ypos == 23 then
  259.         if (xpos>42) and (xpos<54) then
  260.             if automat == true then
  261.                 automat = false
  262.             else
  263.                 automat = true
  264.             end
  265.         end
  266.     elseif ypos == 1 then
  267.         if (xpos<5) then
  268.             --prev page
  269.             if dPage > 1 then
  270.                 dPage = dPage -1
  271.             end
  272.         elseif (xpos>7) and (xpos<12) then
  273.             if dPage < dMax then
  274.                 dPage = dPage +1
  275.             end
  276.         end
  277.     elseif (ypos == 4) or (ypos == 7) or (ypos == 10) or (ypos == 13) or (ypos == 16) or (ypos == 19) then
  278.         if (xpos >= 28) and (xpos <= 33) then
  279.             gNr = (dPage - 1) * 6 + ((ypos-1) / 3)
  280.  
  281.             print(gAddress[gNr])
  282.             dialAddress(gAddress[gNr])
  283.         end
  284.     elseif (ypos == 3) and (xpos >= 49) then
  285.         gate.disconnectStargate()
  286.     elseif (ypos == 6) and (xpos >= 49) then
  287.         toggleIris(true)
  288.     elseif (ypos == 9) and (xpos >= 49) then
  289.         toggleShield(true)
  290.     end
  291.  
  292.     Monitore(true)
  293.  
  294. end
  295.  
  296. function startMonitors(fLesen)
  297.  
  298.     local i = 0
  299.     local fmoni = monitor[1]
  300.  
  301.     for i = 1, (aMoni) do
  302.         if not (monitor[i] == nil) then
  303.             fmoni = monitor[i]
  304.             fmoni.setTextScale(0.5)
  305.             fmoni.setBackgroundColor(colors.black)
  306.             fmoni.clear()
  307.             fmoni.setBackgroundColor(colors.red)
  308.             fmoni.setTextColor(colors.white)
  309.             fmoni.setCursorPos(2,2)
  310.             fmoni.write(" Initialisiere Systeme ... ")
  311.         end
  312.     end
  313.     sleep(3)
  314.  
  315. end
  316.  
  317. function MonAufbau(moni)
  318.  
  319.     local i = 0
  320.     local k = 0
  321.     local pr = 0
  322.     local py = 0
  323.  
  324.     if not(moni == nil) then
  325.         moni.setTextScale(0.5)
  326.         moni.setBackgroundColor(colors.black)
  327.         moni.clear()
  328.         moni.setBackgroundColor(colors.blue)
  329.         moni.setTextColor(colors.orange)
  330.         moni.setCursorPos(13,1)
  331.         moni.write(" *** Wuffelz Stargate Control *** ")
  332.  
  333.         moni.setCursorPos(1,1)
  334.         if dPage > 1 then
  335.             moni.setBackgroundColor(colors.orange)
  336.             moni.setTextColor(colors.black)
  337.         else
  338.             moni.setBackgroundColor(colors.black)
  339.             moni.setTextColor(colors.orange)
  340.         end
  341.         moni.write(" << ")
  342.  
  343.         moni.setCursorPos(6,1)
  344.         moni.setBackgroundColor(colors.black)
  345.         moni.setTextColor(colors.orange)
  346.         moni.write(string.format("%1d", dPage))
  347.  
  348.         moni.setCursorPos(8,1)
  349.         if dPage < dMax then
  350.             moni.setBackgroundColor(colors.orange)
  351.             moni.setTextColor(colors.black)
  352.         else
  353.             moni.setBackgroundColor(colors.black)
  354.             moni.setTextColor(colors.orange)
  355.         end
  356.         moni.write(" >> ")
  357.  
  358.         for i = 1,6 do
  359.             k = (i-1) * 3 + 1
  360.             moni.setBackgroundColor(colors.black)
  361.             moni.setTextColor(colors.blue)
  362.             py = k + 2
  363.             pr = ((dPage -1) * 6) + i
  364.  
  365.             if pr <= aGates then
  366.                 moni.setCursorPos(1,py)
  367.                 moni.write(gName[pr].." ("..gWorld[pr]..")")
  368.                 moni.setCursorPos(1,(py + 1))
  369.                 moni.setTextColor(colors.orange)
  370.                 moni.write("("..gAddress[pr]..")")
  371.  
  372.                 moni.setCursorPos(28,(py+1))
  373.                 moni.setBackgroundColor(colors.blue)
  374.                 moni.write(" Dial ")
  375.             end
  376.         end
  377.  
  378.         moni.setBackgroundColor(colors.black)
  379.         moni.setTextColor(colors.blue)
  380.         moni.setCursorPos(35,3)
  381.         moni.write("Gate ")
  382.         moni.setCursorPos(41,3)
  383.         if gIsConn == true then
  384.             moni.write("active")
  385.         else
  386.             moni.write("idle")
  387.         end
  388.         moni.setCursorPos(49,3)
  389.         moni.setBackgroundColor(colors.orange)
  390.         moni.setTextColor(colors.blue)
  391.         moni.write(" Reset ")
  392.  
  393.         moni.setCursorPos(35,6)
  394.         moni.setBackgroundColor(colors.black)
  395.         moni.setTextColor(colors.blue)
  396.         moni.write("Iris")
  397.         moni.setCursorPos(41,6)
  398.         if iIris == true then
  399.             moni.write("closed")
  400.         else
  401.             moni.write("open")
  402.         end
  403.         moni.setCursorPos(49,6)
  404.         moni.setBackgroundColor(colors.orange)
  405.         moni.setTextColor(colors.blue)
  406.         if iIris == true then
  407.             moni.write(" open ")
  408.         else
  409.             moni.write(" close ")
  410.         end
  411.  
  412.  
  413.         moni.setCursorPos(35,9)
  414.         moni.setBackgroundColor(colors.black)
  415.         moni.setTextColor(colors.blue)
  416.         moni.write("Armor")
  417.         moni.setCursorPos(41,9)
  418.         if iShield == true then
  419.             moni.write("closed")
  420.         else
  421.             moni.write("open")
  422.         end
  423.         moni.setCursorPos(49,9)
  424.         moni.setBackgroundColor(colors.orange)
  425.         moni.setTextColor(colors.blue)
  426.         if iShield == true then
  427.             moni.write(" open ")
  428.         else
  429.             moni.write(" close ")
  430.         end
  431.  
  432.         moni.setCursorPos(35,12)
  433.         moni.setBackgroundColor(colors.black)
  434.         moni.setTextColor(colors.red)
  435.         if gIsConn == false then
  436.             moni.write("not connected")
  437.         else
  438.             moni.write("connected to")
  439.             moni.setCursorPos(35,14)
  440.             moni.write(gConnTo)
  441.             moni.setCursorPos(35,16)
  442.             moni.write("("..gConnName..")")
  443.             moni.setCursorPos(35,18)
  444.             moni.setTextColor(colors.blue)
  445.             if gDialed == true then
  446.                 moni.write("Outgoing connection")
  447.             else
  448.                 moni.write("Incoming connection")
  449.             end
  450.         end
  451.  
  452.  
  453.     end
  454.  
  455. end
  456.  
  457. --Main
  458.  
  459. startMonitors(true)
  460. gatesLesen(true)
  461.  
  462. if (aGates < 1) then
  463.     gatesDefault(true)
  464. end
  465.  
  466. aGates = #gName
  467.  
  468. dMax = math.floor(aGates / 6) +1
  469. dPage = 1
  470.  
  471. print(aGates, dMax)
  472.  
  473. getIrisStatus(true)
  474. getShieldStatus(true)
  475.  
  476. while true do
  477.  
  478.     Monitore(true)
  479.  
  480.     event, button, x, y = os.pullEventRaw()
  481.  
  482.     if event == "terminate" then
  483.         break
  484.     elseif (button == "transceiver_0") then
  485.         print(button, event, x, y)
  486.         if (event == "transceiver_transmission_received") then
  487.             if (x == 1230) then
  488.                 if iIris == true then
  489.                     print("open iris")
  490.                     toggleIris(true)
  491.                 end
  492.  
  493.             end
  494.         end
  495.     elseif event == "redstone" then
  496.         --neuer Durchlauf
  497.     elseif (event == "monitor_touch") and (button == "monitor_20") then
  498.         UserCommand( x, y)
  499.     elseif (event == "monitor_touch") and (button == "monitor_22") then
  500.         UserCommand( x, y)
  501.     elseif event == "stargate_reset" then
  502.             iGate = false
  503.             gIsConn = false
  504.             gConnTo = "not connected"
  505.             gConnName = "-"
  506.             gConnNo = 0
  507.     elseif event == "stargate_disconnected" then
  508.             iGate = false
  509.             gIsConn = false
  510.             gConnTo = "not connected"
  511.             gConnName = "-"
  512.             gConnNo = 0
  513.     elseif event == "stargate_incoming_wormhole" then
  514.             gConnNo = identGate(x)
  515.             iGate = true
  516.             gIsConn = true
  517.             gConnTo = gAddress[gConnNo]
  518.             gConnName = gName[gConnNo]
  519.             gDialed = false
  520.     elseif event == "stargate_outgoing_wormhole" then
  521.             gConnNo = identGate(x)
  522.             iGate = true
  523.             gIsConn = true
  524.             gConnTo = gAddress[gConnNo]
  525.             gConnName = gName[gConnNo]
  526.             gDialed = true
  527.     else
  528.         print(event, button, x, y)
  529.         print(" ")
  530.     end
  531.  
  532. end
  533.  
Advertisement
Add Comment
Please, Sign In to add comment