1-- Znote Shop v1.1 for Znote AAC on TFS 0.3.6+ Crying Damson. [Alternative]
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 repeat
27 -- Fetch order values
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 local description = "Unknown or custom type"
34 if type_desc[q_type] ~= nil then
35 description = type_desc[q_type]
36 end
37 print("Processing type "..q_type..": ".. description)
38
39 -- ORDER TYPE 1 (Regular item shop products)
40 if q_type == 1 then
41 served = true
42 -- Get wheight
43 local playerCap = getPlayerFreeCap(cid)
44 local itemweight = getItemWeightById(q_itemid, q_count)
45 if playerCap >= itemweight then
46 local delete = db.storeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
47 result.free(delete)
48 doPlayerAddItem(cid, q_itemid, q_count)
49 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have recieved ".. q_count .." "..getItemNameById(q_itemid).."(s)!")
50 else
51 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Need more CAP!")
52 end
53 end
54 -- ORDER TYPE 5 (Outfit and addon)
55 if q_type == 5 then
56 served = true
57
58 local itemid = q_itemid
59 local outfits = {}
60
61 if itemid > 1000 then
62 local first = math.floor(itemid/1000)
63 table.insert(outfits, first)
64 itemid = itemid - (first * 1000)
65 end
66 table.insert(outfits, itemid)
67
68 for _, outfitId in pairs(outfits) do
69 -- Make sure player don't already have this outfit and addon
70 if not canPlayerWearOutfit(cid, outfitId, q_count) then
71 local delete = db.storeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
72 result.free(delete)
73 doPlayerAddOutfit(cid,outfitId,q_count)
74 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
75 else
76 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
77 end
78 end
79 end
80
81 -- ORDER TYPE 6 (Mounts)
82 if q_type == 6 then
83 served = true
84 -- Make sure player don't already have this outfit and addon
85 if not getPlayerMount(cid, q_itemid) then -- Failed to find a proper hasMount 0.3 function?
86 local delete = db.storeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
87 result.free(delete)
88 doPlayerAddMount(cid, q_itemid)
89 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new mount!")
90 else
91 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this mount!")
92 end
93 end
94
95 -- Add custom order types here
96 -- Type 1 is for itemids (Already coded here)
97 -- Type 2 is for premium (Coded on web)
98 -- Type 3 is for gender change (Coded on web)
99 -- Type 4 is for character name change (Coded on web)
100 -- Type 5 is for character outfit and addon (Already coded here)
101 -- Type 6 is for mounts (Already coded here)
102 -- Type 7 is for Instant house purchase (Not for TFS 0.3)
103 -- So use type 8+ for custom stuff, like etc packages.
104 -- if q_type == 8 then
105 -- end
106 until not result.next(orderQuery)
107 result.free(orderQuery)
108 if not served then
109 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
110 end
111 else
112 doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.")
113 end
114 else
115 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time())
116 end
117 return false
118end
119