UrsaMauris

home pc

Apr 9th, 2017
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.70 KB | None | 0 0
  1. function show()
  2.   term.clear()
  3.   term.setCursorPos(1, 1)
  4.            
  5.   for slot = 1, 5 do
  6.   if mytable[slot] ~= 0 then
  7.     print("Objednavka je: " .. mytable[slot][1] .. "x " .. mytable[slot][2] .. " za " .. mytable[slot][3] .. " kreditu.")
  8.     print("Cilovym podnikem je " .. mytable[slot][6] .. ".")
  9.     print(" ----------------------------------------")
  10.   else print("volno")
  11.   end
  12.  end
  13. end
  14.  
  15. -- core  
  16. if fs.exists("tabledata") then
  17.   fileH = fs.open("tabledata", "r")
  18.   dataTL = fileH.readAll()
  19.   fileH.close()
  20.   mytable = textutils.unserialize(dataTL)
  21.   show()
  22.  
  23. else mytable = {}
  24.  mytable[1] = 0             -- kolikrat
  25.  mytable[2] = 0             -- co
  26.  mytable[3] = 0             -- cena
  27.  mytable[4] = 0             -- ID restaurace
  28.  mytable[5] = 0             -- F nebo M
  29.  mytable[6] = 0             -- podnik
  30. end
  31.  
  32. rednet.open("top")
  33. while true do
  34.   local id, msg, protocol = rednet.receive("offer")
  35.   temp = textutils.unserialize(msg)
  36.   if temp[5] == "F" then
  37.    
  38.     if mytable[1] ~= 0 and
  39.        mytable[1][4] == temp[4] then
  40.         mytable[1] = 0
  41.          fileHS = fs.open("tabledata", "w")
  42.          fileHS.write(textutils.serialize(mytable))
  43.          fileHS.close()
  44.    
  45.          fileH = fs.open("tabledata", "r")
  46.          dataTL = fileH.readAll()
  47.          fileH.close()
  48.          mytable = textutils.unserialize(dataTL)
  49.         show()  
  50.          
  51.     elseif mytable[2] ~= 0 and
  52.       mytable[2][4] == temp[4] then
  53.         mytable[2] = 0
  54.          fileHS = fs.open("tabledata", "w")
  55.          fileHS.write(textutils.serialize(mytable))
  56.          fileHS.close()
  57.  
  58.          fileH = fs.open("tabledata", "r")
  59.          dataTL = fileH.readAll()
  60.          fileH.close()
  61.          mytable = textutils.unserialize(dataTL)
  62.         show()
  63.          
  64.     elseif mytable[1] == 0 then
  65.       mytable[1] = textutils.unserialize(msg)
  66.        fileHS = fs.open("tabledata", "w")
  67.        fileHS.write(textutils.serialize(mytable))
  68.        fileHS.close()
  69.  
  70.        fileH = fs.open("tabledata", "r")
  71.        dataTL = fileH.readAll()
  72.        fileH.close()
  73.        mytable = textutils.unserialize(dataTL)
  74.       show()
  75.  
  76.     elseif mytable[2] == 0 then
  77.       mytable[2] = textutils.unserialize(msg)
  78.        fileHS = fs.open("tabledata", "w")
  79.        fileHS.write(textutils.serialize(mytable))
  80.        fileHS.close()
  81.  
  82.        fileH = fs.open("tabledata", "r")
  83.        dataTL = fileH.readAll()
  84.        fileH.close()
  85.        mytable = textutils.unserialize(dataTL)
  86.       show()
  87.    
  88.     else rednet.open("top")
  89.     rednet.send(temp[4], "full")          
  90.     end
  91.  
  92.  elseif temp[5] == "M" then
  93.  
  94.    if mytable[3] ~= 0 and
  95.      mytable[3][4] == temp[4] then
  96.        mytable[3] = 0
  97.         fileHS = fs.open("tabledata", "w")
  98.         fileHS.write(textutils.serialize(mytable))
  99.         fileHS.close()
  100.  
  101.         fileH = fs.open("tabledata", "r")
  102.         dataTL = fileH.readAll()
  103.         fileH.close()
  104.         mytable = textutils.unserialize(dataTL)
  105.        show()  
  106.        
  107.    elseif mytable[4] ~= 0 and
  108.      mytable[4][4] == temp[4] then
  109.        mytable[4] = 0
  110.         fileHS = fs.open("tabledata", "w")
  111.         fileHS.write(textutils.serialize(mytable))
  112.         fileHS.close()
  113.  
  114.         fileH = fs.open("tabledata", "r")
  115.         dataTL = fileH.readAll()
  116.         fileH.close()
  117.         mytable = textutils.unserialize(dataTL)
  118.        show()
  119.          
  120.    elseif mytable[5] ~= 0 and
  121.      mytable[5][4] == temp[4] then
  122.        mytable[5] = 0
  123.         fileHS = fs.open("tabledata", "w")
  124.         fileHS.write(textutils.serialize(mytable))
  125.         fileHS.close()
  126.  
  127.         fileH = fs.open("tabledata", "r")
  128.         dataTL = fileH.readAll()
  129.         fileH.close()
  130.         mytable = textutils.unserialize(dataTL)
  131.        show()
  132.        
  133.    elseif mytable[3] == 0 then
  134.      mytable[3] = textutils.unserialize(msg)
  135.       fileHS = fs.open("tabledata", "w")
  136.       fileHS.write(textutils.serialize(mytable))
  137.       fileHS.close()
  138.  
  139.       fileH = fs.open("tabledata", "r")
  140.       dataTL = fileH.readAll()
  141.       fileH.close()
  142.       mytable = textutils.unserialize(dataTL)
  143.      show()  
  144.    
  145.    elseif mytable[4] == 0 then
  146.      mytable[4] = textutils.unserialize(msg)
  147.       fileHS = fs.open("tabledata", "w")
  148.       fileHS.write(textutils.serialize(mytable))
  149.       fileHS.close()
  150.  
  151.       fileH = fs.open("tabledata", "r")
  152.       dataTL = fileH.readAll()
  153.       fileH.close()
  154.       mytable = textutils.unserialize(dataTL)
  155.      show()
  156.      
  157.    elseif mytable[5] == 0 then
  158.      mytable[5] = textutils.unserialize(msg)
  159.       fileHS = fs.open("tabledata", "w")
  160.       fileHS.write(textutils.serialize(mytable))
  161.       fileHS.close()
  162.  
  163.       fileH = fs.open("tabledata", "r")
  164.       dataTL = fileH.readAll()
  165.       fileH.close()
  166.       mytable = textutils.unserialize(dataTL)
  167.      show()                    
  168.    end
  169.  end
  170. end
Add Comment
Please, Sign In to add comment