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