zhiyan114

Universal Coin Auto-Debt Collector

Apr 20th, 2021 (edited)
1,523
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local sides = require("sides")
  3. component.redstone.setOutput(sides.left,0) -- Set redstone signal
  4. local inventory = component.inventory_controller
  5. component.inventory_controller.getStackInSlot(sides.left,1) -- Get the hopper's item count
  6. local CoinName = function(short)
  7.     return "universalcoins:item."..tostring(short):lower().."_coin"
  8. end
  9. print("Service available, please start depositing...")
  10. while(true) do
  11.     os.sleep()
  12.     if(inventory.getStackInSlot(sides.left,1)) then
  13.         -- Something is in the hopper, let process it
  14.         local file = io.open("debt.txt","r")
  15.         local owed = tonumber(file:read())
  16.         file:close()
  17.         print("coins are detected, press enter when you're ready for it to process... \n")
  18.         print("Please note that the more coins you despoit, the longer it will take to process so please avoid using the smaller valued coin when possible. \n")
  19.         print("Your current debt is "..owed)
  20.         io.read()
  21.         os.sleep(0.4)
  22.         print("coins are now being processed, please do not add additional coins as it will not be credited...")
  23.         local deposit = 0;
  24.         local itemcount = 0;
  25.         for slotid=1,inventory.getInventorySize(sides.left) do
  26.             local slot = inventory.getStackInSlot(sides.left,slotid)
  27.             if(slot) then
  28.                 if(CoinName("iron") == slot["name"]:lower()) then
  29.                     deposit=deposit+(1*slot["size"])
  30.                     itemcount=itemcount+slot["size"]
  31.                 elseif(CoinName("gold") == slot["name"]:lower()) then
  32.                     deposit=deposit+(10*slot["size"])
  33.                     itemcount=itemcount+slot["size"]
  34.                 elseif(CoinName("emerald") == slot["name"]:lower()) then
  35.                     deposit=deposit+(100*slot["size"])
  36.                     itemcount=itemcount+slot["size"]
  37.                 elseif(CoinName("diamond") == slot["name"]:lower()) then
  38.                     deposit=deposit+(1000*slot["size"])
  39.                     itemcount=itemcount+slot["size"]
  40.                 elseif(CoinName("obsidian") == slot["name"]:lower()) then
  41.                     deposit=deposit+(10000*slot["size"])
  42.                     itemcount=itemcount+slot["size"]
  43.                 else
  44.                     print("Item "..slot["label"].." was deposited and will not be returned or count as credit")
  45.                     itemcount=itemcount+slot["size"]
  46.                 end
  47.             end
  48.         end
  49.         -- Finalizing the stuff and depositing the items
  50.         component.redstone.setOutput(sides.left,16)
  51.         os.sleep((0.4*itemcount)+1)
  52.         component.redstone.setOutput(sides.left,0)
  53.         file = io.open("debt.txt","w")
  54.         file:write(tostring(owed-deposit))
  55.         file:close()
  56.         print("Thank you for waiting, here is the result:")
  57.         print("Total Deposit: "..deposit)
  58.         print("Your new debt: "..owed-deposit)
  59.         print("-------------------------")
  60.         print("Service available, please start depositing...")
  61.     end
  62. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×