Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pIM = peripheral.wrap("pim_7")
- pIMstorage = peripheral.wrap("ender_chest_5")
- pIMstorageDir = "south"
- pimDir = "north"
- function init_pIMstorage()
- while pIMstorage == nil do
- pIMstorage = peripheral.wrap("ender_chest_5")
- sleep(0.1)
- end
- end
- function init_pIM()
- while pIM == nil do
- pIM = peripheral.wrap("pim_7")
- end
- end
- function giveItemToPIM(name, qty)
- if qty == nil then
- qty = 1
- end
- init_pIMstorage()
- size = pIMstorage.getSizeInventory()
- for i = 0, size - 1 do
- local tableInfo = pIMstorage.getStackInSlot(i)
- if tableInfo ~= nil then
- if tableInfo["name"] == name then
- pIM.pull(pimDir, i, qty)
- end
- end
- end
- end
- function deductFunds(fee)
- local ret = {0,0,0,0,0}
- init_pIM()
- size = pIM.getSizeInventory()
- for i = 0, size-1 do
- local tableInfo = pIM.getStackInSlot(i)
- if tableInfo ~= nil then
- if tableInfo["id"] == 22256 then --We have a credit
- --print("----" .. tostring(tableInfo["name"]))
- if tableInfo["dmg"] > 0 then
- ret[tableInfo["dmg"]+1] = ret[tableInfo["dmg"]+1] + tableInfo["qty"]
- else
- ret[1] = ret[1] + tableInfo["qty"]
- end
- elseif tableInfo["id"] == 30186 then
- -- print("----" .. tostring(tableInfo["name"]))
- ret[2] = ret[2] + tableInfo["qty"]
- end
- end
- end
- tFee = fee
- coinV = {0.125, 1, 8, 64, 512}
- temp = {0,0,0,0,0}
- for i = 1, 5 do
- while tFee >= coinV[6-i] and ret[6-i] > 0 do
- if tFee >= coinV[6-i] then
- ret[6-i] = ret[6-i] - 1
- tFee = tFee - coinV[6 - i]
- temp[6-i] = temp[6-i] + 1
- end
- end
- end
- if tFee > 0 then
- print("Not enough funds!")
- return false
- else
- for i = 0, size -1 do
- local tableInfo = pIM.getStackInSlot(i)
- if tableInfo ~= nil then
- dmg = tonumber(tableInfo["dmg"])
- qty = tonumber(tableInfo["qty"])
- if tableInfo["id"] == 22256 then --We have a credit
- if dmg > 0 then
- m = math.min(qty, temp[dmg+1])
- else
- m = math.min(qty, temp[1])
- end
- if pIM.push(pimDir, i, m) then
- if dmg > 0 then
- temp[dmg+1] = temp[dmg+1] - m
- else
- temp[1] = temp[1] - m
- end
- end
- elseif tableInfo["id"] == 30186 then
- m = math.min(qty, temp[2])
- if pIM.push(pimDir, i, m) then
- temp[2] = temp[2] - m
- end
- end
- end
- end
- for i = 1, 5 do
- if temp[i] > 0 then
- print("Failing b/c t: " .. temp[i])
- return false
- end
- end
- return true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement