MavricMC

ATM Pull API

Apr 16th, 2022 (edited)
1,925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. --ATM version 0.0.8--
  2. --Depricated. All in main file now
  3. --Must be called pullapi.lua--
  4.  
  5. local chests = {"minecraft:chest_0"}
  6.  
  7. local dropper = "minecraft:dropper_0"
  8. local junk = "minecraft:dropper_1"
  9.  
  10. local coin = "minecraft:diamond"
  11.  
  12. local d = peripheral.wrap(dropper)
  13. local j = peripheral.wrap(junk)
  14.  
  15.  
  16. function getStored()
  17.     local count = 0
  18.     for k, v in pairs(chests) do
  19.         cs = peripheral.wrap(v)
  20.         for k2, v2 in pairs(cs.list()) do
  21.             if v2.name == coin then
  22.                 count = count + v2.count
  23.             else
  24.                 j.pullItems(v, k2, v2.count)
  25.             end
  26.         end
  27.     end
  28.     return count
  29. end
  30.  
  31. function deposit()
  32.     local count = 0
  33.     for k, v in pairs(chests) do
  34.         for i = 1, 9 do
  35.             local tab = d.getItemDetail(i)
  36.             if tab ~= nil then
  37.                 if tab.name == coin then
  38.                     local deped = d.pushItems(v, i, 64)
  39.                     count = count + deped
  40.                 else
  41.                     d.pushItems(junk, i, 64)
  42.                 end
  43.             end
  44.         end
  45.     end
  46.     if count > 0 then
  47.         return true, count
  48.     else
  49.         return false, "Diamonds enterd must be more than 0"
  50.     end
  51. end
  52.  
  53. function withdraw(amount)
  54.     if amount > 576 then
  55.         return false, "amount must be at maximum 9 stacks or 576 items"
  56.     end
  57.     if amount > getStored() then
  58.         return false, "not enough money in storage"
  59.     end
  60.    
  61.     local count = 0
  62.     for k, v in pairs(chests) do
  63.         cs = peripheral.wrap(v)
  64.         for i = 1, 54 do
  65.             tab = cs.getItemDetail(i)
  66.             if tab ~= nil then
  67.                 if tab.name == coin then
  68.                     if (count + tab.count) > amount then
  69.                         d.pullItems(v, i, (amount - count))
  70.                         return true
  71.                     else
  72.                         d.pullItems(v, i, tab.count)
  73.                         count = count + tab.count
  74.                     end
  75.                     if count == amount then
  76.                         return true
  77.                     end
  78.                 else
  79.                     j.pullItems(chests, i, 64)
  80.                 end
  81.             end
  82.         end
  83.     end
  84. end
  85.  
Advertisement
Add Comment
Please, Sign In to add comment