UrsaMauris

Construction Company misc pc

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