SHOW:
|
|
- or go back to the newest paste.
1 | ||
2 | local Check = false -- true: Do not show items the player can't buy, false: show all vendor items in the list, even if the player does not have the mats. | |
3 | -- Set NPC entry at the bottom! | |
4 | - | -- {GivenItem, ReqItem1, ReqItem2, ... ReqItemN} |
4 | + | |
5 | - | {25, 35}, |
5 | + | |
6 | - | {25, 36}, |
6 | + | |
7 | - | {25, 37}, |
7 | + | |
8 | - | {25, 38}, |
8 | + | -- {{GivenItem, Amount}, {ReqItem1, Amount}, {ReqItem2, Amount}, ... {ReqItemN, Amount}} |
9 | - | {25, 39}, |
9 | + | {{25, 1}, {35, 1}}, |
10 | - | {25, 40}, -- Testing paging with item entry 40 |
10 | + | {{25, 1}, {36, 1}}, |
11 | - | {25, 40}, |
11 | + | {{25, 1}, {37, 1}}, |
12 | - | {25, 40}, |
12 | + | {{25, 1}, {38, 1}}, |
13 | - | {25, 40}, |
13 | + | {{25, 1}, {39, 1}}, |
14 | - | {25, 40}, |
14 | + | {{25, 2}, {40, 3}, {38, 1}, {39, 1}, {36, 4}}, -- Testing multiple req items |
15 | - | {25, 40}, |
15 | + | {{25, 1}, {40, 1}}, |
16 | - | {25, 40}, |
16 | + | {{25, 1}, {40, 1}}, |
17 | - | {25, 40}, |
17 | + | {{25, 1}, {40, 1}}, |
18 | - | {25, 40}, |
18 | + | {{25, 1}, {40, 1}}, |
19 | - | {25, 40}, |
19 | + | {{25, 1}, {40, 1}}, |
20 | - | {25, 40}, |
20 | + | {{25, 1}, {40, 1}}, |
21 | - | {25, 40}, |
21 | + | {{25, 1}, {40, 1}}, |
22 | - | {25, 40}, |
22 | + | {{25, 1}, {40, 1}}, |
23 | - | {25, 40}, |
23 | + | {{25, 1}, {40, 1}}, |
24 | - | {25, 40}, |
24 | + | {{25, 1}, {40, 1}}, |
25 | - | {25, 40}, |
25 | + | {{25, 1}, {40, 1}}, |
26 | - | {25, 40}, |
26 | + | {{25, 1}, {40, 1}}, |
27 | - | {25, 40}, |
27 | + | {{25, 1}, {40, 1}}, |
28 | - | {25, 40}, |
28 | + | {{25, 1}, {40, 1}}, |
29 | - | {25, 40}, |
29 | + | {{25, 1}, {40, 1}}, |
30 | - | {25, 40}, |
30 | + | {{25, 1}, {40, 1}}, |
31 | - | {25, 40}, |
31 | + | {{25, 1}, {40, 1}}, |
32 | - | {25, 40}, |
32 | + | {{25, 1}, {40, 1}}, |
33 | - | {25, 40}, |
33 | + | {{25, 1}, {40, 1}}, |
34 | - | {25, 40}, |
34 | + | {{25, 1}, {40, 1}}, |
35 | - | {25, 40}, |
35 | + | {{25, 1}, {40, 1}}, |
36 | - | {25, 40}, |
36 | + | {{25, 1}, {40, 1}}, |
37 | - | {25, 40}, |
37 | + | {{25, 1}, {40, 1}}, |
38 | - | {25, 40}, |
38 | + | {{25, 1}, {40, 1}}, |
39 | - | {25, 40}, |
39 | + | {{25, 1}, {40, 1}}, |
40 | - | {25, 40}, |
40 | + | {{25, 1}, {40, 1}}, |
41 | - | {25, 40}, |
41 | + | {{25, 1}, {40, 1}}, |
42 | - | {25, 40}, |
42 | + | {{25, 1}, {40, 1}}, |
43 | - | {25, 40}, |
43 | + | {{25, 1}, {40, 1}}, |
44 | - | {25, 40}, |
44 | + | {{25, 1}, {40, 1}}, |
45 | - | {25, 40}, |
45 | + | {{25, 1}, {40, 1}}, |
46 | - | {25, 40}, |
46 | + | {{25, 1}, {40, 1}}, |
47 | - | {25, 40}, |
47 | + | {{25, 1}, {40, 1}}, |
48 | - | {25, 40}, |
48 | + | {{25, 1}, {40, 1}}, |
49 | - | {25, 40}, |
49 | + | {{25, 1}, {40, 1}}, |
50 | - | {35, 40}, -- Testing vendor with item entry 35 |
50 | + | {{25, 1}, {40, 1}}, |
51 | {{25, 1}, {40, 1}}, | |
52 | {{25, 1}, {40, 1}}, | |
53 | {{25, 1}, {40, 1}}, | |
54 | {{35, 2}, {40, 1}}, -- Testing vendor with item entry 35 | |
55 | } | |
56 | ||
57 | T.Page = {} | |
58 | T.Buy = {} | |
59 | T.Options = 20 | |
60 | local X = 10 | |
61 | ||
62 | function T.Count(Page) | |
63 | if(not Page or Page < 1) then | |
64 | return 1 | |
65 | else | |
66 | return (Page*T.Options) | |
67 | end | |
68 | end | |
69 | ||
70 | function T.Max(Count, LData) | |
71 | if(LData - Count >= T.Options) then | |
72 | return Count+T.Options-1, true | |
73 | else | |
74 | return LData, false | |
75 | end | |
76 | end | |
77 | ||
78 | - | if(not pPlayer:HasItem(v[i])) then |
78 | + | function T.Name(Entry) |
79 | return WorldDBQuery("SELECT Name1 FROM items WHERE entry = "..Entry):GetColumn(0):GetString() | |
80 | end | |
81 | ||
82 | function T.Hello(pUnit, event, pPlayer) | |
83 | local Items = {} | |
84 | - | Items[#Items+1] = {k,v[1]} |
84 | + | |
85 | local Add = true | |
86 | for i = 2, #v do | |
87 | if(Check and (not pPlayer:HasItem(v[i][1]) or pPlayer:GetItemCount(v[i][1]) < v[i][2])) then | |
88 | Add = false | |
89 | break | |
90 | end | |
91 | end | |
92 | if(Add) then | |
93 | Items[#Items+1] = {k, v[1][1], v[1][2]} | |
94 | end | |
95 | end | |
96 | local str = tostring(pPlayer) | |
97 | if(not T.Page[str] or T.Page[str] < 0) then | |
98 | T.Page[str] = 0 | |
99 | end | |
100 | local Page = T.Page[str] | |
101 | local Count = T.Count(Page) | |
102 | - | pUnit:GossipMenuAddItem(6, "Preview page's items", X, 0, '', 0) |
102 | + | |
103 | pUnit:GossipCreateMenu(100, pPlayer, 0) | |
104 | - | local Name = WorldDBQuery("SELECT Name1 FROM items WHERE entry = "..Items[k][2]):GetColumn(0):GetString() |
104 | + | |
105 | - | pUnit:GossipMenuAddItem(0, Name, X+Items[k][1], 0, 'NOTE! You will lose the items required to buy this item.', 0) |
105 | + | |
106 | end | |
107 | if(Page > 0) then | |
108 | pUnit:GossipMenuAddItem(7, "Previous page", 4, 0, '', 0) | |
109 | end | |
110 | pUnit:GossipMenuAddItem(4, "Refresh", 1, 0, '', 0) | |
111 | pUnit:GossipMenuAddItem(1, "Preview page's items", X, 0, '', 0) | |
112 | for k = Count, Max do | |
113 | local Amount = "" | |
114 | if(Items[k][3] > 1) then | |
115 | Amount = Items[k][3].." " | |
116 | end | |
117 | local Name = T.Name(Items[k][2]) | |
118 | pUnit:GossipMenuAddItem(3, Amount..Name, X+Items[k][1], 0, '', 0) | |
119 | end | |
120 | pUnit:GossipSendMenu(pPlayer) | |
121 | end | |
122 | ||
123 | - | if(not pPlayer:HasItem(v[i])) then |
123 | + | |
124 | local str = tostring(pPlayer) | |
125 | if(intid == 3) then | |
126 | T.Page[str] = T.Page[str] + 1 | |
127 | elseif(intid == 4) then | |
128 | T.Page[str] = T.Page[str] - 1 | |
129 | - | Items[#Items+1] = v[1] |
129 | + | elseif(intid == 5) then |
130 | T.Select(pUnit, 666, pPlayer, id, T.Buy[str], code) | |
131 | return | |
132 | elseif(intid == X) then | |
133 | pPlayer:GossipComplete() | |
134 | pUnit:VendorRemoveAllItems() | |
135 | local Items = {} | |
136 | for k,v in ipairs(T.Items) do | |
137 | local Add = true | |
138 | for i = 2, #v do | |
139 | if(Check and (not pPlayer:HasItem(v[i][1]) or pPlayer:GetItemCount(v[i][1]) < v[i][2])) then | |
140 | Add = false | |
141 | - | local intid = intid-X |
141 | + | |
142 | end | |
143 | - | for i = 2, #T.Items[intid] do |
143 | + | |
144 | - | if(not pPlayer:HasItem(T.Items[intid][i])) then |
144 | + | |
145 | Items[#Items+1] = v[1][1] | |
146 | end | |
147 | end | |
148 | local Page = T.Page[str] | |
149 | local Count = T.Count(Page) | |
150 | - | if(pPlayer:AddItem(T.Items[intid][1], 1)) then |
150 | + | |
151 | - | for i = 2, #T.Items[intid] do |
151 | + | |
152 | - | pPlayer:RemoveItem(T.Items[intid][i], 1) |
152 | + | |
153 | end | |
154 | pPlayer:SendVendorWindow(pUnit) | |
155 | - | pPlayer:SendAreaTriggerMessage("Your inventory is full") |
155 | + | |
156 | elseif(T.Items[intid-X]) then | |
157 | if(event ~= 666) then | |
158 | - | pPlayer:SendAreaTriggerMessage("You do not have the required items") |
158 | + | T.Buy[str] = intid |
159 | pPlayer:SendBroadcastMessage("You need these items to purchase:") | |
160 | for i = 2, #T.Items[intid-X] do | |
161 | local Name = T.Name(T.Items[intid-X][i][1]) | |
162 | pPlayer:SendBroadcastMessage(T.Items[intid-X][i][2].." \124cff00B0E4\124Hitem:"..T.Items[intid-X][i][1]..":0:0:0:0:0:0:0:0\124h["..Name.."]\124h\124r") | |
163 | end | |
164 | local Name = T.Name(T.Items[intid-X][1][1]) | |
165 | pUnit:GossipCreateMenu(100, pPlayer, 0) | |
166 | pUnit:GossipMenuAddItem(1, "Buy "..T.Items[intid-X][1][2].." "..Name, 5, 0, "Buying "..T.Items[intid-X][1][2].." "..Name.."!", 0) | |
167 | pUnit:GossipMenuAddItem(6, "Show price", intid, 0, '', 0) | |
168 | pUnit:GossipMenuAddItem(7, "Back..", 1, 0, '', 0) | |
169 | pUnit:GossipSendMenu(pPlayer) | |
170 | return | |
171 | else | |
172 | local intid = intid-X | |
173 | local Add = true | |
174 | for i = 2, #T.Items[intid] do | |
175 | if(not pPlayer:HasItem(T.Items[intid][i][1]) or pPlayer:GetItemCount(T.Items[intid][i][1]) < T.Items[intid][i][2]) then | |
176 | Add = false | |
177 | break | |
178 | end | |
179 | end | |
180 | if(Add) then | |
181 | local Done = 0 | |
182 | for k = 1, T.Items[intid][1][2] do | |
183 | if(pPlayer:AddItem(T.Items[intid][1][1], 1)) then | |
184 | Done = Done + 1 | |
185 | else | |
186 | pPlayer:RemoveItem(T.Items[intid][1][1], Done) | |
187 | pPlayer:SendAreaTriggerMessage("Your inventory is too full") | |
188 | break | |
189 | end | |
190 | end | |
191 | if(Done == T.Items[intid][1][2]) then | |
192 | for i = 2, #T.Items[intid] do | |
193 | pPlayer:RemoveItem(T.Items[intid][i][1], T.Items[intid][i][2]) | |
194 | end | |
195 | else | |
196 | T.Select(pUnit, 0, pPlayer, id, intid+X, code) | |
197 | return | |
198 | end | |
199 | else | |
200 | pPlayer:SendAreaTriggerMessage("You do not have the required items") | |
201 | if(not Check) then | |
202 | T.Select(pUnit, 0, pPlayer, id, intid+X, code) | |
203 | return | |
204 | end | |
205 | end | |
206 | end | |
207 | end | |
208 | T.Hello(pUnit, event, pPlayer) | |
209 | end | |
210 | ||
211 | local ID = 180001 -- NPC entry | |
212 | RegisterUnitGossipEvent(ID, 1, T.Hello) | |
213 | RegisterUnitGossipEvent(ID, 2, T.Select) |