Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local me = nil
- local pim = nil
- --------------------------------------------------------
- --> Key Names <--
- --------------------------------------------------------
- key_name = nil
- l_key_name = nil
- if fs.exists("/keyNames") then
- local list = gcapi.getListFromFile("/keyNames")
- key_name = list["key_name"]
- l_key_name = list["l_key_name"]
- else
- error("You need to create the keyNames file with the names of the keys ({key_name and l_key_name})")
- end
- function setup(pimP, meP)
- pim = pimP
- me = meP
- end
- function priceToKeys(price)
- local keys_qty = math.floor((price/100)+0.5)
- if keys_qty < 1 then
- keys_qty = 1
- end
- return keys_qty
- end
- function withdraw(price)
- local keys_qty = priceToKeys(price)
- local ok, err = moveKeysToSystem(keys_qty)
- return ok, err
- end
- function getKeysInInventory()
- local id = 131
- local name = key_name
- local qty = 0
- for i,item in pairs(pim.getAllStacks()) do
- if item["id"] == 131 then
- if item["name"] == name then
- if item["ench"] ~= nil then
- if item["ench"][1] ~= nil and item["ench"][1] == "Unbreaking I" then
- qty = qty + item["qty"]
- end
- end
- end
- end
- end
- return qty
- end
- function moveKeysToSystem(amount)
- local name = key_name
- if amount > getKeysInInventory() then
- return false, "Not enough keys!"
- end
- local qty = 0
- for i,item in pairs(pim.getAllStacks()) do
- if item["id"] == 131 then
- if item["name"] == name then
- if item["ench"] ~= nil then
- if item["ench"][1] ~= nil and item["ench"][1] == "Unbreaking I" then
- local keysMoved = me.insertItem(i, amount, "up")
- qty = qty + keysMoved
- amount = amount - keysMoved
- end
- end
- end
- end
- end
- return qty
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement