Advertisement
MavricMC

ATM Pull API

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