This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [LUA] [WotLk][TC] Exchange script problem  (Read 2157 times)

lovekilz

  • Registred Member
  • BLP Convertor
  • *****
  • Posts: 6
    • View Profile
[LUA] [WotLk][TC] Exchange script problem
« on: April 20, 2016, 11:46:17 pm »
Im using Rochet2's version of item exchange : http://pastebin.com/BS3mTx1x
original link : http://www.ac-web.org/forums/showthread ... nge-script
I want to use it for multi item upgrade so i dont have to make 5 quest for each item, (like 300 items)
The thing is it dosent work as intended. It only shows the Hello player message, i think it`s because it`s made for an older eluna version.
/ Set the npcflag  and gossip_menu to 129 and it dosent work.

Any help would be apreciated.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

lovekilz

  • Registred Member
  • BLP Convertor
  • *****
  • Posts: 6
    • View Profile
Re: [LUA] [WotLk][TC] Exchange script problem
« Reply #1 on: April 22, 2016, 04:28:14 pm »
bump
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: [LUA] [WotLk][TC] Exchange script problem
« Reply #2 on: April 23, 2016, 10:25:35 am »
Do you get any errors?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

lovekilz

  • Registred Member
  • BLP Convertor
  • *****
  • Posts: 6
    • View Profile
Re: [LUA] [WotLk][TC] Exchange script problem
« Reply #3 on: April 23, 2016, 01:15:50 pm »
No, no errors, just that the items dont show in the menu
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: [LUA] [WotLk][TC] Exchange script problem
« Reply #4 on: April 23, 2016, 05:37:02 pm »
Did you change the npc id in the script to your id?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

lovekilz

  • Registred Member
  • BLP Convertor
  • *****
  • Posts: 6
    • View Profile
Re: [LUA] [WotLk][TC] Exchange script problem
« Reply #5 on: April 24, 2016, 01:09:50 am »
yes i did. i did all that is necesary and the item list does not display. the help would be much apreciated
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

lovekilz

  • Registred Member
  • BLP Convertor
  • *****
  • Posts: 6
    • View Profile
Re: [LUA] [WotLk][TC] Exchange script problem
« Reply #6 on: April 24, 2016, 04:04:18 am »
sorry for double
here is the script
Code: [Select]

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)

and the npc
Code: [Select]
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');


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,
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: [LUA] [WotLk][TC] Exchange script problem
« Reply #7 on: April 27, 2016, 12:54:58 pm »
Quote from: "lovekilz"
sorry for double
here is the script
Code: [Select]

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)

and the npc
Code: [Select]
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');


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,

Try RegisterCreatureGossipEvent instead of RegisterUnitGossipEvent.
http://eluna.emudevs.com/Global/Registe ... Event.html
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

lovekilz

  • Registred Member
  • BLP Convertor
  • *****
  • Posts: 6
    • View Profile
Re: [LUA] [WotLk][TC] Exchange script problem
« Reply #8 on: April 28, 2016, 05:52:02 pm »
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.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »