diff --git a/data-otservbr-global/npc/alaistar.lua b/data-otservbr-global/npc/alaistar.lua index 68aaa75679a..c82e478e89b 100644 --- a/data-otservbr-global/npc/alaistar.lua +++ b/data-otservbr-global/npc/alaistar.lua @@ -114,15 +114,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true diff --git a/data-otservbr-global/npc/alexander.lua b/data-otservbr-global/npc/alexander.lua index 52b98a9760e..bd6a0329652 100644 --- a/data-otservbr-global/npc/alexander.lua +++ b/data-otservbr-global/npc/alexander.lua @@ -134,11 +134,6 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] local itemId = items[player:getVocation():getBaseId()] if MsgContains(message, "first rod") or MsgContains(message, "first wand") then @@ -163,7 +158,8 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:say("Ok then.", npc, creature) npcHandler:setTopic(playerId, 0) elseif categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -175,7 +171,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Hi there |PLAYERNAME|, and welcome to the {magic} store.") npcHandler:setMessage(MESSAGE_FAREWELL, "See you, |PLAYERNAME|.") npcHandler:setMessage(MESSAGE_WALKAWAY, "See you, |PLAYERNAME|.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {runes} or {wands}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/asima.lua b/data-otservbr-global/npc/asima.lua index c3aca3fcd5e..2d209e95d4c 100644 --- a/data-otservbr-global/npc/asima.lua +++ b/data-otservbr-global/npc/asima.lua @@ -145,11 +145,6 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] local itemId = items[player:getVocation():getBaseId()] if MsgContains(message, "first rod") or MsgContains(message, "first wand") then @@ -174,12 +169,14 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:say("Ok then.", npc, creature) npcHandler:setTopic(playerId, 0) elseif categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true end +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) diff --git a/data-otservbr-global/npc/battlemart.lua b/data-otservbr-global/npc/battlemart.lua index 4cc010da066..e19ba50b6e5 100644 --- a/data-otservbr-global/npc/battlemart.lua +++ b/data-otservbr-global/npc/battlemart.lua @@ -196,16 +196,12 @@ local itemsTable = { } local function creatureSayCallback(npc, player, type, message) - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if MsgContains(message, "shop options") then - npcHandler:say("I sell a selection of " .. table.concat(formattedCategoryNames, ", "), npc, player) + npcHandler:say("I sell a selection of " .. npc:getFormattedCategoryNames(itemsTable), npc, player) elseif categoryTable then - npcHandler:say("Here are the items for the category " .. message, npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end end @@ -213,6 +209,7 @@ end npcHandler:setMessage(MESSAGE_GREET, "It is good to see you. I'm always at your {shop options}") npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, |PLAYERNAME|, I'll be here if you need me again.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Come back soon!") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) diff --git a/data-otservbr-global/npc/chuckles.lua b/data-otservbr-global/npc/chuckles.lua index 4eb06b6bb3d..5642304172f 100644 --- a/data-otservbr-global/npc/chuckles.lua +++ b/data-otservbr-global/npc/chuckles.lua @@ -135,20 +135,17 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true end +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) diff --git a/data-otservbr-global/npc/fenech.lua b/data-otservbr-global/npc/fenech.lua index f69dcafaa89..acc2ab55b45 100644 --- a/data-otservbr-global/npc/fenech.lua +++ b/data-otservbr-global/npc/fenech.lua @@ -134,11 +134,6 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] local itemId = items[player:getVocation():getBaseId()] if MsgContains(message, "first rod") or MsgContains(message, "first wand") then @@ -163,7 +158,8 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:say("Ok then.", npc, creature) npcHandler:setTopic(playerId, 0) elseif categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -173,7 +169,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Be mourned pilgrim in flesh and welcome to the magic store.") npcHandler:setMessage(MESSAGE_FAREWELL, "May enlightenment be your path.") npcHandler:setMessage(MESSAGE_WALKAWAY, "May enlightenment be your path.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {wands} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/frans.lua b/data-otservbr-global/npc/frans.lua index a1b695adf14..ad5b30c4fd5 100644 --- a/data-otservbr-global/npc/frans.lua +++ b/data-otservbr-global/npc/frans.lua @@ -116,15 +116,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -134,7 +130,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Beeee greeeeted, Simula! What is your neeeed?") npcHandler:setMessage(MESSAGE_FAREWELL, "Bye.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {wands} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/frederik.lua b/data-otservbr-global/npc/frederik.lua index 81ff1ec58b6..d7850598c56 100644 --- a/data-otservbr-global/npc/frederik.lua +++ b/data-otservbr-global/npc/frederik.lua @@ -140,15 +140,10 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] - if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -158,7 +153,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Hi there and welcome to my little magic shop.") npcHandler:setMessage(MESSAGE_FAREWELL, "Yeah, bye.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Yeah, bye.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {potions}, {wands} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/ghorza.lua b/data-otservbr-global/npc/ghorza.lua index 17f752e7435..43db1d3238f 100644 --- a/data-otservbr-global/npc/ghorza.lua +++ b/data-otservbr-global/npc/ghorza.lua @@ -123,15 +123,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -141,7 +137,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Hello, scraggy human.") npcHandler:setMessage(MESSAGE_FAREWELL, "Take care of evil spirits.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Take care of evil spirits.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {potions} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/gnomegica.lua b/data-otservbr-global/npc/gnomegica.lua index b860caf3962..5b776260bd5 100644 --- a/data-otservbr-global/npc/gnomegica.lua +++ b/data-otservbr-global/npc/gnomegica.lua @@ -136,15 +136,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -154,7 +150,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Greetings! You came to the right gnome to buy {potions}, {runes} or {wands}. So let's talk about a {trade}.") npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye and come again.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye and come again.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {potions}, {wands} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/hamish.lua b/data-otservbr-global/npc/hamish.lua index b00d21393a6..050fc41dbb9 100644 --- a/data-otservbr-global/npc/hamish.lua +++ b/data-otservbr-global/npc/hamish.lua @@ -162,11 +162,6 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if MsgContains(message, "dawnport") then npcHandler:say({ @@ -191,7 +186,8 @@ local function creatureSayCallback(npc, creature, type, message) He even has a crush on lady Oressa. Cute. ", }, npc, creature, 200) elseif categoryTable then - npcHandler:say("Take your pick!", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -203,6 +199,8 @@ npcHandler:setMessage( "Hi there, fellow adventurer. \z What's your need? Say {trade} and we'll soon get you fixed up. Or ask me about {potions}, {wands}, or {runes}." ) + +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:setMessage(MESSAGE_FAREWELL, "Use your runes wisely!") npcHandler:setMessage(MESSAGE_WALKAWAY, "Use your runes wisely!") npcHandler:setMessage(MESSAGE_SENDTRADE, "Take your pick! Or maybe you want to look only at {potions}, {wands} or {runes}?") diff --git a/data-otservbr-global/npc/hireling.lua b/data-otservbr-global/npc/hireling.lua index 6897bafdcf7..ce5c6737e02 100644 --- a/data-otservbr-global/npc/hireling.lua +++ b/data-otservbr-global/npc/hireling.lua @@ -674,7 +674,8 @@ function createHirelingType(HirelingName) local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Here are the items for the category " .. message .. ".", npc, creature) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end end diff --git a/data-otservbr-global/npc/khanna.lua b/data-otservbr-global/npc/khanna.lua index 76b5c1e70da..497a8f87c64 100644 --- a/data-otservbr-global/npc/khanna.lua +++ b/data-otservbr-global/npc/khanna.lua @@ -173,11 +173,6 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] local itemId = items[player:getVocation():getBaseId()] if MsgContains(message, "first rod") or MsgContains(message, "first wand") then @@ -202,14 +197,15 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:say("Ok then.", npc, creature) npcHandler:setTopic(playerId, 0) elseif categoryTable then - npcHandler:say("Take your pick!", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) -npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {wands} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/mordecai.lua b/data-otservbr-global/npc/mordecai.lua index dc0e3c07a77..3b2ec4e60e8 100644 --- a/data-otservbr-global/npc/mordecai.lua +++ b/data-otservbr-global/npc/mordecai.lua @@ -143,15 +143,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Choose wisely!", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -161,7 +157,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Welcome to the magic emporium, child. Ask me for a trade if you need {runes}, {wands}, or spellbooks.") npcHandler:setMessage(MESSAGE_FAREWELL, "Take care, child.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Ah, the impetuosity of youth.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Choose wisely! Or maybe you want to look only at {wands} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Choose wisely! Or maybe you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/nelly.lua b/data-otservbr-global/npc/nelly.lua index 911464524c6..8a3cb6be150 100644 --- a/data-otservbr-global/npc/nelly.lua +++ b/data-otservbr-global/npc/nelly.lua @@ -152,15 +152,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -170,7 +166,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|, What can I do for you? I'm working for the post office, but I also trade with important {potions}, {runes} and other magical equipment.") npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye, |PLAYERNAME|.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Ah, the impetuosity of youth.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {post stuff}, {potions}, {wands} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/nipuna.lua b/data-otservbr-global/npc/nipuna.lua index ef3211bce42..d428b45c9c8 100644 --- a/data-otservbr-global/npc/nipuna.lua +++ b/data-otservbr-global/npc/nipuna.lua @@ -156,22 +156,18 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) -npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {potions}, {wands} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/rabaz.lua b/data-otservbr-global/npc/rabaz.lua index df9e8ca2ca5..0de19876209 100644 --- a/data-otservbr-global/npc/rabaz.lua +++ b/data-otservbr-global/npc/rabaz.lua @@ -140,11 +140,6 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if MsgContains(message, "mission") then if player:getStorageValue(Storage.Quest.U8_6.AnInterestInBotany.Questline) < 1 then @@ -189,7 +184,8 @@ local function creatureSayCallback(npc, creature, type, message) end end elseif categoryTable then - npcHandler:say("Have a look.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -199,7 +195,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Ah, a customer! Please feel free to browse my wares, |PLAYERNAME|.") npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Have a look. But perhaps you just want to see my {potions}, {wands} or {runes}?") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Have a look. But perhaps you just want to see my " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/rachel.lua b/data-otservbr-global/npc/rachel.lua index 057787692c9..a301abf2f93 100644 --- a/data-otservbr-global/npc/rachel.lua +++ b/data-otservbr-global/npc/rachel.lua @@ -142,11 +142,6 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] local itemId = items[player:getVocation():getBaseId()] if MsgContains(message, "first rod") or MsgContains(message, "first wand") then @@ -171,7 +166,8 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:say("Ok then.", npc, creature) npcHandler:setTopic(playerId, 0) elseif categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -181,11 +177,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Welcome |PLAYERNAME|! Whats your need?") npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye, |PLAYERNAME|.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, |PLAYERNAME|.") -npcHandler:setMessage( - MESSAGE_SENDTRADE, - "Of course, just browse through my wares. \z - Or do you want to look only at {potions}, {wands} or {runes}?" -) +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/richard.lua b/data-otservbr-global/npc/richard.lua index d38b6c93b0b..9f3c8ad36e3 100644 --- a/data-otservbr-global/npc/richard.lua +++ b/data-otservbr-global/npc/richard.lua @@ -22,27 +22,42 @@ npcConfig.outfit = { npcConfig.flags = { floorchange = false, } -npcConfig.shop = { - { itemName = "backpack", clientId = 2854, buy = 10, count = 1 }, - { itemName = "bag", clientId = 2853, buy = 4, count = 1 }, - { itemName = "bread", clientId = 3600, buy = 3, count = 1 }, - { itemName = "carrot", clientId = 3595, buy = 1, count = 1 }, - { itemName = "cheese", clientId = 3607, sell = 2, count = 1 }, - { itemName = "cherry", clientId = 3590, buy = 1, count = 1 }, - { itemName = "egg", clientId = 3606, buy = 1, count = 1 }, - { itemName = "fishing rod", clientId = 3483, sell = 30, count = 1 }, - { itemName = "ham", clientId = 3582, buy = 8, count = 1 }, - { itemName = "machete", clientId = 3308, buy = 6, count = 1 }, - { itemName = "meat", clientId = 3577, sell = 2, count = 1 }, - { itemName = "pick", clientId = 3456, buy = 15, count = 1 }, - { itemName = "rope", clientId = 3003, sell = 8, count = 1 }, - { itemName = "salmon", clientId = 3579, buy = 2, count = 1 }, - { itemName = "scroll", clientId = 2815, buy = 5, count = 1 }, - { itemName = "shovel", clientId = 3457, sell = 2, count = 1 }, - { itemName = "torch", clientId = 2920, buy = 2, count = 1 }, - { itemName = "worm", clientId = 3492, buy = 1, count = 1 }, +local itemsTable = { + ["containers"] = { + { itemName = "backpack", clientId = 2854, buy = 10, count = 1 }, + { itemName = "bag", clientId = 2853, buy = 4, count = 1 }, + }, + ["food"] = { + { itemName = "bread", clientId = 3600, buy = 3, count = 1 }, + { itemName = "carrot", clientId = 3595, buy = 1, count = 1 }, + { itemName = "cheese", clientId = 3607, sell = 2, count = 1 }, + { itemName = "cherry", clientId = 3590, buy = 1, count = 1 }, + { itemName = "egg", clientId = 3606, buy = 1, count = 1 }, + { itemName = "ham", clientId = 3582, buy = 8, count = 1 }, + { itemName = "meat", clientId = 3577, sell = 2, count = 1 }, + { itemName = "salmon", clientId = 3579, buy = 2, count = 1 }, + }, + ["equipment"] = { + { itemName = "fishing rod", clientId = 3483, sell = 30, count = 1 }, + { itemName = "machete", clientId = 3308, buy = 6, count = 1 }, + { itemName = "pick", clientId = 3456, buy = 15, count = 1 }, + { itemName = "rope", clientId = 3003, sell = 8, count = 1 }, + { itemName = "shovel", clientId = 3457, sell = 2, count = 1 }, + { itemName = "torch", clientId = 2920, buy = 2, count = 1 }, + }, + ["others"] = { + { itemName = "scroll", clientId = 2815, buy = 5, count = 1 }, + { itemName = "worm", clientId = 3492, buy = 1, count = 1 }, + }, } +npcConfig.shop = {} +for _, category in pairs(itemsTable) do + for _, item in ipairs(category) do + table.insert(npcConfig.shop, item) + end +end + -- On buy npc shop message npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost) npc:sellItem(player, itemId, amount, subType, 0, ignore, inBackpacks) @@ -103,6 +118,7 @@ local function creatureSayCallback(npc, creature, type, message) return false end + local categoryTable = itemsTable[message:lower()] if MsgContains(message, "job") then npcHandler:say({ "I was a carpenter, back on Main. Wanted my own little shop. Didn't sit with the old man. \z @@ -114,9 +130,13 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:say({ "Only the best quality, I assure you. A rope in need is a friend indeed! Imagine you stumble into a rat \z hole without a rope - heh, your bones will be gnawed clean before someone finds ya!", - "Now, about that rope - ask me for equipment to see my wares. ", + "Now, about that rope - ask me for {equipment} to see my wares. ", }, npc, creature, 10) npcHandler:setTopic(playerId, 0) + elseif categoryTable then + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) + npc:openShopWindowTable(player, categoryTable) end return true end @@ -178,11 +198,7 @@ keywordHandler:addKeyword({ "hamish" }, StdModule.say, { }) npcHandler:setMessage(MESSAGE_GREET, "Hello there, mate. Here for a {trade}? My stock's just been refilled.") -npcHandler:setMessage( - MESSAGE_SENDTRADE, - "Of course, just browse through my wares. \z - You can also have a look at food or {equipment} only." -) +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:setMessage(MESSAGE_FAREWELL, "Have fun!") npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) diff --git a/data-otservbr-global/npc/rock_in_a_hard_place.lua b/data-otservbr-global/npc/rock_in_a_hard_place.lua index 64ee5e08174..7abec0e60d1 100644 --- a/data-otservbr-global/npc/rock_in_a_hard_place.lua +++ b/data-otservbr-global/npc/rock_in_a_hard_place.lua @@ -274,15 +274,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Here, have a look", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -292,7 +288,7 @@ local function onTradeRequest(npc, creature) local player = Player(creature) local playerId = player:getId() - npcHandler:say("You would be surprised how many things are washed ashore here. I trade {magic stuff}, {local equipment}, {weapons}, {armor}, {ammunition}, {post things} and {creature products}.", npc, creature) + npcHandler:say("You would be surprised how many things are washed ashore here. I trade " .. GetFormattedShopCategoryNames(itemsTable) .. ".", npc, creature) return true end diff --git a/data-otservbr-global/npc/romir.lua b/data-otservbr-global/npc/romir.lua index 09ab62ab1a4..c658e358e6f 100644 --- a/data-otservbr-global/npc/romir.lua +++ b/data-otservbr-global/npc/romir.lua @@ -140,15 +140,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -158,11 +154,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Greetings, traveller. I'm a magical trader and trainer for sorcerer spells. How may I help you?") npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.") -npcHandler:setMessage( - MESSAGE_SENDTRADE, - "Of course, just browse through my wares. \z - Or do you want to look only at {potions}, {wands} or {runes}?" -) +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/shiriel.lua b/data-otservbr-global/npc/shiriel.lua index fd982f345b9..eda4a03f1e0 100644 --- a/data-otservbr-global/npc/shiriel.lua +++ b/data-otservbr-global/npc/shiriel.lua @@ -128,15 +128,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -146,11 +142,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Greetings, |PLAYERNAME|.") npcHandler:setMessage(MESSAGE_FAREWELL, "Goodbye, |PLAYERNAME|.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Goodbye, |PLAYERNAME|.") -npcHandler:setMessage( - MESSAGE_SENDTRADE, - "Of course, just browse through my wares. \z - Or do you want to look only at {potions}, {wands} or {runes}?" -) +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- Greeting message diff --git a/data-otservbr-global/npc/sigurd.lua b/data-otservbr-global/npc/sigurd.lua index e4d1b585307..57d14f02f4b 100644 --- a/data-otservbr-global/npc/sigurd.lua +++ b/data-otservbr-global/npc/sigurd.lua @@ -130,15 +130,11 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -148,11 +144,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Welcome to the magic store, |PLAYERNAME|! Ask me for a trade if you need something.") npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye. Come back soon.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye. Come back soon.") -npcHandler:setMessage( - MESSAGE_SENDTRADE, - "Of course, just browse through my wares. \z - Or do you want to look only at {potions}, {wands} or {runes}?" -) +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/sundara.lua b/data-otservbr-global/npc/sundara.lua index 95ff206f2ad..b75a7349432 100644 --- a/data-otservbr-global/npc/sundara.lua +++ b/data-otservbr-global/npc/sundara.lua @@ -156,26 +156,18 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) -npcHandler:setMessage( - MESSAGE_SENDTRADE, - "Of course, just browse through my wares. \z - Or do you want to look only at {potions}, {wands} or {runes}?" -) +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/tandros.lua b/data-otservbr-global/npc/tandros.lua index ae647b26127..07e51abc163 100644 --- a/data-otservbr-global/npc/tandros.lua +++ b/data-otservbr-global/npc/tandros.lua @@ -146,26 +146,18 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] if categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) -npcHandler:setMessage( - MESSAGE_SENDTRADE, - "Of course, just browse through my wares. \z - Or do you want to look only at {potions}, {wands} or {runes}?" -) +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) -- On buy npc shop message diff --git a/data-otservbr-global/npc/the_lootmonger.lua b/data-otservbr-global/npc/the_lootmonger.lua index e0c2b03da32..cb42a0be210 100644 --- a/data-otservbr-global/npc/the_lootmonger.lua +++ b/data-otservbr-global/npc/the_lootmonger.lua @@ -55,23 +55,19 @@ npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) npcConfig.shop = LootShopConfig local function creatureSayCallback(npc, player, type, message) - local formattedCategoryNames = {} - for categoryName, _ in pairs(LootShopConfigTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = LootShopConfigTable[message:lower()] if MsgContains(message, "shop options") then - npcHandler:say("I sell a selection of " .. table.concat(formattedCategoryNames, ", "), npc, player) + npcHandler:say("I sell a selection of " .. GetFormattedShopCategoryNames(LootShopConfigTable), npc, player) elseif categoryTable then - npcHandler:say("Here are the items for the category " .. message, npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), LootShopConfigTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, "Ah, a customer! Be greeted, |PLAYERNAME|! I buy all kinds of loot, would you like a {trade}? I can also show you my {shop options}.") -npcHandler:setMessage(MESSAGE_SENDTRADE, "Ah, a customer! Be greeted, |PLAYERNAME|! I buy all kinds of loot, would you like a {trade}? I can also show you my {shop options}.") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Ah, a customer! Be greeted, |PLAYERNAME|! I buy all kinds of loot, would you look at " .. GetFormattedShopCategoryNames(LootShopConfigTable) .. ".") -- On buy npc shop message npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost) diff --git a/data-otservbr-global/npc/topsy.lua b/data-otservbr-global/npc/topsy.lua index 66ea6f27e6a..c37faecb0fd 100644 --- a/data-otservbr-global/npc/topsy.lua +++ b/data-otservbr-global/npc/topsy.lua @@ -141,11 +141,6 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] local itemId = items[player:getVocation():getBaseId()] if MsgContains(message, "first rod") or MsgContains(message, "first wand") then @@ -170,7 +165,8 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:say("Ok then.", npc, creature) npcHandler:setTopic(playerId, 0) elseif categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -182,11 +178,7 @@ npcHandler:setMessage( "Hello, dear |PLAYERNAME|. How can I help you? \z If you need magical equipment such as {runes} or {wands}, just ask me for a {trade}." ) -npcHandler:setMessage( - MESSAGE_SENDTRADE, - "Of course, just browse through my wares. \z - Or do you want to look only at {potions}, {wands} or {runes}?" -) +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye, |PLAYERNAME|. Do come again!") npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, |PLAYERNAME|. Do come again!") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) diff --git a/data-otservbr-global/npc/xodet.lua b/data-otservbr-global/npc/xodet.lua index f687b491e89..f1148505266 100644 --- a/data-otservbr-global/npc/xodet.lua +++ b/data-otservbr-global/npc/xodet.lua @@ -135,11 +135,6 @@ local function creatureSayCallback(npc, creature, type, message) return false end - local formattedCategoryNames = {} - for categoryName, _ in pairs(itemsTable) do - table.insert(formattedCategoryNames, "{" .. categoryName .. "}") - end - local categoryTable = itemsTable[message:lower()] local itemId = items[player:getVocation():getBaseId()] if MsgContains(message, "first rod") or MsgContains(message, "first wand") then @@ -164,7 +159,8 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:say("Ok then.", npc, creature) npcHandler:setTopic(playerId, 0) elseif categoryTable then - npcHandler:say("Of course, just browse through my wares.", npc, player) + local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable) + npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) npc:openShopWindowTable(player, categoryTable) end return true @@ -176,11 +172,7 @@ npcHandler:setMessage( "Oh, please come in, |PLAYERNAME| \z If you need magical equipment such as {runes} or {wands}, just ask me for a {trade}." ) -npcHandler:setMessage( - MESSAGE_SENDTRADE, - "Of course, just browse through my wares. \z - Or do you want to look only at {potions}, {wands} or {runes}?" -) +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".") npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye and come again.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye and come again.") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) diff --git a/data/npclib/npc.lua b/data/npclib/npc.lua index 30305778707..4de60c45c49 100644 --- a/data/npclib/npc.lua +++ b/data/npclib/npc.lua @@ -28,6 +28,30 @@ function MsgFind(message, keyword) return string.find(lowerMessage, lowerKeyword) and string.find(lowerMessage, lowerKeyword .. "(%w+)") and string.find(lowerMessage, "(%w+)" .. lowerKeyword) end +function GetFormattedShopCategoryNames(itemsTable) + local formattedCategoryNames = {} + for categoryName, _ in pairs(itemsTable) do + table.insert(formattedCategoryNames, "{" .. categoryName .. "}") + end + + if #formattedCategoryNames > 1 then + local lastCategory = table.remove(formattedCategoryNames) + return table.concat(formattedCategoryNames, ", ") .. " and " .. lastCategory + else + return formattedCategoryNames[1] or "" + end +end + +function Npc:getRemainingShopCategories(selectedCategory, itemsTable) + local remainingCategories = {} + for categoryName, _ in pairs(itemsTable) do + if categoryName ~= selectedCategory then + table.insert(remainingCategories, "{" .. categoryName .. "}") + end + end + return table.concat(remainingCategories, " or ") +end + -- Npc talk -- npc:talk({text, text2}) or npc:talk(text) function Npc:talk(player, text) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index b8eb94346d7..ee96b5bba24 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -1888,7 +1888,7 @@ bool Player::openShopWindow(std::shared_ptr npc, const std::vectorisShopPlayer(getGUID())) { + if (npc->isShopPlayer(getGUID()) && npc->getShopItemVector(getGUID()).size() == shopItems.size()) { g_logger().debug("[Player::openShopWindow] - Player {} is already in shop window", getName()); return false; } diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index 3a161ba3501..b18814cdae7 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -352,6 +352,7 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { return 1; } + player->closeShopWindow(); pushBoolean(L, player->openShopWindow(npc)); return 1; } @@ -402,6 +403,7 @@ int NpcFunctions::luaNpcOpenShopWindowTable(lua_State* L) { } lua_pop(L, 3); + player->closeShopWindow(); pushBoolean(L, player->openShopWindow(npc, items)); return 1; }