1-- Znote Shop v1.1 for Znote AAC on TFS 0.2.13+ Mystic Spirit.
2function onSay(cid, words, param)
3 local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks.
4 local cooldown = 15 -- in seconds.
5
6 if getPlayerStorageValue(cid, storage) <= os.time() then
7 setPlayerStorageValue(cid, storage, os.time() + cooldown)
8 local accid = getAccountNumberByPlayerName(getCreatureName(cid))
9
10 local type_desc = {
11 "itemids",
12 "pending premium (skip)",
13 "pending gender change (skip)",
14 "pending character name change (skip)",
15 "Outfit and addons",
16 "Mounts",
17 "Instant house purchase"
18 }
19 print("Player: " .. getCreatureName(cid) .. " triggered !shop talkaction.")
20 -- Create the query
21 local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. accid .. ";")
22 local served = false
23
24 -- Detect if we got any results
25 if orderQuery ~= false then
26 -- Fetch order values
27 local q_id = result.getDataInt(orderQuery, "id")
28 local q_type = result.getDataInt(orderQuery, "type")
29 local q_itemid = result.getDataInt(orderQuery, "itemid")
30 local q_count = result.getDataInt(orderQuery, "count")
31
32 local description = "Unknown or custom type"
33 if type_desc[q_type] ~= nil then
34 description = type_desc[q_type]
35 end
36 print("Processing type "..q_type..": ".. description)
37
38 -- ORDER TYPE 1 (Regular item shop products)
39 if q_type == 1 then
40 served = true
41 -- Get weight
42 local playerCap = getPlayerFreeCap(cid)
43 local itemweight = getItemWeight(q_itemid, q_count)
44 if playerCap >= itemweight then
45 db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
46 doPlayerAddItem(cid, q_itemid, q_count)
47 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received ".. q_count .." "..getItemName(q_itemid).."(s)!")
48 else
49 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Need more CAP!")
50 end
51 end
52 -- ORDER TYPE 5 (Outfit and addon)
53 if q_type == 5 then
54 served = true
55
56 local itemid = q_itemid
57 local outfits = {}
58
59 if itemid > 1000 then
60 local first = math.floor(itemid/1000)
61 table.insert(outfits, first)
62 itemid = itemid - (first * 1000)
63 end
64 table.insert(outfits, itemid)
65
66 for _, outfitId in pairs(outfits) do
67 -- Make sure player don't already have this outfit and addon
68 if not canPlayerWearOutfit(cid, outfitId, q_count) then
69 db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
70 doPlayerAddOutfit(cid,outfitId,q_count)
71 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
72 else
73 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
74 end
75 end
76 end
77
78 -- ORDER TYPE 6 (Mounts)
79 -- Not supported on TFS 0.2
80
81 -- Add custom order types here
82 -- Type 1 is for itemids (Already coded here)
83 -- Type 2 is for premium (Coded on web)
84 -- Type 3 is for gender change (Coded on web)
85 -- Type 4 is for character name change (Coded on web)
86 -- Type 5 is for character outfit and addon (Already coded here)
87 -- Type 6 is for mounts (Not for TFS 0.2)
88 -- Type 7 is for Instant house purchase (Not for TFS 0.2)
89 -- So use type 8+ for custom stuff, like etc packages.
90 -- if q_type == 8 then
91 -- end
92 result.free(orderQuery)
93 if not served then
94 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
95 end
96 else
97 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.")
98 end
99 else
100 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time())
101 end
102 return false
103end
104