Skip to content

Commit 3cd4031

Browse files
authored
fix: resolve nil method error in battlemart.lua callback (opentibiabr#2961)
Replaced the method npc:getFormattedCategoryNames(itemsTable) with the function GetFormattedShopCategoryNames(SupplyShopConfigTable), which correctly formats the shop category names. This fixes the error and allows the NPC to properly display the selection of item categories.
1 parent ad56722 commit 3cd4031

1 file changed

Lines changed: 4 additions & 149 deletions

File tree

data-otservbr-global/npc/battlemart.lua

Lines changed: 4 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -50,157 +50,12 @@ npcType.onCloseChannel = function(npc, creature)
5050
npcHandler:onCloseChannel(npc, creature)
5151
end
5252

53-
local itemsTable = {
54-
["foods"] = {
55-
{ itemName = "brown mushroom", clientId = 3725, buy = 10 },
56-
{ itemName = "fire mushroom", clientId = 3731, buy = 300 },
57-
},
58-
["exercise weapons"] = {
59-
{ itemName = "enhanced exercise axe", clientId = 35280, buy = 2340000 },
60-
{ itemName = "enhanced exercise bow", clientId = 35282, buy = 2340000 },
61-
{ itemName = "enhanced exercise club", clientId = 35281, buy = 2340000 },
62-
{ itemName = "enhanced exercise rod", clientId = 35283, buy = 2340000 },
63-
{ itemName = "enhanced exercise shield", clientId = 44066, buy = 2340000 },
64-
{ itemName = "enhanced exercise sword", clientId = 35279, buy = 2340000 },
65-
{ itemName = "enhanced exercise wand", clientId = 35284, buy = 2340000 },
66-
{ itemName = "exercise axe", clientId = 28553, buy = 1800000 },
67-
{ itemName = "exercise bow", clientId = 28555, buy = 1800000 },
68-
{ itemName = "exercise club", clientId = 28554, buy = 1800000 },
69-
{ itemName = "exercise rod", clientId = 28556, buy = 1800000 },
70-
{ itemName = "exercise sword", clientId = 28552, buy = 1800000 },
71-
{ itemName = "exercise wand", clientId = 28557, buy = 1800000 },
72-
{ itemName = "masterful exercise axe", clientId = 35286, buy = 2700000 },
73-
{ itemName = "masterful exercise bow", clientId = 35288, buy = 2700000 },
74-
{ itemName = "masterful exercise club", clientId = 35287, buy = 2700000 },
75-
{ itemName = "masterful exercise rod", clientId = 35289, buy = 2700000 },
76-
{ itemName = "masterful exercise shield", clientId = 44067, buy = 2700000 },
77-
{ itemName = "masterful exercise sword", clientId = 35285, buy = 2700000 },
78-
{ itemName = "masterful exercise wand", clientId = 35290, buy = 2700000 },
79-
},
80-
["distance equipments"] = {
81-
{ itemName = "envenomed arrow", clientId = 16143, buy = 12 },
82-
{ itemName = "diamond arrow", clientId = 35901, buy = 100 },
83-
{ itemName = "drill bolt", clientId = 16142, buy = 12 },
84-
{ itemName = "crystalline arrow", clientId = 15793, buy = 20 },
85-
{ itemName = "blue quiver", clientId = 35848, buy = 400 },
86-
{ itemName = "bolt", clientId = 3446, buy = 4 },
87-
{ itemName = "bow", clientId = 3350, buy = 400 },
88-
{ itemName = "arrow", clientId = 3447, buy = 3 },
89-
{ itemName = "assassin star", clientId = 7368, buy = 100 },
90-
{ itemName = "earth arrow", clientId = 774, buy = 5 },
91-
{ itemName = "enchanted spear", clientId = 7367, buy = 30 },
92-
{ itemName = "flaming arrow", clientId = 763, buy = 5 },
93-
{ itemName = "flash arrow", clientId = 761, buy = 5 },
94-
{ itemName = "royal star", clientId = 25759, buy = 110 },
95-
{ itemName = "quiver", clientId = 35562, buy = 400 },
96-
{ itemName = "red quiver", clientId = 35849, buy = 400 },
97-
{ itemName = "power bolt", clientId = 3450, buy = 7 },
98-
{ itemName = "piercing bolt", clientId = 7363, buy = 5 },
99-
{ itemName = "onyx arrow", clientId = 7365, buy = 7 },
100-
{ itemName = "prismatic bolt", clientId = 16141, buy = 20 },
101-
{ itemName = "shiver arrow", clientId = 762, buy = 5 },
102-
{ itemName = "sniper arrow", clientId = 7364, buy = 5 },
103-
{ itemName = "spear", clientId = 3277, buy = 5 },
104-
{ itemName = "spectral bolt", clientId = 35902, buy = 70 },
105-
{ itemName = "throwing star", clientId = 3287, buy = 42 },
106-
{ itemName = "tarsal arrow", clientId = 14251, buy = 6 },
107-
{ itemName = "vortex bolt", clientId = 14252, buy = 6 },
108-
{ itemName = "hunting spear", clientId = 3347, buy = 25 },
109-
},
110-
["runes"] = {
111-
{ itemName = "avalanche rune", clientId = 3161, buy = 57 },
112-
{ itemName = "blank rune", clientId = 3147, buy = 10 },
113-
{ itemName = "chameleon rune", clientId = 3178, buy = 210 },
114-
{ itemName = "animate dead rune", clientId = 3203, buy = 375 },
115-
{ itemName = "convince creature rune", clientId = 3177, buy = 80 },
116-
{ itemName = "cure poison rune", clientId = 3153, buy = 65 },
117-
{ itemName = "desintegrate rune", clientId = 3197, buy = 26 },
118-
{ itemName = "destroy field rune", clientId = 3148, buy = 15 },
119-
{ itemName = "energy wall rune", clientId = 3166, buy = 85 },
120-
{ itemName = "energy bomb rune", clientId = 3149, buy = 203 },
121-
{ itemName = "energy field rune", clientId = 3164, buy = 38 },
122-
{ itemName = "explosion rune", clientId = 3200, buy = 31 },
123-
{ itemName = "fire bomb rune", clientId = 3192, buy = 147 },
124-
{ itemName = "fire field rune", clientId = 3188, buy = 28 },
125-
{ itemName = "fire wall rune", clientId = 3190, buy = 61 },
126-
{ itemName = "fireball rune", clientId = 3189, buy = 30 },
127-
{ itemName = "great fireball rune", clientId = 3191, buy = 57 },
128-
{ itemName = "heavy magic missile rune", clientId = 3198, buy = 12 },
129-
{ itemName = "holy missile rune", clientId = 3182, buy = 16 },
130-
{ itemName = "icicle rune", clientId = 3158, buy = 30 },
131-
{ itemName = "intense healing rune", clientId = 3152, buy = 95 },
132-
{ itemName = "light magic missile rune", clientId = 3174, buy = 4 },
133-
{ itemName = "magic wall rune", clientId = 3180, buy = 116 },
134-
{ itemName = "paralyze rune", clientId = 3165, buy = 700 },
135-
{ itemName = "poison bomb rune", clientId = 3173, buy = 85 },
136-
{ itemName = "poison field rune", clientId = 3172, buy = 21 },
137-
{ itemName = "poison wall rune", clientId = 3176, buy = 52 },
138-
{ itemName = "stone shower rune", clientId = 3175, buy = 37 },
139-
{ itemName = "stalagmite rune", clientId = 3179, buy = 12 },
140-
{ itemName = "sudden death rune", clientId = 3155, buy = 135 },
141-
{ itemName = "soulfire rune", clientId = 3195, buy = 46 },
142-
{ itemName = "thunderstorm rune", clientId = 3202, buy = 47 },
143-
{ itemName = "ultimate healing rune", clientId = 3160, buy = 175 },
144-
{ itemName = "wild growth rune", clientId = 3156, buy = 160 },
145-
},
146-
["tools"] = {
147-
{ itemName = "fishing rod", clientId = 3483, buy = 150 },
148-
{ itemName = "flask of rust remover", clientId = 9016, buy = 50 },
149-
{ itemName = "torch", clientId = 2920, buy = 2 },
150-
{ itemName = "worm", clientId = 3492, buy = 1 },
151-
{ itemName = "crowbar", clientId = 3304, buy = 260 },
152-
{ itemName = "backpack", clientId = 2854, buy = 20 },
153-
},
154-
["amulets"] = {
155-
{ itemName = "gill necklace", clientId = 16108, buy = 20000 },
156-
{ itemName = "glacier amulet", clientId = 815, buy = 15000 },
157-
{ itemName = "leviathan's amulet", clientId = 9303, buy = 30000 },
158-
{ itemName = "magma amulet", clientId = 817, buy = 15000 },
159-
{ itemName = "lightning pendant", clientId = 816, buy = 15000 },
160-
{ itemName = "prismatic necklace", clientId = 16113, buy = 20000 },
161-
{ itemName = "sacred tree amulet", clientId = 9302, buy = 30000 },
162-
{ itemName = "shockwave amulet", clientId = 9304, buy = 30000 },
163-
{ itemName = "stone skin amulet", clientId = 3081, buy = 5000 },
164-
{ itemName = "collar of blue plasma", clientId = 23542, buy = 60000 },
165-
{ itemName = "collar of green plasma", clientId = 23543, buy = 60000 },
166-
{ itemName = "collar of red plasma", clientId = 23544, buy = 60000 },
167-
{ itemName = "terra amulet", clientId = 814, buy = 15000 },
168-
},
169-
["rings"] = {
170-
{ itemName = "life ring", clientId = 3052, buy = 900 },
171-
{ itemName = "might ring", clientId = 3048, buy = 5000 },
172-
{ itemName = "ring of blue plasma", clientId = 23529, buy = 80000 },
173-
{ itemName = "ring of green plasma", clientId = 23531, buy = 80000 },
174-
{ itemName = "ring of healing", clientId = 3098, buy = 2000 },
175-
{ itemName = "prismatic ring", clientId = 16114, buy = 100000 },
176-
{ itemName = "ring of red plasma", clientId = 23533, buy = 80000 },
177-
{ itemName = "stealth ring", clientId = 3049, buy = 5000 },
178-
{ itemName = "time ring", clientId = 3053, buy = 2000 },
179-
{ itemName = "dwarven ring", clientId = 3097, buy = 2000 },
180-
{ itemName = "energy ring", clientId = 3051, buy = 2000 },
181-
},
182-
["potions"] = {
183-
{ itemName = "great health potion", clientId = 239, buy = 225 },
184-
{ itemName = "great mana potion", clientId = 238, buy = 144 },
185-
{ itemName = "great spirit potion", clientId = 7642, buy = 228 },
186-
{ itemName = "health potion", clientId = 266, buy = 50 },
187-
{ itemName = "mana potion", clientId = 268, buy = 56 },
188-
{ itemName = "mana shield potion", clientId = 35563, buy = 200000 },
189-
{ itemName = "ultimate health potion", clientId = 7643, buy = 379 },
190-
{ itemName = "ultimate mana potion", clientId = 23373, buy = 438 },
191-
{ itemName = "ultimate spirit potion", clientId = 23374, buy = 438 },
192-
{ itemName = "supreme health potion", clientId = 23375, buy = 625 },
193-
{ itemName = "strong health potion", clientId = 236, buy = 115 },
194-
{ itemName = "strong mana potion", clientId = 237, buy = 93 },
195-
},
196-
}
197-
19853
local function creatureSayCallback(npc, player, type, message)
199-
local categoryTable = itemsTable[message:lower()]
54+
local categoryTable = SupplyShopConfigTable[message:lower()]
20055
if MsgContains(message, "shop options") then
201-
npcHandler:say("I sell a selection of " .. npc:getFormattedCategoryNames(itemsTable), npc, player)
56+
npcHandler:say("I sell a selection of " .. GetFormattedShopCategoryNames(SupplyShopConfigTable), npc, player)
20257
elseif categoryTable then
203-
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
58+
local remainingCategories = npc:getRemainingShopCategories(message:lower(), SupplyShopConfigTable)
20459
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
20560
npc:openShopWindowTable(player, categoryTable)
20661
end
@@ -209,7 +64,7 @@ end
20964
npcHandler:setMessage(MESSAGE_GREET, "It is good to see you. I'm always at your {shop options}")
21065
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, |PLAYERNAME|, I'll be here if you need me again.")
21166
npcHandler:setMessage(MESSAGE_WALKAWAY, "Come back soon!")
212-
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
67+
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(SupplyShopConfigTable) .. ".")
21368

21469
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
21570
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

0 commit comments

Comments
 (0)