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