SHOW:
|
|
- or go back to the newest paste.
1 | local me = nil | |
2 | local pim = nil | |
3 | -------------------------------------------------------- | |
4 | --> Key Names <-- | |
5 | -------------------------------------------------------- | |
6 | - | key_name = nil |
6 | + | key_name = string.char(194) .. string.char(167) .. string.char(108) .. "Vote Crate Key" |
7 | - | l_key_name = nil |
7 | + | |
8 | - | if fs.exists("/keyNames") then |
8 | + | |
9 | - | local list = gcapi.getListFromFile("/keyNames") |
9 | + | |
10 | - | key_name = list["key_name"] |
10 | + | |
11 | - | l_key_name = list["l_key_name"] |
11 | + | |
12 | - | else |
12 | + | |
13 | - | error("You need to create the keyNames file with the names of the keys ({key_name and l_key_name})") |
13 | + | |
14 | local keys_qty = math.floor((price/100)+0.5) | |
15 | if keys_qty < 1 then | |
16 | keys_qty = 1 | |
17 | end | |
18 | return keys_qty | |
19 | end | |
20 | ||
21 | function withdraw(price) | |
22 | local keys_qty = priceToKeys(price) | |
23 | local ok, err = moveKeysToSystem(keys_qty) | |
24 | return ok, err | |
25 | end | |
26 | ||
27 | function getKeysInInventory() | |
28 | local id = 131 | |
29 | local name = key_name | |
30 | ||
31 | local qty = 0 | |
32 | for i,item in pairs(pim.getAllStacks()) do | |
33 | if item["id"] == 131 then | |
34 | if item["name"] == name then | |
35 | if item["ench"] ~= nil then | |
36 | if item["ench"][1] ~= nil and item["ench"][1] == "Unbreaking I" then | |
37 | qty = qty + item["qty"] | |
38 | end | |
39 | end | |
40 | end | |
41 | end | |
42 | end | |
43 | ||
44 | return qty | |
45 | end | |
46 | ||
47 | function moveKeysToSystem(amount) | |
48 | local name = key_name | |
49 | if amount > getKeysInInventory() then | |
50 | return false, "Not enough keys!" | |
51 | end | |
52 | local qty = 0 | |
53 | for i,item in pairs(pim.getAllStacks()) do | |
54 | if item["id"] == 131 then | |
55 | if item["name"] == name then | |
56 | if item["ench"] ~= nil then | |
57 | if item["ench"][1] ~= nil and item["ench"][1] == "Unbreaking I" then | |
58 | local keysMoved = me.insertItem(i, amount, "up") | |
59 | qty = qty + keysMoved | |
60 | amount = amount - keysMoved | |
61 | end | |
62 | end | |
63 | end | |
64 | end | |
65 | end | |
66 | return qty | |
67 | end |