Forum > Serverside Modding
[LUA] [WotLk][TC] Exchange script problem
<< < (2/2)
lovekilz:
yes i did. i did all that is necesary and the item list does not display. the help would be much apreciated
lovekilz:
sorry for double here is the script
--- Code: --- 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. -- Set NPC entry at the bottom!
local T = {} T.Items = { -- {{GivenItem, Amount}, {ReqItem1, Amount}, {ReqItem2, Amount}, ... {ReqItemN, Amount}} {{25, 1}, {35, 1}}, {{25, 2}, {40, 3}, {38, 1}, {39, 1}, {36, 4}}, -- Testing multiple req items {{35, 2}, {40, 1}}, -- Testing vendor with item entry 35 }
T.Page = {} T.Buy = {} T.Options = 20 local X = 10
function T.Count(Page) if(not Page or Page < 1) then return 1 else return (Page*T.Options) end end
function T.Max(Count, LData) if(LData - Count >= T.Options) then return Count+T.Options-1, true else return LData, false end end
function T.Name(Entry) return WorldDBQuery("SELECT name FROM item_template WHERE entry = "..Entry):GetColumn(0):GetString() end
function T.Hello(pUnit, event, pPlayer) local Items = {} for k,v in ipairs(T.Items) do local Add = true for i = 2, #v do if(Check and (not pPlayer:HasItem(v[i][1]) or pPlayer:GetItemCount(v[i][1]) < v[i][2])) then Add = false break end end if(Add) then Items[#Items+1] = {k, v[1][1], v[1][2]} end end local str = tostring(pPlayer) if(not T.Page[str] or T.Page[str] < 0) then T.Page[str] = 0 end local Page = T.Page[str] local Count = T.Count(Page) local Max, Next = T.Max(Count, #Items) pUnit:GossipCreateMenu(100, pPlayer, 0) if(Next) then pUnit:GossipMenuAddItem(7, "Next page", 3, 0, '', 0) end if(Page > 0) then pUnit:GossipMenuAddItem(7, "Previous page", 4, 0, '', 0) end pUnit:GossipMenuAddItem(4, "Refresh", 1, 0, '', 0) pUnit:GossipMenuAddItem(1, "Preview page's items", X, 0, '', 0) for k = Count, Max do local Amount = "" if(Items[k][3] > 1) then Amount = Items[k][3].." " end local Name = T.Name(Items[k][2]) pUnit:GossipMenuAddItem(3, Amount..Name, X+Items[k][1], 0, '', 0) end pUnit:GossipSendMenu(pPlayer) end
function T.Select(pUnit, event, pPlayer, id, intid, code) local str = tostring(pPlayer) if(intid == 3) then T.Page[str] = T.Page[str] + 1 elseif(intid == 4) then T.Page[str] = T.Page[str] - 1 elseif(intid == 5) then T.Select(pUnit, 666, pPlayer, id, T.Buy[str], code) return elseif(intid == X) then pPlayer:GossipComplete() pUnit:VendorRemoveAllItems() local Items = {} for k,v in ipairs(T.Items) do local Add = true for i = 2, #v do if(Check and (not pPlayer:HasItem(v[i][1]) or pPlayer:GetItemCount(v[i][1]) < v[i][2])) then Add = false break end end if(Add) then Items[#Items+1] = v[1][1] end end local Page = T.Page[str] local Count = T.Count(Page) local Max, Next = T.Max(Count, #Items) for k = Count, Max do pUnit:VendorAddItem(Items[k], -1, 0) end pPlayer:SendVendorWindow(pUnit) return elseif(T.Items[intid-X]) then if(event ~= 666) then T.Buy[str] = intid pPlayer:SendBroadcastMessage("You need these items to purchase:") for i = 2, #T.Items[intid-X] do local Name = T.Name(T.Items[intid-X][i][1]) pPlayer:SendBroadcastMessage(T.Items[intid-X][i][2].." 124cff00B0E4124Hitem:"..T.Items[intid-X][i][1]..":0:0:0:0:0:0:0:0124h["..Name.."]124h124r") end local Name = T.Name(T.Items[intid-X][1][1]) pUnit:GossipCreateMenu(100, pPlayer, 0) pUnit:GossipMenuAddItem(1, "Buy "..T.Items[intid-X][1][2].." "..Name, 5, 0, "Buying "..T.Items[intid-X][1][2].." "..Name.."!", 0) pUnit:GossipMenuAddItem(6, "Show price", intid, 0, '', 0) pUnit:GossipMenuAddItem(7, "Back..", 1, 0, '', 0) pUnit:GossipSendMenu(pPlayer) return else local intid = intid-X local Add = true for i = 2, #T.Items[intid] do if(not pPlayer:HasItem(T.Items[intid][i][1]) or pPlayer:GetItemCount(T.Items[intid][i][1]) < T.Items[intid][i][2]) then Add = false break end end if(Add) then local Done = 0 for k = 1, T.Items[intid][1][2] do if(pPlayer:AddItem(T.Items[intid][1][1], 1)) then Done = Done + 1 else pPlayer:RemoveItem(T.Items[intid][1][1], Done) pPlayer:SendAreaTriggerMessage("Your inventory is too full") break end end if(Done == T.Items[intid][1][2]) then for i = 2, #T.Items[intid] do pPlayer:RemoveItem(T.Items[intid][i][1], T.Items[intid][i][2]) end else T.Select(pUnit, 0, pPlayer, id, intid+X, code) return end else pPlayer:SendAreaTriggerMessage("You do not have the required items") if(not Check) then T.Select(pUnit, 0, pPlayer, id, intid+X, code) return end end end end T.Hello(pUnit, event, pPlayer) end
local ID = 190018 -- NPC entry RegisterUnitGossipEvent(ID, 1, T.Hello) RegisterUnitGossipEvent(ID, 2, T.Select)
--- End code ---
and the npc
--- Code: ---INSERT INTO `creature_template` VALUES ('190018', '0', '0', '0', '0', '0', '21249', '0', '0', '0', 'ExchangerTest', '', 'Speak', '0', '80', '80', '2', '35', '129', '1', '1.14286', '1', '0', '0', '2000', '0', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '7', '138936390', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'EventAI', '0', '3', '1', '1', '1', '1', '1', '1', '0', '0', '1', '0', '0', '', '0');
--- End code ---
Forget about the EventAI flag, was just testing. The script just opens an empty store. Also when i remove the test item i put in the npc_Vendor it says Creature has vendor flag but no items,
Kaev:
--- Quote from: "lovekilz" ---sorry for double here is the script
--- Code: --- 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. -- Set NPC entry at the bottom!
local T = {} T.Items = { -- {{GivenItem, Amount}, {ReqItem1, Amount}, {ReqItem2, Amount}, ... {ReqItemN, Amount}} {{25, 1}, {35, 1}}, {{25, 2}, {40, 3}, {38, 1}, {39, 1}, {36, 4}}, -- Testing multiple req items {{35, 2}, {40, 1}}, -- Testing vendor with item entry 35 }
T.Page = {} T.Buy = {} T.Options = 20 local X = 10
function T.Count(Page) if(not Page or Page < 1) then return 1 else return (Page*T.Options) end end
function T.Max(Count, LData) if(LData - Count >= T.Options) then return Count+T.Options-1, true else return LData, false end end
function T.Name(Entry) return WorldDBQuery("SELECT name FROM item_template WHERE entry = "..Entry):GetColumn(0):GetString() end
function T.Hello(pUnit, event, pPlayer) local Items = {} for k,v in ipairs(T.Items) do local Add = true for i = 2, #v do if(Check and (not pPlayer:HasItem(v[i][1]) or pPlayer:GetItemCount(v[i][1]) < v[i][2])) then Add = false break end end if(Add) then Items[#Items+1] = {k, v[1][1], v[1][2]} end end local str = tostring(pPlayer) if(not T.Page[str] or T.Page[str] < 0) then T.Page[str] = 0 end local Page = T.Page[str] local Count = T.Count(Page) local Max, Next = T.Max(Count, #Items) pUnit:GossipCreateMenu(100, pPlayer, 0) if(Next) then pUnit:GossipMenuAddItem(7, "Next page", 3, 0, '', 0) end if(Page > 0) then pUnit:GossipMenuAddItem(7, "Previous page", 4, 0, '', 0) end pUnit:GossipMenuAddItem(4, "Refresh", 1, 0, '', 0) pUnit:GossipMenuAddItem(1, "Preview page's items", X, 0, '', 0) for k = Count, Max do local Amount = "" if(Items[k][3] > 1) then Amount = Items[k][3].." " end local Name = T.Name(Items[k][2]) pUnit:GossipMenuAddItem(3, Amount..Name, X+Items[k][1], 0, '', 0) end pUnit:GossipSendMenu(pPlayer) end
function T.Select(pUnit, event, pPlayer, id, intid, code) local str = tostring(pPlayer) if(intid == 3) then T.Page[str] = T.Page[str] + 1 elseif(intid == 4) then T.Page[str] = T.Page[str] - 1 elseif(intid == 5) then T.Select(pUnit, 666, pPlayer, id, T.Buy[str], code) return elseif(intid == X) then pPlayer:GossipComplete() pUnit:VendorRemoveAllItems() local Items = {} for k,v in ipairs(T.Items) do local Add = true for i = 2, #v do if(Check and (not pPlayer:HasItem(v[i][1]) or pPlayer:GetItemCount(v[i][1]) < v[i][2])) then Add = false break end end if(Add) then Items[#Items+1] = v[1][1] end end local Page = T.Page[str] local Count = T.Count(Page) local Max, Next = T.Max(Count, #Items) for k = Count, Max do pUnit:VendorAddItem(Items[k], -1, 0) end pPlayer:SendVendorWindow(pUnit) return elseif(T.Items[intid-X]) then if(event ~= 666) then T.Buy[str] = intid pPlayer:SendBroadcastMessage("You need these items to purchase:") for i = 2, #T.Items[intid-X] do local Name = T.Name(T.Items[intid-X][i][1]) pPlayer:SendBroadcastMessage(T.Items[intid-X][i][2].." 124cff00B0E4124Hitem:"..T.Items[intid-X][i][1]..":0:0:0:0:0:0:0:0124h["..Name.."]124h124r") end local Name = T.Name(T.Items[intid-X][1][1]) pUnit:GossipCreateMenu(100, pPlayer, 0) pUnit:GossipMenuAddItem(1, "Buy "..T.Items[intid-X][1][2].." "..Name, 5, 0, "Buying "..T.Items[intid-X][1][2].." "..Name.."!", 0) pUnit:GossipMenuAddItem(6, "Show price", intid, 0, '', 0) pUnit:GossipMenuAddItem(7, "Back..", 1, 0, '', 0) pUnit:GossipSendMenu(pPlayer) return else local intid = intid-X local Add = true for i = 2, #T.Items[intid] do if(not pPlayer:HasItem(T.Items[intid][i][1]) or pPlayer:GetItemCount(T.Items[intid][i][1]) < T.Items[intid][i][2]) then Add = false break end end if(Add) then local Done = 0 for k = 1, T.Items[intid][1][2] do if(pPlayer:AddItem(T.Items[intid][1][1], 1)) then Done = Done + 1 else pPlayer:RemoveItem(T.Items[intid][1][1], Done) pPlayer:SendAreaTriggerMessage("Your inventory is too full") break end end if(Done == T.Items[intid][1][2]) then for i = 2, #T.Items[intid] do pPlayer:RemoveItem(T.Items[intid][i][1], T.Items[intid][i][2]) end else T.Select(pUnit, 0, pPlayer, id, intid+X, code) return end else pPlayer:SendAreaTriggerMessage("You do not have the required items") if(not Check) then T.Select(pUnit, 0, pPlayer, id, intid+X, code) return end end end end T.Hello(pUnit, event, pPlayer) end
local ID = 190018 -- NPC entry RegisterUnitGossipEvent(ID, 1, T.Hello) RegisterUnitGossipEvent(ID, 2, T.Select)
--- End code ---
and the npc
--- Code: ---INSERT INTO `creature_template` VALUES ('190018', '0', '0', '0', '0', '0', '21249', '0', '0', '0', 'ExchangerTest', '', 'Speak', '0', '80', '80', '2', '35', '129', '1', '1.14286', '1', '0', '0', '2000', '0', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '7', '138936390', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'EventAI', '0', '3', '1', '1', '1', '1', '1', '1', '0', '0', '1', '0', '0', '', '0');
--- End code ---
Forget about the EventAI flag, was just testing. The script just opens an empty store. Also when i remove the test item i put in the npc_Vendor it says Creature has vendor flag but no items, --- End quote ---
Try RegisterCreatureGossipEvent instead of RegisterUnitGossipEvent. http://eluna.emudevs.com/Global/Registe ... Event.html
lovekilz:
did that earlier, after i get the error pUnit:GossipCreateMenu( the functions are deprecated ... and i have no idea how to fix a script this big.
Navigation
[0] Message Index
[*] Previous page
|