Advertisement
UrsaMauris

Construction Company alt

Jun 3rd, 2017
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local slot = 0
  2. local myID = os.getComputerID()
  3.  
  4. while true do
  5.  if fs.exists("currentoffer") then
  6.    
  7.    fileCO = fs.open("currentoffer", "r")
  8.    local line = fileCO.readAll()
  9.    fileCO.close()
  10.    offertable = textutils.unserialize(line)
  11.    
  12.    pocet = offertable[1]
  13.    jidlo = offertable[2]
  14.    cena = offertable[3]
  15.    
  16.    print("---------------------------")
  17.    print("Objednavka: ", pocet, jidlo)
  18.    print("Vyplata: ", cena, " kreditu.")
  19.     passwordD = "david"
  20.  passwordF = "filip"
  21.  
  22.  local heslonerozpoznano = true
  23.  while heslonerozpoznano do  
  24.    write("Heslo: ")
  25.    local input = read("*")
  26.    if input == passwordD
  27.    then
  28.       heslonerozpoznano = false
  29.       print ("Objednavka prijata. Na ucet David bylo pripsano " .. cena .. " kreditu.")
  30.       rednet.open("top")
  31.       rednet.broadcast("poptavka", "ucel")
  32.       rednet.broadcast("David","kdo")
  33.       rednet.broadcast(cena,"kolik")
  34.       slot = slot - 1
  35.       hotovot = {}
  36.  hotovot[4] = myID
  37.  hotovot[5] = "F"
  38.  local msg = textutils.serialize(hotovot)
  39.  rednet.open("top")
  40.  rednet.broadcast(msg, "offer")
  41.  fs.delete("currentoffer")
  42.  sleep(3)
  43.      
  44.    elseif input == passwordF
  45.    then
  46.       heslonerozpoznano = false
  47.       print ("Objednavka prijata. Na ucet Filip bylo pripsano " .. cena .. " kreditu.")
  48.       rednet.open("top")
  49.       rednet.broadcast("poptavka", "ucel")
  50.       rednet.broadcast("Filip","kdo")
  51.       rednet.broadcast(cena,"kolik")
  52.       slot = slot - 1
  53.       hotovot = {}
  54.  hotovot[4] = myID
  55.  hotovot[5] = "F"
  56.  local msg = textutils.serialize(hotovot)
  57.  rednet.open("top")
  58.  rednet.broadcast(msg, "offer")
  59.  fs.delete("currentoffer")
  60.  sleep(3)
  61.            
  62.    else print("Heslo nerozpoznano")
  63.    sleep(1)
  64.    end
  65.   end
  66.  
  67.  else
  68.    local vacancy = 1
  69.    while vacancy == 1 do
  70.     rednet.open("top")
  71.     while slot == 0 do
  72.    slot = slot + 1
  73.    n = math.random(1,18)
  74.    pocet = math.random(1, 4)
  75.    
  76.    if n == 1 then
  77.     slot = slot - 1
  78.          
  79.    elseif n == 2 then
  80.     jidlo = "stack(s) of strings"
  81.     cenajidla = 320
  82.        
  83.    elseif n == 3 then
  84.     jidlo = "stack(s) of wool"
  85.     cenajidla = 320
  86.            
  87.    elseif n == 4 then
  88.     jidlo = "stack(s) of stone"
  89.     cenajidla = 640
  90.        
  91.    elseif n == 5 then
  92.     jidlo = "stack(s) of glass"
  93.     cenajidla = 960
  94.    
  95.    elseif n == 6 then
  96.     jidlo = "stack(s) of sandstone"
  97.     cenajidla = 960
  98.    
  99.    elseif n == 7 then
  100.     jidlo = "stack(s) of acacia wood planks"
  101.     cenajidla = 320
  102.    
  103.    elseif n == 8 then
  104.     jidlo = "stack(s) of birch wood planks"
  105.     cenajidla = 320
  106.      
  107.    elseif n >= 9 and n<= 18 then
  108.    slot = slot - 1
  109.                
  110.   end
  111.   end
  112.  
  113.     vacancy = vacancy - 1
  114.      cena = cenajidla * pocet
  115.  local t = {}
  116.  t[1] = pocet
  117.  t[2] = jidlo
  118.  t[3] = cena
  119.  t[4] = myID
  120.  t[5] = "F"
  121.  t[6] = "Akka Constructions"
  122.  local msg = textutils.serialize(t)
  123.  rednet.open("top")
  124.  rednet.broadcast(msg, "offer")
  125.  
  126.  
  127.  local id, msg = rednet.receive(2)
  128.  if msg == "full" then
  129.    sleep(3)
  130.    slot = 0
  131.    
  132.  else
  133.    print("-----------------------------")
  134.    print("Objednavka: ", pocet, jidlo)
  135.    print("Vyplata: ", cena," kreditu.")
  136.    
  137.    local savetable = {}
  138.    cena = cenajidla * pocet
  139.    savetable[1] = pocet
  140.    savetable[2] = jidlo
  141.    savetable[3] = cena
  142.    
  143.    local fileWT = fs.open("currentoffer", "w")
  144.    fileWT.write(textutils.serialize(savetable))
  145.    fileWT.close()
  146.    
  147.     passwordD = "david"
  148.  passwordF = "filip"
  149.  
  150.  local heslonerozpoznano = true
  151.  while heslonerozpoznano do  
  152.    write("Heslo: ")
  153.    local input = read("*")
  154.    if input == passwordD
  155.    then
  156.       heslonerozpoznano = false
  157.       print ("Objednavka prijata. Na ucet David bylo pripsano " .. cena .. " kreditu.")
  158.       rednet.open("top")
  159.       rednet.broadcast("poptavka", "ucel")
  160.       rednet.broadcast("David","kdo")
  161.       rednet.broadcast(cena,"kolik")
  162.       slot = slot - 1
  163.       hotovot = {}
  164.  hotovot[4] = myID
  165.  hotovot[5] = "F"
  166.  local msg = textutils.serialize(hotovot)
  167.  rednet.open("top")
  168.  rednet.broadcast(msg, "offer")
  169.  fs.delete("currentoffer")
  170.  sleep(3)
  171.      
  172.    elseif input == passwordF
  173.    then
  174.       heslonerozpoznano = false
  175.       print ("Objednavka prijata. Na ucet Filip bylo pripsano " .. cena .. " kreditu.")
  176.       rednet.open("top")
  177.       rednet.broadcast("poptavka", "ucel")
  178.       rednet.broadcast("Filip","kdo")
  179.       rednet.broadcast(cena,"kolik")
  180.       slot = slot - 1
  181.       hotovot = {}
  182.  hotovot[4] = myID
  183.  hotovot[5] = "F"
  184.  local msg = textutils.serialize(hotovot)
  185.  rednet.open("top")
  186.  rednet.broadcast(msg, "offer")
  187.  fs.delete("currentoffer")
  188.  sleep(3)
  189.            
  190.    else print("Heslo nerozpoznano")
  191.    sleep(1)
  192.    end
  193.   end
  194.   end
  195.     vacancy = vacancy + 1
  196.    end
  197.   end      
  198.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement