MatthewGB

CC LogiPipes Seller

Sep 10th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.75 KB | None | 0 0
  1. ItemList = {}
  2. SellablesList = {}
  3. AddItem = function(ID, Name, EMC)
  4.  Info = {}
  5.  Info["ID"] = ID
  6.  Info["Name"] = Name
  7.  Info["EMC"] = EMC
  8.  Info["$"] = EMC/100
  9.  table.insert(ItemList, Info)
  10. end
  11. AddItem(264, "Diamond", 8192)
  12. AddItem(351.4, "Lapis Lazuli", 864)
  13. AddItem(265, "Iron Ingot", 256)
  14. AddItem(266, "Gold Ingot", 2048)
  15. AddItem(369, "Blaze Rod", 1536)
  16. AddItem(4696.2, "Tin Ingot", 256)
  17. AddItem(4362, "Copper Ingot", 256)
  18. AddItem(331, "Redstone", 64)
  19. AddItem(57, "Diamond Block", 73728)
  20. AddItem(4336, "Coal Dust", 64)
  21. AddItem(4271, "IC2 Electronic Circuit", 1344)
  22. AddItem(4270, "IC2 Advanced Circuit", 4096)
  23. AddItem(225.3, "IC2 Solar Panel", 6155)
  24. AddItem(225, "IC2 Generator", 3238)
  25. AddItem(566, "EE3 Energy Condenser", 40000)
  26.  
  27. GetInfoItem = function(ID)
  28.  for key, value in ipairs(ItemList) do
  29.   if value["ID"] == ID then
  30.    return value
  31.   end
  32.  end
  33. end
  34.  
  35. NumFormat = function(num)
  36.  if(num > 1000000) then
  37.   return tostring(math.floor(num/10000)/100).."M"
  38.  end
  39.  if(num > 1000) then
  40.   return tostring(math.floor(num/100)/10).."K"
  41.  end
  42.  return tostring(num).."U"
  43. end
  44. r = peripheral.wrap("back")
  45. MakeRequest = function(ID, amnt)
  46.  local result = r.getLP().getItemIdentifierBuilder()
  47.  result.setItemID(ID)
  48.  ID2 = result.build()
  49.  r.makeRequest(ID2, amnt)
  50.  print("Requested "..tostring(amnt).." of ID"..tostring(ID).." from logi network")
  51. end
  52. GetEMC = function(ID)
  53.  return r.getItemAmount(ID)*73728
  54. end
  55. GetItems = function(NumID)
  56.  local result = r.getLP().getItemIdentifierBuilder()
  57.  result.setItemID(NumID)
  58.  ID2 = result.build()
  59.  return r.getItemAmount(ID2)
  60. end
  61. ItemAmountList = {}
  62. tosay = "Items for sale:                . indicates decimal \n"
  63. for key, value in ipairs(ItemList) do
  64.  amnt = GetItems(value["ID"])
  65.  if amnt > 0 then
  66.   tosay = tosay.."|"..value["Name"].."(ID"..value["ID"]..")($"..value["$"].." each)"
  67.  end
  68.  if ItemList[10000] ~= nil then
  69.   SellableItem = {}
  70.   SellableItem["Name"] = ItemList[i]["name"]
  71.   SellableItem["ID"] = ItemList[i]["ID"]
  72.   SellableItem["EMC"] = ItemList[i]["EMC"]
  73.   SellableItem["Amount"] = amnt
  74.   table.insert(SellablesList, SellableItem)
  75.  end
  76. end
  77. print("MINIMUM ORDER $100")
  78. cart = {}
  79. done = false
  80. subtotal = 0
  81. while done == false do
  82.  print(tosay)
  83.  os.sleep(2)
  84.  print()
  85.  print("Cart: ")
  86.  subtotal = 0
  87.  for key, value in ipairs(cart) do
  88.   print("ID: "..value["ID"].." Amnt: "..value["Amnt"].." Price $"..value["$"])
  89.   subtotal = subtotal + value["$"]
  90.  end
  91.  print("Subtotal: "..subtotal)
  92.  print()
  93.  print("What item ID would you like to order? (Enter r to restart, c for checkout)")
  94.  cmd = read()
  95.  if cmd == "r" then
  96.   os.reboot()
  97.  end
  98.  if cmd == "c" then
  99.   done = true
  100.  else
  101.   ID = tonumber(cmd)
  102.   if GetItems(ID) ~= 0 then
  103.    print("You can order up to "..tostring(GetItems(ID))..". How many do you want?")
  104.    amnt = tonumber(read())
  105.    itemtoadd = {}
  106.    itemtoadd["ID"] = ID
  107.    itemtoadd["Amnt"] = amnt
  108.    itemtoadd["$"] = GetInfoItem(ID)["$"]*amnt
  109.    table.insert(cart, itemtoadd)
  110.   else
  111.    print("Sorry, none in stock")
  112.   end
  113.  end
  114. end
  115. total = math.ceil(subtotal/100)*100
  116. dirtinchest = GetItems(3)
  117. print("You must now pay $"..tostring(total))
  118. print("Buy "..tostring(total/100).." dirt from the chest (This is just the method of payment, don't worry you'll receive your items in the cart once you've paid)")
  119. targetdirtinchest = dirtinchest-(total/100)
  120. print(dirtinchest)
  121. print(targetdirtinchest)
  122. while GetItems(3) ~= targetdirtinchest do
  123.  dirtinchest = GetItems(3)
  124.  print(tostring(dirtinchest-targetdirtinchest).." more...")
  125.  os.sleep(2)
  126. end
  127. print("Payment complete! Requesting order from logi system...")
  128. for key, value in ipairs(cart) do
  129.  MakeRequest(value["ID"], value["Amnt"])
  130. end
  131. print("Your items should arrive in a few moments. Thanks for shopping at MatthewGB's!")
Add Comment
Please, Sign In to add comment