1-- Znote Shop for Znote AAC on OTHire (7.72).
2-- Player types !shop to receive the orders bought on the website.
3--
4-- OTHire is a 7.72 server: there are no mounts and no addon system, so only
5-- order type 1 (items) and a plain type 5 (outfit look type, addon ignored by
6-- the client) are handled here. Premium / gender / name orders (2, 3, 4) are
7-- applied by the website.
8
9function onSay(cid, words, param)
10 local storage = 54073 -- unused storage, throttles !shop against SQL spam
11 local cooldown = 15 -- seconds
12
13 if getPlayerStorageValue(cid, storage) > os.time() then
14 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can use !shop again in " .. (getPlayerStorageValue(cid, storage) - os.time()) .. " seconds.")
15 return false
16 end
17 setPlayerStorageValue(cid, storage, os.time() + cooldown)
18
19 local accid = getAccountNumberByPlayerName(getCreatureName(cid))
20 local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. accid .. ";")
21 if orderQuery == false then
22 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.")
23 return false
24 end
25
26 local served = false
27 repeat
28 local q_id = result.getDataInt(orderQuery, "id")
29 local q_type = result.getDataInt(orderQuery, "type")
30 local q_itemid = result.getDataInt(orderQuery, "itemid")
31 local q_count = result.getDataInt(orderQuery, "count")
32
33 -- ORDER TYPE 1 (items)
34 if q_type == 1 then
35 served = true
36 if getPlayerFreeCap(cid) >= getItemWeight(q_itemid, q_count) then
37 db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
38 doPlayerAddItem(cid, q_itemid, q_count)
39 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received " .. q_count .. " " .. getItemName(q_itemid) .. "(s)!")
40 else
41 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You need more capacity to carry this order!")
42 end
43 end
44
45 -- ORDER TYPE 5 (outfit look type; addon bit is ignored on 7.72)
46 if q_type == 5 then
47 served = true
48 local itemid = q_itemid
49 local outfits = {}
50 if itemid > 1000 then
51 local first = math.floor(itemid / 1000)
52 table.insert(outfits, first)
53 itemid = itemid - (first * 1000)
54 end
55 table.insert(outfits, itemid)
56
57 for _, outfitId in pairs(outfits) do
58 if not canPlayerWearOutfit(cid, outfitId, q_count) then
59 db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
60 doPlayerAddOutfit(cid, outfitId, q_count)
61 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
62 else
63 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this outfit!")
64 end
65 end
66 end
67
68 -- Type 6 (mounts) and 7 (houses) do not exist on 7.72 / OTHire.
69 until not result.next(orderQuery)
70 result.free(orderQuery)
71
72 if not served then
73 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
74 end
75 return false
76end
77