MrUndead

Recive Stocks

Feb 23rd, 2022 (edited)
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.01 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local event = require("event")
  4. local Data = component.data
  5. local m = component.modem
  6. local SER = require("serialization")
  7.  
  8. local PortO = 123
  9. m.open(PortO)
  10. ServerS = "31ef9c76-ab30-4bf1-a5d4-a1524e13bfb1"
  11.  
  12. while true do
  13.  
  14.     local _, _, _, _, _, serialized_message = event.pull("modem_message")
  15.     local received_table = SER.unserialize(serialized_message)
  16.  
  17.     local Iron = received_table.Iron
  18.     local Gold = received_table.Gold
  19.     local Diamond = received_table.Diamond
  20.     local Stone = received_table.Stone
  21.     local Cobble = received_table.Cobble
  22.     local DSI = received_table.DSI
  23.     local DIL = received_table.DIL
  24.  
  25.     if Iron <= 25 then
  26.         local IFileR = io.open("Iron", "r")
  27.         if IFileR == nil then
  28.             local CIFile = io.open("Iron", "a")
  29.             CIFile:write("100")
  30.             CIFile:close()
  31.             local IFileR = io.open("Iron", "r")
  32.             local Balance = IFileR:read("*l")
  33.             IFileR:close()
  34.             local IFileW = io.open("Iron", "w")
  35.             newBalanceI = Balance - 1
  36.             IFileW:write(newBalanceI)
  37.             io.write("Iron DOWN: ", newBalanceI, "$\n")
  38.             IFileW:close()
  39.         else
  40.             local Balance = IFileR:read("*l")
  41.             IFileR:close()
  42.             local IFileW = io.open("Iron", "w")
  43.             newBalanceI = Balance - 1
  44.             IFileW:write(newBalanceI)
  45.             io.write("Iron DOWN: ", newBalanceI, "$\n")
  46.             IFileW:close()
  47.         end
  48.  
  49.     elseif Iron >= 26 and Iron <= 51 then
  50.         local IFileR = io.open("Iron", "r")
  51.         if IFileR == nil then
  52.             local CIFile = io.open("Iron", "a")
  53.             CIFile:write("100")
  54.             CIFile:close()
  55.             local IFileR = io.open("Iron", "r")
  56.             local Balance = IFileR:read("*l")
  57.             IFileR:close()
  58.             local IFileW = io.open("Iron", "w")
  59.             newBalanceI = Balance
  60.             IFileW:write(newBalanceI)
  61.             io.write("Iron STAY: ", newBalanceI, "$\n")
  62.             IFileW:close()
  63.         else
  64.             local Balance = IFileR:read("*l")
  65.             IFileR:close()
  66.             local IFileW = io.open("Iron", "w")
  67.             newBalanceI = Balance
  68.             IFileW:write(newBalanceI)
  69.             io.write("Iron STAY: ", newBalanceI, "$\n")
  70.             IFileW:close()
  71.         end
  72.     else
  73.         local IFileR = io.open("Iron", "r")
  74.         if IFileR == nil then
  75.             local CIFile = io.open("Iron", "a")
  76.             CIFile:write("100")
  77.             CIFile:close()
  78.             local IFileR = io.open("Iron", "r")
  79.             local Balance = IFileR:read("*l")
  80.             IFileR:close()
  81.             local IFileW = io.open("Iron", "w")
  82.             newBalanceI = Balance + 1
  83.             IFileW:write(newBalanceI)
  84.             io.write("Iron UP: ", newBalanceI, "$\n")
  85.             IFileW:close()
  86.         else
  87.             local Balance = IFileR:read("*l")
  88.             IFileR:close()
  89.             local IFileW = io.open("Iron", "w")
  90.             newBalanceI = Balance + 1
  91.             IFileW:write(newBalanceI)
  92.             io.write("Iron UP: ", newBalanceI, "$\n")
  93.             IFileW:close()
  94.         end
  95.     end
  96.  
  97.     if Gold <= 25 then
  98.         local GFileR = io.open("Gold", "r")
  99.         if GFileR == nil then
  100.             local CGFile = io.open("Gold", "a")
  101.             CGFile:write("1000")
  102.             CGFile:close()
  103.             local GFileR = io.open("Gold", "r")
  104.             local Balance = GFileR:read("*l")
  105.             GFileR:close()
  106.             local GFileW = io.open("Gold", "w")
  107.             newBalanceG = Balance - 1
  108.             GFileW:write(newBalanceG)
  109.             io.write("Gold: DOWN ", newBalanceG, "$\n")
  110.             GFileW:close()
  111.         else
  112.             local Balance = GFileR:read("*l")
  113.             GFileR:close()
  114.             local GFileW = io.open("Gold", "w")
  115.             newBalanceG = Balance - 1
  116.             GFileW:write(newBalanceG)
  117.             io.write("Gold: DOWN ", newBalanceG, "$\n")
  118.             GFileW:close()
  119.         end
  120.     elseif Gold >= 26 and Gold <= 51 then
  121.         local GFileR = io.open("Gold", "r")
  122.         if GFileR == nil then
  123.             local CGFile = io.open("Gold", "a")
  124.             CGFile:write("1000")
  125.             CGFile:close()
  126.             local GFileR = io.open("Gold", "r")
  127.             local Balance = GFileR:read("*l")
  128.             GFileR:close()
  129.             local GFileW = io.open("Gold", "w")
  130.             newBalanceG = Balance
  131.             GFileW:write(newBalanceG)
  132.             io.write("Gold: STAY ", newBalanceG, "$\n")
  133.             GFileW:close()
  134.         else
  135.             local Balance = GFileR:read("*l")
  136.             GFileR:close()
  137.             local GFileW = io.open("Gold", "w")
  138.             newBalanceG = Balance
  139.             GFileW:write(newBalanceG)
  140.             io.write("Gold: STAY ", newBalanceG, "$\n")
  141.             GFileW:close()
  142.         end
  143.     else
  144.         local GFileR = io.open("Gold", "r")
  145.         if GFileR == nil then
  146.             local CGFile = io.open("Gold", "a")
  147.             CGFile:write("1000")
  148.             CGFile:close()
  149.             local GFileR = io.open("Gold", "r")
  150.             local Balance = GFileR:read("*l")
  151.             GFileR:close()
  152.             local GFileW = io.open("Gold", "w")
  153.             newBalanceG = Balance + 1
  154.             GFileW:write(newBalanceG)
  155.             io.write("Gold: UP ", newBalanceG, "$\n")
  156.             GFileW:close()
  157.         else
  158.             local Balance = GFileR:read("*l")
  159.             GFileR:close()
  160.             local GFileW = io.open("Gold", "w")
  161.             newBalanceG = Balance + 1
  162.             GFileW:write(newBalanceG)
  163.             io.write("Gold: UP ", newBalanceG, "$\n")
  164.             GFileW:close()
  165.         end
  166.     end
  167.  
  168.     if Diamond <= 25 then
  169.         local DFileR = io.open("Diamond", "r")
  170.         if DFileR == nil then
  171.             local CDFile = io.open("Diamond", "a")
  172.             CDFile:write("10000")
  173.             CDFile:close()
  174.             local DFileR = io.open("Diamond", "r")
  175.             local Balance = DFileR:read("*l")
  176.             DFileR:close()
  177.             local DFileW = io.open("Diamond", "w")
  178.             newBalanceD = Balance - 1
  179.             DFileW:write(newBalanceD)
  180.             io.write("Diamond: DOWN ", newBalanceD, "$\n")
  181.             DFileW:close()
  182.         else
  183.             local Balance = DFileR:read("*l")
  184.             DFileR:close()
  185.             local DFileW = io.open("Diamond", "w")
  186.             newBalanceD = Balance - 1
  187.             DFileW:write(newBalanceD)
  188.             io.write("Diamond: DOWN ", newBalanceD, "$\n")
  189.             DFileW:close()
  190.         end
  191.     elseif Diamond >= 26 and Diamond <= 51 then
  192.         local DFileR = io.open("Diamond", "r")
  193.         if DFileR == nil then
  194.             local CDFile = io.open("Diamond", "a")
  195.             CDFile:write("10000")
  196.             CDFile:close()
  197.             local DFileR = io.open("Diamond", "r")
  198.             local Balance = DFileR:read("*l")
  199.             DFileR:close()
  200.             local DFileW = io.open("Diamond", "w")
  201.             newBalanceD = Balance
  202.             DFileW:write(newBalanceD)
  203.             io.write("Diamond: STAY ", newBalanceD, "$\n")
  204.             DFileW:close()
  205.         else
  206.             local Balance = DFileR:read("*l")
  207.             DFileR:close()
  208.             local DFileW = io.open("Diamond", "w")
  209.             newBalanceD = Balance
  210.             DFileW:write(newBalanceD)
  211.             io.write("Diamond: STAY ", newBalanceD, "$\n")
  212.             DFileW:close()
  213.         end
  214.     else
  215.         local DFileR = io.open("Diamond", "r")
  216.         if DFileR == nil then
  217.             local CDFile = io.open("Diamond", "a")
  218.             CDFile:write("10000")
  219.             CDFile:close()
  220.             local DFileR = io.open("Diamond", "r")
  221.             local Balance = DFileR:read("*l")
  222.             DFileR:close()
  223.             local DFileW = io.open("Diamond", "w")
  224.             newBalanceD = Balance + 1
  225.             DFileW:write(newBalanceD)
  226.             io.write("Diamond: UP ", newBalanceD, "$\n")
  227.             DFileW:close()
  228.         else
  229.             local Balance = DFileR:read("*l")
  230.             DFileR:close()
  231.             local DFileW = io.open("Diamond", "w")
  232.             newBalanceD = Balance + 1
  233.             DFileW:write(newBalanceD)
  234.             io.write("Diamond: UP ", newBalanceD, "$\n")
  235.             DFileW:close()
  236.         end
  237.     end
  238.  
  239.     if Stone <= 25 then
  240.         local SFileR = io.open("Stone", "r")
  241.         if SFileR == nil then
  242.             local CSFile = io.open("Stone", "a")
  243.             CSFile:write("10")
  244.             CSFile:close()
  245.             local SFileR = io.open("Stone", "r")
  246.             local Balance = SFileR:read("*l")
  247.             SFileR:close()
  248.             local SFileW = io.open("Stone", "w")
  249.             newBalanceS = Balance - 1
  250.             SFileW:write(newBalanceS)
  251.             io.write("Stone: DOWN ", newBalanceS, "$\n")
  252.             SFileW:close()
  253.         else
  254.             local Balance = SFileR:read("*l")
  255.             SFileR:close()
  256.             local SFileW = io.open("Stone", "w")
  257.             newBalanceS = Balance - 1
  258.             SFileW:write(newBalanceS)
  259.             io.write("Stone: DOWN ", newBalanceS, "$\n")
  260.             SFileW:close()
  261.         end
  262.     elseif Stone >= 26 and Stone <= 51 then
  263.         local SFileR = io.open("Stone", "r")
  264.         if SFileR == nil then
  265.             local CSFile = io.open("Stone", "a")
  266.             CSFile:write("10")
  267.             CSFile:close()
  268.             local SFileR = io.open("Stone", "r")
  269.             local Balance = SFileR:read("*l")
  270.             SFileR:close()
  271.             local SFileW = io.open("Stone", "w")
  272.             newBalanceS = Balance
  273.             SFileW:write(newBalanceS)
  274.             io.write("Stone: STAY ", newBalanceS, "$\n")
  275.             SFileW:close()
  276.         else
  277.             local Balance = SFileR:read("*l")
  278.             SFileR:close()
  279.             local SFileW = io.open("Stone", "w")
  280.             newBalanceS = Balance
  281.             SFileW:write(newBalanceS)
  282.             io.write("Stone: STAY ", newBalanceS, "$\n")
  283.             SFileW:close()
  284.         end
  285.     else
  286.         local SFileR = io.open("Stone", "r")
  287.         if SFileR == nil then
  288.             local CSFile = io.open("Stone", "a")
  289.             CSFile:write("10")
  290.             CSFile:close()
  291.             local SFileR = io.open("Stone", "r")
  292.             local Balance = SFileR:read("*l")
  293.             SFileR:close()
  294.             local SFileW = io.open("Stone", "w")
  295.             newBalanceS = Balance + 1
  296.             SFileW:write(newBalanceS)
  297.             io.write("Stone: UP ", newBalanceS, "$\n")
  298.             SFileW:close()
  299.         else
  300.             local Balance = SFileR:read("*l")
  301.             SFileR:close()
  302.             local SFileW = io.open("Stone", "w")
  303.             newBalanceS = Balance + 1
  304.             SFileW:write(newBalanceS)
  305.             io.write("Stone: UP ", newBalanceS, "$\n")
  306.             SFileW:close()
  307.         end
  308.     end
  309.  
  310.     if Cobble <= 25 then
  311.         local CFileR = io.open("Cobble", "r")
  312.         if CFileR == nil then
  313.             local CCFile = io.open("Cobble", "a")
  314.             CCFile:write("5")
  315.             CCFile:close()
  316.             local CFileR = io.open("Cobble", "r")
  317.             local Balance = CFileR:read("*l")
  318.             CFileR:close()
  319.             local CFileW = io.open("Cobble", "w")
  320.             newBalanceC = Balance - 1
  321.             CFileW:write(newBalanceC)
  322.             io.write("Cobble: DOWN ", newBalanceC, "$\n")
  323.             CFileW:close()
  324.         else
  325.             local Balance = CFileR:read("*l")
  326.             CFileR:close()
  327.             local CFileW = io.open("Cobble", "w")
  328.             newBalanceC = Balance - 1
  329.             CFileW:write(newBalanceC)
  330.             io.write("Cobble: DOWN ", newBalanceC, "$\n")
  331.             CFileW:close()
  332.         end
  333.     elseif Cobble >= 26 and Cobble <= 51 then
  334.         local CFileR = io.open("Cobble", "r")
  335.         if CFileR == nil then
  336.             local CCFile = io.open("Cobble", "a")
  337.             CCFile:write("5")
  338.             CCFile:close()
  339.             local CFileR = io.open("Cobble", "r")
  340.             local Balance = CFileR:read("*l")
  341.             CFileR:close()
  342.             local CFileW = io.open("Cobble", "w")
  343.             newBalanceC = Balance
  344.             CFileW:write(newBalanceC)
  345.             io.write("Cobble: STAY ", newBalanceC, "$\n")
  346.             CFileW:close()
  347.         else
  348.             local Balance = CFileR:read("*l")
  349.             CFileR:close()
  350.             local CFileW = io.open("Cobble", "w")
  351.             newBalanceC = Balance
  352.             CFileW:write(newBalanceC)
  353.             io.write("Cobble: STAY ", newBalanceC, "$\n")
  354.             CFileW:close()
  355.         end
  356.     else
  357.         local CFileR = io.open("Cobble", "r")
  358.         if CFileR == nil then
  359.             local CCFile = io.open("Cobble", "a")
  360.             CCFile:write("5")
  361.             CCFile:close()
  362.             local CFileR = io.open("Cobble", "r")
  363.             local Balance = CFileR:read("*l")
  364.             CFileR:close()
  365.             local CFileW = io.open("Cobble", "w")
  366.             newBalanceC = Balance + 1
  367.             CFileW:write(newBalanceC)
  368.             io.write("Cobble: UP ", newBalanceC, "$\n")
  369.             CFileW:close()
  370.         else
  371.             local Balance = CFileR:read("*l")
  372.             CFileR:close()
  373.             local CFileW = io.open("Cobble", "w")
  374.             newBalanceC = Balance + 1
  375.             CFileW:write(newBalanceC)
  376.             io.write("Cobble: UP ", newBalanceC, "$\n")
  377.             CFileW:close()
  378.         end
  379.     end
  380.  
  381.     if DSI <= 25 then
  382.         local DSFileR = io.open("DSI", "r")
  383.         if DSFileR == nil then
  384.             local CDSFile = io.open("DSI", "a")
  385.             CDSFile:write("500")
  386.             CDSFile:close()
  387.             local DSFileR = io.open("DSI", "r")
  388.             local Balance = DSFileR:read("*l")
  389.             DSFileR:close()
  390.             local DSFileW = io.open("DSI", "w")
  391.             newBalanceDSI = Balance - 1
  392.             DSFileW:write(newBalanceDSI)
  393.             io.write("DSI: DOWN ", newBalanceDSI, "$\n")
  394.             DSFileW:close()
  395.         else
  396.             local Balance = DSFileR:read("*l")
  397.             DSFileR:close()
  398.             local DSFileW = io.open("DSI", "w")
  399.             newBalanceDSI = Balance - 1
  400.             DSFileW:write(newBalanceDSI)
  401.             io.write("DSI: DOWN ", newBalanceDSI, "$\n")
  402.             DSFileW:close()
  403.         end
  404.     elseif DSI >= 26 and DSI <= 51 then
  405.         local DSFileR = io.open("DSI", "r")
  406.         if DSFileR == nil then
  407.             local CDSFile = io.open("DSI", "a")
  408.             CDSFile:write("500")
  409.             CDSFile:close()
  410.             local DSFileR = io.open("DSI", "r")
  411.             local Balance = DSFileR:read("*l")
  412.             DSFileR:close()
  413.             local DSFileW = io.open("DSI", "w")
  414.             newBalanceDSI = Balance
  415.             DSFileW:write(newBalanceDSI)
  416.             io.write("DSI: STAY ", newBalanceDSI, "$\n")
  417.             DSFileW:close()
  418.         else
  419.             local Balance = DSFileR:read("*l")
  420.             DSFileR:close()
  421.             local DSFileW = io.open("DSI", "w")
  422.             newBalanceDSI = Balance
  423.             DSFileW:write(newBalanceDSI)
  424.             io.write("DSI: STAY ", newBalanceDSI, "$\n")
  425.             DSFileW:close()
  426.         end
  427.     else
  428.         local DSFileR = io.open("DSI", "r")
  429.         if DSFileR == nil then
  430.             local CDSFile = io.open("DSI", "a")
  431.             CDSFile:write("500")
  432.             CDSFile:close()
  433.             local DSFileR = io.open("DSI", "r")
  434.             local Balance = DSFileR:read("*l")
  435.             DSFileR:close()
  436.             local DSFileW = io.open("DSI", "w")
  437.             newBalanceDSI = Balance + 1
  438.             DSFileW:write(newBalanceDSI)
  439.             io.write("DSI: UP ", newBalanceDSI, "$\n")
  440.             DSFileW:close()
  441.         else
  442.             local Balance = DSFileR:read("*l")
  443.             DSFileR:close()
  444.             local DSFileW = io.open("DSI", "w")
  445.             newBalanceDSI = Balance + 1
  446.             DSFileW:write(newBalanceDSI)
  447.             io.write("DSI: UP ", newBalanceDSI, "$\n")
  448.             DSFileW:close()
  449.         end
  450.     end
  451.  
  452.     if DIL <= 25 then
  453.         local DIFileR = io.open("DIL", "r")
  454.         if DIFileR == nil then
  455.             local CDIFile = io.open("DIL", "a")
  456.             CDIFile:write("400")
  457.             CDIFile:close()
  458.             local DIFileR = io.open("DIL", "r")
  459.             local Balance = DIFileR:read("*l")
  460.             DIFileR:close()
  461.             local DIFileW = io.open("DIL", "w")
  462.             newBalanceDIL = Balance - 1
  463.             DIFileW:write(newBalanceDIL)
  464.             io.write("DIL: DOWN ", newBalanceDIL, "$\n")
  465.             DIFileW:close()
  466.         else
  467.             local Balance = DIFileR:read("*l")
  468.             DIFileR:close()
  469.             local DIFileW = io.open("DIL", "w")
  470.             newBalanceDIL = Balance - 1
  471.             DIFileW:write(newBalanceDIL)
  472.             io.write("DIL: DOWN ", newBalanceDIL, "$\n")
  473.             DIFileW:close()
  474.         end
  475.     elseif DIL >= 26 and DIL <= 51 then
  476.         local DIFileR = io.open("DIL", "r")
  477.         if DIFileR == nil then
  478.             local CDIFile = io.open("DIL", "a")
  479.             CDIFile:write("400")
  480.             CDIFile:close()
  481.             local DIFileR = io.open("DIL", "r")
  482.             local Balance = DIFileR:read("*l")
  483.             DIFileR:close()
  484.             local DIFileW = io.open("DIL", "w")
  485.             newBalanceDIL = Balance
  486.             DIFileW:write(newBalanceDIL)
  487.             io.write("DIL: STAY ", newBalanceDIL, "$\n")
  488.             DIFileW:close()
  489.         else
  490.             local Balance = DIFileR:read("*l")
  491.             DIFileR:close()
  492.             local DIFileW = io.open("DIL", "w")
  493.             newBalanceDIL = Balance
  494.             DIFileW:write(newBalanceDIL)
  495.             io.write("DIL: STAY ", newBalanceDIL, "$\n")
  496.             DIFileW:close()
  497.         end
  498.     else
  499.         local DIFileR = io.open("DIL", "r")
  500.         if DIFileR == nil then
  501.             local CDIFile = io.open("DIL", "a")
  502.             CDIFile:write("400")
  503.             CDIFile:close()
  504.             local DIFileR = io.open("DIL", "r")
  505.             local Balance = DIFileR:read("*l")
  506.             DIFileR:close()
  507.             local DIFileW = io.open("DIL", "w")
  508.             newBalanceDIL = Balance + 1
  509.             DIFileW:write(newBalanceDIL)
  510.             io.write("DIL: UP ", newBalanceDIL, "$\n")
  511.             DIFileW:close()
  512.         else
  513.             local Balance = DIFileR:read("*l")
  514.             DIFileR:close()
  515.             local DIFileW = io.open("DIL", "w")
  516.             newBalanceDIL = Balance + 1
  517.             DIFileW:write(newBalanceDIL)
  518.             io.write("DIL: UP ", newBalanceDIL, "$\n")
  519.             DIFileW:close()
  520.         end
  521.     end
  522.  
  523.     table_to_send = {
  524.         Iron = newBalanceI,
  525.         Gold = newBalanceG,
  526.         Diamond = newBalanceD,
  527.         Stone = newBalanceS,
  528.         Cobble = newBalanceC,
  529.         DSI = newBalanceDSI,
  530.         DIL = newBalanceDIL
  531.     }
  532.  
  533.     local message_to_send = SER.serialize(table_to_send)
  534.     m.send(ServerS, PortO, message_to_send)
  535.  
  536.  
  537.     os.sleep(12)
  538.     term.clear()
  539. end
  540.  
Add Comment
Please, Sign In to add comment