KaychenHH

Mobfun

Nov 2nd, 2025 (edited)
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.00 KB | Gaming | 0 0
  1. --MobFun V1.01
  2. --written in 10/2025 by Kay Michaelsen
  3. --
  4. --vardef
  5. --
  6. monitor = {}
  7. monitor[1] = peripheral.wrap("monitor_36")
  8.  
  9. aMoni = #monitor
  10.  
  11. --gate = peripheral.wrap("advanced_crystal_interface_2")
  12. --trans = peripheral.wrap("transceiver_0")
  13.  
  14. --
  15.  
  16. l = 0
  17. m = 0
  18. atext = ""
  19. ax = 0
  20. dPage = 1
  21. dMax = 0
  22.  
  23. gName = {}
  24. gLine = {}
  25. gStat = {}
  26.  
  27. aMobs = 0
  28.  
  29. enderOn = false
  30.  
  31. function MobsDefault(fLesen)
  32.  
  33.     gName[1] = "Spider"
  34.     gLine[1] = colors.red
  35.  
  36.     gName[2] = "Skeleton"
  37.     gLine[2] = colors.orange
  38.  
  39.     gName[3] = "Enderman"
  40.     gLine[3] = colors.magenta
  41.  
  42.     gName[4] = "Wither Skeleton"
  43.     gLine[4] = colors.blue
  44.  
  45.     gName[5] = "Zombie"
  46.     gLine[5] = colors.lime
  47.  
  48.     gName[6] = "Creeper"
  49.     gLine[6] = colors.lightBlue
  50.  
  51.     gName[7] = "Smasher"
  52.     gLine[7] = colors.cyan
  53.  
  54.  
  55.     aMobs = #gName
  56.  
  57.     MobsSchreiben(true)
  58.  
  59. end
  60.  
  61.  
  62. function MobsLesen(fLesen)
  63.  
  64.     local fName = "mobsdef.dat"
  65.  
  66.     local vars = {}
  67.     local line = ""
  68.  
  69.     datei = fs.open(fName, "r")
  70.  
  71.     if not (datei == nil) then
  72.  
  73.         local tableString = datei.read()
  74.         while not(line == nil) do
  75.             line = datei.read()
  76.             if line == nil then
  77.                 break
  78.             end
  79.             tableString = tableString..line
  80.         end
  81.         datei.close()
  82.  
  83.         vars = textutils.unserialise(tableString)
  84.  
  85.         aMobs = vars.aMobs
  86.         gName = vars.gName
  87.         gLine = vars.gLine
  88.  
  89.     else
  90.         print("Fehler: Datei nicht lesbar")
  91.     end
  92. end
  93.  
  94. function MobsSchreiben(fLesen)
  95.  
  96.     local fName="mobsdef.dat"
  97.  
  98.     local vars = {}
  99.  
  100.     vars.aMobs = aMobs
  101.     vars.gName = gName
  102.     vars.gLine = gLine
  103.  
  104.     local tableString = textutils.serialise(vars)
  105.     datei = fs.open(fName, "w")
  106.     datei.write(tableString)
  107.     datei.close()
  108.  
  109. end
  110.  
  111.  
  112. function Monitore(fLesen)
  113.  
  114.     for i = 1, aMoni do
  115.         MonAufbau(monitor[i])
  116.     end
  117.  
  118. end
  119.  
  120. function UserCommand( xpos, ypos)
  121.  
  122.     local gNr = 0
  123.  
  124.     print("UC" ,xpos ,ypos)
  125.     if ypos == 1 then
  126.         if (xpos<5) then
  127.             --prev page
  128.             if dPage > 1 then
  129.                 dPage = dPage -1
  130.             end
  131.         elseif (xpos>7) and (xpos<12) then
  132.             if dPage < dMax then
  133.                 dPage = dPage +1
  134.             end
  135.         end
  136.     elseif (ypos == 3) or (ypos == 6) or (ypos == 9) or (ypos == 12) or (ypos == 15) or (ypos == 18) or (ypos == 21) then
  137.         if (xpos >= 37) and (xpos <= 45) then
  138.             gNr = (dPage - 1) * 7 + ((ypos) / 3)
  139.             if gStat[gNr] == true then
  140.                 gStat[gNr] = false
  141.             else
  142.                 gStat[gNr] = true
  143.             end
  144.             setOutput(true)
  145.         end
  146.     end
  147.  
  148.     Monitore(true)
  149.  
  150. end
  151.  
  152. function startMonitors(fLesen)
  153.  
  154.     local i = 0
  155.     local fmoni = monitor[1]
  156.  
  157.     for i = 1, (aMoni) do
  158.         if not (monitor[i] == nil) then
  159.             fmoni = monitor[i]
  160.             fmoni.setTextScale(0.5)
  161.             fmoni.setBackgroundColor(colors.black)
  162.             fmoni.clear()
  163.             fmoni.setBackgroundColor(colors.red)
  164.             fmoni.setTextColor(colors.white)
  165.             fmoni.setCursorPos(2,2)
  166.             fmoni.write(" Initialisiere Systeme ... ")
  167.         end
  168.     end
  169.     sleep(2)
  170.  
  171. end
  172.  
  173. function MonAufbau(moni)
  174.  
  175.     local i = 0
  176.     local k = 0
  177.     local pr = 0
  178.     local py = 0
  179.  
  180.     if not(moni == nil) then
  181.         moni.setTextScale(0.5)
  182.         moni.setBackgroundColor(colors.black)
  183.         moni.clear()
  184.         moni.setBackgroundColor(colors.blue)
  185.         moni.setTextColor(colors.orange)
  186.         moni.setCursorPos(15,1)
  187.         moni.write(" *** Wuffelz Fun mit Mobs *** ")
  188.  
  189.         moni.setCursorPos(1,1)
  190.         if dPage > 1 then
  191.             moni.setBackgroundColor(colors.orange)
  192.             moni.setTextColor(colors.black)
  193.         else
  194.             moni.setBackgroundColor(colors.black)
  195.             moni.setTextColor(colors.orange)
  196.         end
  197.         moni.write(" << ")
  198.  
  199.         moni.setCursorPos(6,1)
  200.         moni.setBackgroundColor(colors.black)
  201.         moni.setTextColor(colors.orange)
  202.         moni.write(string.format("%1d", dPage))
  203.  
  204.         moni.setCursorPos(8,1)
  205.         if dPage < dMax then
  206.             moni.setBackgroundColor(colors.orange)
  207.             moni.setTextColor(colors.black)
  208.         else
  209.             moni.setBackgroundColor(colors.black)
  210.             moni.setTextColor(colors.orange)
  211.         end
  212.         moni.write(" >> ")
  213.  
  214.         for i = 1,7 do
  215.             k = (i-1) * 3 + 1
  216.             moni.setBackgroundColor(colors.black)
  217.             moni.setTextColor(colors.blue)
  218.             py = k + 2
  219.             pr = ((dPage -1) * 7) + i
  220.  
  221.             if pr <= aMobs then
  222.                 moni.setCursorPos(1,py)
  223.                 moni.write(gName[pr])
  224.                 moni.setCursorPos(25,(py))
  225.                 if gStat[pr] == true then
  226.                     moni.setBackgroundColor(colors.black)
  227.                     moni.setTextColor(colors.orange)
  228.                     moni.write("active  ->")
  229.                     moni.setCursorPos(37,(py))
  230.                     moni.setBackgroundColor(colors.orange)
  231.                     moni.setTextColor(colors.blue)
  232.                     moni.write(" stop ")
  233.                 else
  234.                     moni.setBackgroundColor(colors.black)
  235.                     moni.setTextColor(colors.orange)
  236.                     moni.write("inactive  ->")
  237.                     moni.setCursorPos(39,(py))
  238.                     moni.setBackgroundColor(colors.orange)
  239.                     moni.setTextColor(colors.blue)
  240.                     moni.write(" start ")
  241.                 end
  242.             end
  243.  
  244.         end
  245.  
  246.  
  247.     end
  248.  
  249. end
  250.  
  251. function setOutput(lesen)
  252.  
  253.     local lauf = 0
  254.     local bund = 0
  255.  
  256.     for lauf = 1, aMobs do
  257.         if gStat[lauf] == true then
  258.             bund = bund + gLine[lauf]
  259.         end
  260.     end
  261.  
  262.     redstone.setBundledOutput("bottom", (bund))
  263.  
  264. end
  265.  
  266. function getOutput(lesen)
  267.  
  268.     local lauf = 0
  269.     local bund = 0
  270.  
  271.     for lauf = 1, aMobs do
  272.         if not(lauf == 3) and not(lauf == 7) then
  273.             if gStat[lauf] == true then
  274.                 bund = bund +1
  275.             end
  276.         end
  277.     end
  278.  
  279.     return (bund)
  280.  
  281. end
  282.  
  283.  
  284. --Main
  285.  
  286. startMonitors(true)
  287. MobsLesen(true)
  288.  
  289. if (aMobs < 1) then
  290.     MobsDefault(true)
  291. end
  292.  
  293. aMobs = #gName
  294.  
  295. dMax = math.floor(aMobs / 7) +1
  296. dPage = 1
  297.  
  298. print(aMobs, dMax)
  299.  
  300. for z = 1, aMobs do
  301.  
  302.     gStat[z] = false
  303.  
  304. end
  305.  
  306. if (redstone.getBundledInput("bottom") == colors.white) then
  307.     enderOn = true
  308.     gStat[3] = true
  309.     gStat[7] = true
  310. else
  311.     enderOn = false
  312. end
  313. setOutput(true)
  314.  
  315.  
  316. while true do
  317.  
  318.     Monitore(true)
  319.  
  320.     event, button, x, y = os.pullEventRaw()
  321.  
  322.     if event == "terminate" then
  323.         break
  324.     elseif event == "redstone" then
  325.         if (redstone.getBundledInput("bottom") == colors.white) then
  326.             if enderOn == false) then
  327.                 gStat[3] = true
  328.                 gStat[7] = true
  329.                 enderOn = true
  330.                 setOutput(true)
  331.             end
  332.         else
  333.             if enderOn == true then
  334.                 if (getOutput(true) == 0) then
  335.                     gStat[3] = false
  336.                     gStat[7] = false
  337.                 else
  338.                     gStat[3] = false
  339.                 end
  340.                 enderOn = false
  341.                 setOutput(true)
  342.             end
  343.         end
  344.     elseif (event == "monitor_touch") and (button == "monitor_36") then
  345.         UserCommand( x, y)
  346.     elseif (event == "monitor_touch") and (button == "monitor_63") then
  347.         UserCommand( x, y)
  348.     else
  349.         print(event, button, x, y)
  350.         print(" ")
  351.     end
  352.  
  353. end
  354.  
  355.  
Advertisement
Add Comment
Please, Sign In to add comment