Guest User

test

a guest
Apr 19th, 2026
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.96 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. local order =  "";
  3. local price = 0
  4. local passAccettata = false
  5. local ben = peripheral.wrap("back")
  6.  
  7. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  8. local function drawPixelInternal(xPos, yPos)
  9.    term.setCursorPos(xPos, yPos)
  10.    term.write(" ")
  11. end
  12.  
  13. local tColourLookup = {}
  14. for n = 1, 16 do
  15.    tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  16. end
  17.  
  18. function drawFilledBox(startX, startY, endX, endY, nColour)
  19.    if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  20.    "number" or type(endY) ~= "number" or
  21.    (nColour ~= nil and type(nColour) ~= "number") then
  22.       error("Expected startX, startY, endX, endY, colour", 2)
  23.    end
  24.  
  25.    startX = math.floor(startX)
  26.    startY = math.floor(startY)
  27.    endX = math.floor(endX)
  28.    endY = math.floor(endY)
  29.  
  30.    if nColour then term.setBackgroundColor(nColour) end
  31.    if startX == endX and startY == endY then
  32.       drawPixelInternal(startX, startY)
  33.       return
  34.    end
  35.  
  36.    local minX = math.min(startX, endX)
  37.    if minX == startX then
  38.       minY = startY
  39.       maxX = endX
  40.       maxY = endY
  41.    else
  42.       minY = endY
  43.       maxX = startX
  44.       maxY = startY
  45.    end
  46.  
  47.    for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  48. end
  49.  
  50. function clear()
  51.    sfondo(colors.black)
  52.    term.clear()
  53.    term.setCursorPos(1, 1)
  54. end
  55.  
  56. function clearRed()
  57.    sfondo(colors.red)
  58.    term.clear()
  59.    term.setCursorPos(1, 1)
  60. end
  61.  
  62. function colore(sfumatura) term.setTextColour(sfumatura) end
  63.  
  64.    function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
  65.  
  66.       function fineColore() term.setTextColour(colours.white) end
  67.  
  68.          function fineSfondo() term.setBackgroundColour(colours.black) end
  69.          function paga(prezzo,id,modid,qty)
  70.             sfondo(colours.blue)
  71.             term.clear()
  72.             term.setCursorPos(1, 1)
  73.             sfondo(colours.blue)
  74.             colore(colors.white)
  75.             print(
  76.             "\n\nInserire i propri dati. Premere Enter per confermare i dati inseriti. \nSe i dati sono corretti, il campo diventeråA5A0 verde. Se sono errati, il programma chiederåA5A0 di reinserirli nuovamente.")
  77.  
  78.             -- nomeutente
  79.             term.setCursorPos(1, 9)
  80.             term.write("Nome utente:")
  81.             term.setCursorPos(15, 9)
  82.             fineColore()
  83.             utenteAccettato = false
  84.             conteggioErrori = 0
  85.             while utenteAccettato == false do
  86.                utente = read()
  87.                checkuser = http.get(
  88.                "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
  89.                utente).readAll()
  90.                tabcheckuser = textutils.unserialize(checkuser)
  91.                if tabcheckuser.stato == "OK" then
  92.                   term.setCursorPos(15, 9)
  93.                   colore(colours.lime)
  94.                   term.write(utente)
  95.                   fineColore()
  96.                   utenteAccettato = true
  97.                else
  98.                   term.setCursorPos(15, 9)
  99.                   colore(colours.red)
  100.                   term.write("Utente errato!          ")
  101.                   sleep(2)
  102.                   term.setCursorPos(15, 9)
  103.                   fineColore()
  104.                   term.write("                       ")
  105.                   term.setCursorPos(15, 9)
  106.                   conteggioErrori = conteggioErrori + 1
  107.                   if conteggioErrori > 2 then
  108.                      term.setCursorPos(15, 9)
  109.                      colore(colours.red)
  110.                      errore("Troppi tentativi di immissione errati    ")
  111.                   end
  112.                end
  113.             end
  114.             colore(colours.white)
  115.             term.setCursorPos(1, 11)
  116.             term.write("Password:")
  117.             term.setCursorPos(15, 11)
  118.             conteggioErrori = 0
  119.             while passAccettata == false do
  120.                fineColore()
  121.                password = read("#")
  122.                colore(colours.black)
  123.                checkuser = http.get(
  124.                "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
  125.                password .. "&richiesta=addebito&valore=0&utente=" ..
  126.                utente).readAll()
  127.                risposta = textutils.unserialize(checkuser)
  128.  
  129.                if risposta.stato == "OK" then
  130.                   term.setCursorPos(15, 11)
  131.                   colore(colours.lime)
  132.                   term.write("##############               ")
  133.                   fineColore()
  134.                   passAccettata = true
  135.                   --    rednet.send(6102, order)
  136.  
  137.                   addOrder = http.get("http://192.168.13.103/addOrder.php?order=" .. order .. "&username=" .. utente .. "&password="                    .. password .. "&type=pecten")
  138.  
  139.  
  140.                   sleep(0.4)
  141.                   sfondo(colours.yellow)
  142.                   term.clear()
  143.                   term.setCursorPos(1, 1)
  144.                   sfondo(colours.yellow)
  145.                   colore(colors.black)
  146.                   print(
  147.                   "\n\Erogazione in corso, attendere, la ringraziamo per l'acquisto!")
  148.                   sleep(2)
  149. --local requestOrder =  http.get("http://192.168.13.103/requestOrder.php?user=" .. utente  .. "-" .. "pecten" .. "&location=3110").readAll()
  150.                   sleep(10)
  151.                   fuelID = ben.getItemIdentifierIDFor(id, modid)
  152.                   if(qty == 16 or qty == 32) then
  153.                     ben.makeRequest(fuelID, qty)
  154.                   elseif(qty == 160) then
  155.                     ben.makeRequest(fuelID, 64)
  156.                     sleep(17.5)
  157.                     ben.makeRequest(fuelID, 64)
  158.                     sleep(17.5)
  159.                     ben.makeRequest(fuelID, 32)
  160.                   elseif(qty == 208) then
  161.                     ben.makeRequest(fuelID, 64)
  162.                     sleep(17.5)
  163.                     ben.makeRequest(fuelID, 64)
  164.                     sleep(17.5)
  165.                     ben.makeRequest(fuelID, 64)
  166.                     sleep(17.5)
  167.                     ben.makeRequest(fuelID, 16)
  168.                
  169.                   end
  170.                   os.reboot()
  171.  
  172.                else
  173.                   term.setCursorPos(15, 11)
  174.                   colore(colours.red)
  175.                   term.write("Password errata o credito insufficiente!            ")
  176.                   conteggioErrori = conteggioErrori + 1
  177.                   sleep(2)
  178.                   term.setCursorPos(15, 11)
  179.                   term.write("                               ")
  180.                   term.setCursorPos(15, 11)
  181.                   if conteggioErrori > 2 then
  182.                      term.setCursorPos(15, 11)
  183.                      colore(colours.red)
  184.                      errore("Troppi tentativi di immissione errati")
  185.                   end
  186.                end
  187.             end
  188.          end
  189.  
  190.             function acquista(product,modid,price)
  191.                term.clear()
  192.                drawFilledBox(1, 1, 51, 19, colors.yellow)
  193.                drawFilledBox(1, 1, 51, 1, colors.orange)
  194.                term.setCursorPos(2, 1)
  195.                colore(colours.white)
  196.                print("PECTEN")
  197.                drawFilledBox(1, 2, 51, 2, colors.red)
  198.                drawFilledBox(1, 3, 51, 21, colors.yellow)
  199.                
  200.                colore(colors.black)
  201.                drawFilledBox(4, 4, 11, 7, colors.red)
  202.                term.setCursorPos(7, 5)
  203.                print("16")
  204.                term.setCursorPos(5, 6)
  205.                print("secchi")
  206.                drawFilledBox(16, 4, 23, 7, colors.red)
  207.                term.setCursorPos(19, 5)
  208.                print("32")
  209.                term.setCursorPos(17, 6)
  210.                print("secchi")
  211.                drawFilledBox(40, 4, 47, 7, colors.red)
  212.                term.setCursorPos(41, 5)
  213.                print("Pieno")
  214.                term.setCursorPos(41, 6)
  215.                print("vagone")
  216.                drawFilledBox(28, 4, 35, 7, colors.red)
  217.                term.setCursorPos(29, 5)
  218.                print("Pieno")
  219.                term.setCursorPos(29, 6)
  220.                print("loco")
  221.  
  222.                term.setCursorPos(20, 9)
  223.                term.setBackgroundColor( colors.yellow )
  224.                colore(colors.red)
  225.                print("AVVERTENZE:")
  226.                term.setCursorPos(2, 11)
  227.                colore(colors.black)
  228.                print("Mantenere la loco spenta durante il rifornimento")
  229.                
  230.                selezione = false
  231.                while(selezione == false) do
  232.                     local event, par1, x, y = os.pullEvent("mouse_click")
  233.                     if event == "mouse_click" and x >= 4 and x <= 11 and y >= 4 and y <=  7 then -- 16
  234.                         order = product .. "-" .. modid .. "-16"
  235.                         paga(tonumber(price),tonumber(product),tonumber(modid),16)                  
  236.  
  237.                         -- selezione = true
  238.                     elseif event == "mouse_click" and x >= 16 and x <= 23 and y >= 4 and y <=  7 then -- 32
  239.                         order = product .. "-" .. modid .. "-32"
  240.                         paga(tonumber(price),tonumber(product),tonumber(modid),32)  
  241.  
  242.                     elseif event == "mouse_click" and x >= 28 and x <= 35 and y >= 4 and y <=  7 then -- pieno loco
  243.                         order = product .. "-" .. modid .. "-160"
  244.                         paga(tonumber(price),tonumber(product),tonumber(modid),160)  
  245.  
  246.  
  247.                     elseif event == "mouse_click" and x >= 40 and x <= 47 and y >= 4 and y <=  7 then -- pieno vagone
  248.                         order = product .. "-" .. modid .. "-208"
  249.                         paga(tonumber(price),tonumber(product),tonumber(modid),208)  
  250.  
  251.                    
  252.                     end  
  253.                end
  254.  
  255.  
  256.             end
  257.  
  258.             sfondo(colours.yellow)
  259.             term.clear()
  260.             drawFilledBox(13, 3, 13, 9, colors.red)
  261.             drawFilledBox(14, 3, 15, 3, colors.red)
  262.             drawFilledBox(16, 4, 16, 5, colors.red)
  263.             drawFilledBox(14, 6, 15, 6, colors.red)
  264.             drawFilledBox(18, 5, 18, 9, colors.red)
  265.             drawFilledBox(19, 5, 20, 5, colors.red)
  266.             drawFilledBox(19, 9, 20, 9, colors.red)
  267.             drawFilledBox(19, 7, 19, 7, colors.red)
  268.             drawFilledBox(22, 6, 22, 8, colors.red)
  269.             drawFilledBox(23, 5, 24, 5, colors.red)
  270.             drawFilledBox(23, 9, 24, 9, colors.red)
  271.             drawFilledBox(26, 5, 28, 5, colors.red)
  272.             drawFilledBox(27, 6, 27, 9, colors.red)
  273.             drawFilledBox(30, 5, 30, 9, colors.red)
  274.             drawFilledBox(31, 5, 32, 5, colors.red)
  275.             drawFilledBox(31, 9, 32, 9, colors.red)
  276.             drawFilledBox(31, 7, 31, 7, colors.red)
  277.             drawFilledBox(34, 5, 34, 9, colors.red)
  278.             drawFilledBox(37, 5, 37, 9, colors.red)
  279.             drawFilledBox(35, 6, 35, 6, colors.red)
  280.             drawFilledBox(36, 7, 36, 7, colors.red)
  281.             sfondo(colours.yellow)
  282.             colore(colours.black)
  283.             term.setCursorPos(8, 14)
  284.             print("Premi un tasto qualsiasi per iniziare...")
  285.             local event, key = os.pullEvent("key")
  286.  
  287.             clear()
  288.             drawFilledBox(1, 1, 51, 19, colors.yellow)
  289.             drawFilledBox(1, 1, 51, 1, colors.orange)
  290.             term.setCursorPos(2, 1)
  291.             colore(colours.white)
  292.             print("PECTEN")
  293.             drawFilledBox(1, 2, 51, 2, colors.red)
  294.             local index = -1
  295.             term.setCursorPos(44, 1)
  296.             colore(colors.black)
  297.             sfondo(colors.red)
  298.             term.write("Annulla")
  299.    
  300.  
  301.                local productsRaw = http.get("http://172.16.20.220/luanet/servlets/test.txt").readAll()
  302.                products = textutils.unserialize(productsRaw)
  303.  
  304.                for k, v in pairs(products) do
  305.                   if(index == tonumber(v.page)) then
  306.                      term.setCursorPos(3, tonumber(v.PagePosition))
  307.                         term.setBackgroundColor( colors.yellow )
  308.                      colore(colors.black)
  309.                      if type(v.prezzo) == "string" then
  310.                         term.write(v.nome)
  311.                         term.setCursorPos(30, tonumber(v.PagePosition))
  312.                         term.write(tostring(v.prezzo) .. " IC")
  313.  
  314.                      else
  315.                         term.write(v.nome)
  316.                      end
  317.                      term.setCursorPos(3, tonumber(v.PagePosition))
  318.                      if not (v.categoria == "lista") then
  319.                         colore(colors.black)
  320.                         term.setBackgroundColor( colors.red )
  321.                         term.setCursorPos(39, tonumber(v.PagePosition))
  322.                         term.write("seleziona")
  323.                         term.setBackgroundColor( colors.yellow )
  324.                      end
  325.                   end
  326.                end
  327.                 click = false
  328.                 while(click == false) do
  329.                 local event, par1, x, y = os.pullEvent("mouse_click")
  330.  
  331.                for k, v in pairs(products) do
  332.                        if (v.PagePosition ~= nil) then
  333.                   if event == "mouse_click" and x >= 39 and x <= 49 and y >= tonumber(v.PagePosition) and y <=  tonumber(v.PagePosition) then -- seleziona
  334.                      if (tonumber(v.page) == index) then
  335.                         if not (v.categoria == "lista") then
  336.                         term.setCursorPos(1, 1)
  337.                            acquista(v.id,v.modId,tonumber(v.prezzo))
  338.                             click = true
  339.                         end
  340.                      end
  341.             elseif event == "mouse_click" and x >= 44 and x <= 50 and y >= 1 and y <= 1 then -- ANNULLA
  342.                os.reboot()
  343.                   end
  344.                end
  345.                 end
  346.             end
  347.  
Advertisement
Add Comment
Please, Sign In to add comment