Guest User

Untitled

a guest
Jun 23rd, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.43 KB | None | 0 0
  1. -- Advanced NPC System (Created by Jiddo),
  2. -- Modified by Cykotitan, Elf and Talaturen.
  3.  
  4. if(Modules == nil) then
  5. -- default words for greeting and ungreeting the npc. Should be a table containing all such words.
  6. FOCUS_GREETWORDS = {"hi", "hello"}
  7. FOCUS_FAREWELLWORDS = {"bye", "farewell"}
  8.  
  9. -- The words for requesting trade window.
  10. SHOP_TRADEREQUEST = {"trade"}
  11.  
  12. -- The word for accepting/declining an offer. CAN ONLY CONTAIN ONE FIELD! Should be a teble with a single string value.
  13. SHOP_YESWORD = {"yes"}
  14. SHOP_NOWORD = {"no"}
  15.  
  16. -- Pattern used to get the amount of an item a player wants to buy/sell.
  17. PATTERN_COUNT = "%d+"
  18.  
  19. -- Constants used to separate buying from selling.
  20. SHOPMODULE_SELL_ITEM = 1
  21. SHOPMODULE_BUY_ITEM = 2
  22. SHOPMODULE_BUY_ITEM_CONTAINER = 3
  23.  
  24. -- Constants used for shop mode. Notice: addBuyableItemContainer is working on all modes
  25. SHOPMODULE_MODE_TALK = 1 -- Old system used before Tibia 8.2: sell/buy item name
  26. SHOPMODULE_MODE_TRADE = 2 -- Trade window system introduced in Tibia 8.2
  27. SHOPMODULE_MODE_BOTH = 3 -- Both working at one time
  28.  
  29. -- Used shop mode
  30. SHOPMODULE_MODE = SHOPMODULE_MODE_BOTH
  31.  
  32. Modules = {
  33. parseableModules = {}
  34. }
  35.  
  36. StdModule = {}
  37.  
  38. -- These callback function must be called with parameters.npcHandler = npcHandler in the parameters table or they will not work correctly.
  39. -- Notice: The members of StdModule have not yet been tested. If you find any bugs, please report them to me.
  40. -- Usage:
  41. -- keywordHandler:addKeyword({"offer"}, StdModule.say, {npcHandler = npcHandler, text = "I sell many powerful melee weapons."})
  42. function StdModule.say(cid, message, keywords, parameters, node)
  43. local npcHandler = parameters.npcHandler
  44. if(npcHandler == nil) then
  45. error("StdModule.say called without any npcHandler instance.")
  46. end
  47. local onlyFocus = (parameters.onlyFocus == nil or parameters.onlyFocus == true)
  48. if(not npcHandler:isFocused(cid) and onlyFocus) then
  49. return false
  50. end
  51.  
  52. local parseInfo = {[TAG_PLAYERNAME] = getCreatureName(cid)}
  53. npcHandler:say(npcHandler:parseMessage(parameters.text or parameters.message, parseInfo), cid, parameters.publicize and true)
  54. if(parameters.reset == true) then
  55. npcHandler:resetNpc()
  56. elseif(parameters.moveup ~= nil and type(parameters.moveup) == "number") then
  57. npcHandler.keywordHandler:moveUp(parameters.moveup)
  58. end
  59.  
  60. return true
  61. end
  62.  
  63. --Usage:
  64. -- local node1 = keywordHandler:addKeyword({"promot"}, StdModule.say, {npcHandler = npcHandler, text = "I can promote you for 20000 gold coins. Do you want me to promote you?"})
  65. -- node1:addChildKeyword({"yes"}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20}, text = "Congratulations! You are now promoted.")
  66. -- node1:addChildKeyword({"no"}, StdModule.say, {npcHandler = npcHandler, text = "Allright then. Come back when you are ready."}, reset = true)
  67. function StdModule.promotePlayer(cid, message, keywords, parameters, node)
  68. local npcHandler = parameters.npcHandler
  69. if(npcHandler == nil) then
  70. error("StdModule.promotePlayer called without any npcHandler instance.")
  71. end
  72. if(not npcHandler:isFocused(cid)) then
  73. return false
  74. end
  75.  
  76. if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
  77. local promotedVoc = getPromotedVocation(getPlayerVocation(cid))
  78. if(getPlayerStorageValue(cid, 30018) == TRUE) then
  79. npcHandler:say("You are already promoted!", cid)
  80. elseif(getPlayerLevel(cid) < parameters.level) then
  81. npcHandler:say("I am sorry, but I can only promote you once you have reached level " .. parameters.level .. ".", cid)
  82. elseif(doPlayerRemoveItem(cid, 2159, parameters.cost) ~= TRUE) then
  83. npcHandler:say("You do not have enough money!", cid)
  84. else
  85. doPlayerSetVocation(cid, promotedVoc)
  86. npcHandler:say(parameters.text, cid)
  87. end
  88. else
  89. npcHandler:say("You need a premium account in order to get promoted.", cid)
  90. end
  91. npcHandler:resetNpc()
  92. return true
  93. end
  94.  
  95. function StdModule.learnSpell(cid, message, keywords, parameters, node)
  96. local npcHandler = parameters.npcHandler
  97. if(npcHandler == nil) then
  98. error("StdModule.learnSpell called without any npcHandler instance.")
  99. end
  100.  
  101. if(not npcHandler:isFocused(cid)) then
  102. return false
  103. end
  104.  
  105. if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) or not parameters.premium) then
  106. if getPlayerLearnedInstantSpell(cid, parameters.spellName) == TRUE then
  107. npcHandler:say("You already know this spell.", cid)
  108. elseif getPlayerLevel(cid) < parameters.level then
  109. npcHandler:say("You need to obtain a level of " .. parameters.level .. " or higher to be able to learn " .. parameters.spellName .. ".", cid)
  110. elseif getPlayerVocation(cid) ~= parameters.vocation and getPlayerVocation(cid) ~= parameters.vocation + 4 and vocation ~= 9 then
  111. npcHandler:say("This spell is not for your vocation", cid)
  112. elseif doPlayerRemoveMoney(cid, parameters.price) == FALSE then
  113. npcHandler:say("You do not have enough money, this spell costs " .. parameters.price .. " gold.", cid)
  114. else
  115. npcHandler:say("You have learned " .. parameters.spellName .. ".", cid)
  116. playerLearnInstantSpell(cid, parameters.spellName)
  117. end
  118. else
  119. npcHandler:say("You need a premium account in order to buy " .. parameters.spellName .. ".", cid)
  120. end
  121.  
  122. npcHandler:resetNpc()
  123. return true
  124. end
  125.  
  126. function StdModule.bless(cid, message, keywords, parameters, node)
  127. local npcHandler = parameters.npcHandler
  128. if(npcHandler == nil) then
  129. error("StdModule.bless called without any npcHandler instance.")
  130. end
  131.  
  132. if(not npcHandler:isFocused(cid) or getWorldType() == WORLD_TYPE_PVP_ENFORCED) then
  133. return false
  134. end
  135.  
  136. if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
  137. if getPlayerBlessing(cid, parameters.bless) then
  138. npcHandler:say("Gods have already blessed you with this blessing!", cid)
  139. elseif doPlayerRemoveMoney(cid, parameters.cost) == FALSE then
  140. npcHandler:say("You don't have enough money for blessing.", cid)
  141. else
  142. npcHandler:say("You have been blessed by one of the five gods!", cid)
  143. doPlayerAddBlessing(cid, parameters.bless)
  144. end
  145. else
  146. npcHandler:say("You need a premium account in order to be blessed.", cid)
  147. end
  148.  
  149. npcHandler:resetNpc()
  150. return true
  151. end
  152.  
  153. function StdModule.travel(cid, message, keywords, parameters, node)
  154. local npcHandler = parameters.npcHandler
  155. if(npcHandler == nil) then
  156. error("StdModule.travel called without any npcHandler instance.")
  157. end
  158. if(not npcHandler:isFocused(cid)) then
  159. return false
  160. end
  161. if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
  162. if(isPlayerPzLocked(cid)) then
  163. npcHandler:say("First get rid of those blood stains! You are not going to ruin my vehicle!", cid)
  164. elseif(parameters.level ~= nil and getPlayerLevel(cid) < parameters.level) then
  165. npcHandler:say("You must reach level " .. parameters.level .. " before I can let you go there.", cid)
  166. elseif(doPlayerRemoveMoney(cid, parameters.cost) ~= TRUE) then
  167. npcHandler:say("You don't have enough money.", cid)
  168. else
  169. npcHandler:say(parameters.msg or "Set the sails!", cid)
  170. npcHandler:releaseFocus(cid)
  171. doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
  172. doTeleportThing(cid, parameters.destination)
  173. doSendMagicEffect(parameters.destination, CONST_ME_TELEPORT)
  174. end
  175. else
  176. npcHandler:say("I'm sorry, but you need a premium account in order to travel onboard our ships.", cid)
  177. end
  178. npcHandler:resetNpc()
  179. return true
  180. end
  181.  
  182. FocusModule = {
  183. npcHandler = nil
  184. }
  185.  
  186. -- Creates a new instance of FocusModule without an associated NpcHandler.
  187. function FocusModule:new()
  188. local obj = {}
  189. setmetatable(obj, self)
  190. self.__index = self
  191. return obj
  192. end
  193.  
  194. -- Inits the module and associates handler to it.
  195. function FocusModule:init(handler)
  196. self.npcHandler = handler
  197. for i, word in pairs(FOCUS_GREETWORDS) do
  198. local obj = {}
  199. table.insert(obj, word)
  200. obj.callback = FOCUS_GREETWORDS.callback or FocusModule.messageMatcher
  201. handler.keywordHandler:addKeyword(obj, FocusModule.onGreet, {module = self})
  202. end
  203.  
  204. for i, word in pairs(FOCUS_FAREWELLWORDS) do
  205. local obj = {}
  206. table.insert(obj, word)
  207. obj.callback = FOCUS_FAREWELLWORDS.callback or FocusModule.messageMatcher
  208. handler.keywordHandler:addKeyword(obj, FocusModule.onFarewell, {module = self})
  209. end
  210.  
  211. return true
  212. end
  213.  
  214. -- Greeting callback function.
  215. function FocusModule.onGreet(cid, message, keywords, parameters)
  216. parameters.module.npcHandler:onGreet(cid)
  217. return true
  218. end
  219.  
  220. -- UnGreeting callback function.
  221. function FocusModule.onFarewell(cid, message, keywords, parameters)
  222. if(parameters.module.npcHandler:isFocused(cid)) then
  223. parameters.module.npcHandler:onFarewell(cid)
  224. return true
  225. else
  226. return false
  227. end
  228. end
  229.  
  230. -- Custom message matching callback function for greeting messages.
  231. function FocusModule.messageMatcher(keywords, message)
  232. for i, word in pairs(keywords) do
  233. if(type(word) == "string") then
  234. if string.find(message, word) and not string.find(message, "[%w+]" .. word) and not string.find(message, word .. "[%w+]") then
  235. return true
  236. end
  237. end
  238. end
  239. return false
  240. end
  241.  
  242. KeywordModule = {
  243. npcHandler = nil
  244. }
  245. -- Add it to the parseable module list.
  246. Modules.parseableModules["module_keywords"] = KeywordModule
  247.  
  248. function KeywordModule:new()
  249. local obj = {}
  250. setmetatable(obj, self)
  251. self.__index = self
  252. return obj
  253. end
  254.  
  255. function KeywordModule:init(handler)
  256. self.npcHandler = handler
  257. return true
  258. end
  259.  
  260. -- Parses all known parameters.
  261. function KeywordModule:parseParameters()
  262. local ret = NpcSystem.getParameter("keywords")
  263. if(ret ~= nil) then
  264. self:parseKeywords(ret)
  265. end
  266. end
  267.  
  268. function KeywordModule:parseKeywords(data)
  269. local n = 1
  270. for keys in string.gmatch(data, "[^;]+") do
  271. local i = 1
  272.  
  273. local keywords = {}
  274. for temp in string.gmatch(keys, "[^,]+") do
  275. table.insert(keywords, temp)
  276. i = i + 1
  277. end
  278.  
  279. if(i ~= 1) then
  280. local reply = NpcSystem.getParameter("keyword_reply" .. n)
  281. if(reply ~= nil) then
  282. self:addKeyword(keywords, reply)
  283. else
  284. print("[Warning] NpcSystem:", "Parameter '" .. "keyword_reply" .. n .. "' missing. Skipping...")
  285. end
  286. else
  287. print("[Warning] NpcSystem:", "No keywords found for keyword set #" .. n .. ". Skipping...")
  288. end
  289.  
  290. n = n+1
  291. end
  292. end
  293.  
  294. function KeywordModule:addKeyword(keywords, reply)
  295. self.npcHandler.keywordHandler:addKeyword(keywords, StdModule.say, {npcHandler = self.npcHandler, onlyFocus = true, text = reply, reset = true})
  296. end
  297.  
  298. TravelModule = {
  299. npcHandler = nil,
  300. destinations = nil,
  301. yesNode = nil,
  302. noNode = nil,
  303. }
  304. -- Add it to the parseable module list.
  305. Modules.parseableModules["module_travel"] = TravelModule
  306.  
  307. function TravelModule:new()
  308. local obj = {}
  309. setmetatable(obj, self)
  310. self.__index = self
  311. return obj
  312. end
  313.  
  314. function TravelModule:init(handler)
  315. self.npcHandler = handler
  316. self.yesNode = KeywordNode:new(SHOP_YESWORD, TravelModule.onConfirm, {module = self})
  317. self.noNode = KeywordNode:new(SHOP_NOWORD, TravelModule.onDecline, {module = self})
  318. self.destinations = {}
  319. return true
  320. end
  321.  
  322. -- Parses all known parameters.
  323. function TravelModule:parseParameters()
  324. local ret = NpcSystem.getParameter("travel_destinations")
  325. if(ret ~= nil) then
  326. self:parseDestinations(ret)
  327.  
  328. self.npcHandler.keywordHandler:addKeyword({"destination"}, TravelModule.listDestinations, {module = self})
  329. self.npcHandler.keywordHandler:addKeyword({"where"}, TravelModule.listDestinations, {module = self})
  330. self.npcHandler.keywordHandler:addKeyword({"travel"}, TravelModule.listDestinations, {module = self})
  331.  
  332. end
  333. end
  334.  
  335. function TravelModule:parseDestinations(data)
  336. for destination in string.gmatch(data, "[^;]+") do
  337. local i = 1
  338.  
  339. local name = nil
  340. local x = nil
  341. local y = nil
  342. local z = nil
  343. local cost = nil
  344. local premium = false
  345.  
  346. for temp in string.gmatch(destination, "[^,]+") do
  347. if(i == 1) then
  348. name = temp
  349. elseif(i == 2) then
  350. x = tonumber(temp)
  351. elseif(i == 3) then
  352. y = tonumber(temp)
  353. elseif(i == 4) then
  354. z = tonumber(temp)
  355. elseif(i == 5) then
  356. cost = tonumber(temp)
  357. elseif(i == 6) then
  358. premium = temp == "true"
  359. else
  360. print("[Warning : " .. getCreatureName(getNpcCid()) .. "] NpcSystem:", "Unknown parameter found in travel destination parameter.", temp, destination)
  361. end
  362. i = i + 1
  363. end
  364.  
  365. if(name ~= nil and x ~= nil and y ~= nil and z ~= nil and cost ~= nil) then
  366. self:addDestination(name, {x=x, y=y, z=z}, cost, premium)
  367. else
  368. print("[Warning] NpcSystem:", "Parameter(s) missing for travel destination:", name, x, y, z, cost, premium)
  369. end
  370. end
  371. end
  372.  
  373. function TravelModule:addDestination(name, position, price, premium)
  374. table.insert(self.destinations, name)
  375.  
  376. local parameters = {
  377. cost = price,
  378. destination = position,
  379. premium = premium,
  380. module = self
  381. }
  382. local keywords = {}
  383. table.insert(keywords, name)
  384.  
  385. local keywords2 = {}
  386. table.insert(keywords2, "bring me to " .. name)
  387. local node = self.npcHandler.keywordHandler:addKeyword(keywords, TravelModule.travel, parameters)
  388. self.npcHandler.keywordHandler:addKeyword(keywords2, TravelModule.bringMeTo, parameters)
  389. node:addChildKeywordNode(self.yesNode)
  390. node:addChildKeywordNode(self.noNode)
  391.  
  392. if(npcs_loaded_travel[getNpcCid()] == nil) then
  393. npcs_loaded_travel[getNpcCid()] = getNpcCid()
  394. self.npcHandler.keywordHandler:addKeyword({'yes'}, TravelModule.onConfirm, {module = self})
  395. self.npcHandler.keywordHandler:addKeyword({'no'}, TravelModule.onDecline, {module = self})
  396. end
  397. end
  398.  
  399. function TravelModule.travel(cid, message, keywords, parameters, node)
  400. local module = parameters.module
  401. if(not module.npcHandler:isFocused(cid)) then
  402. return false
  403. end
  404.  
  405. local npcHandler = module.npcHandler
  406.  
  407. shop_destination[cid] = parameters.destination
  408. shop_cost[cid] = parameters.cost
  409. shop_premium[cid] = parameters.premium
  410.  
  411. local cost = parameters.cost
  412. local destination = parameters.destination
  413. local premium = parameters.premium
  414.  
  415. module.npcHandler:say("Do you want to travel to " .. keywords[1] .. " for " .. cost .. " gold coins?", cid)
  416. return true
  417. end
  418.  
  419. function TravelModule.onConfirm(cid, message, keywords, parameters, node)
  420. local module = parameters.module
  421. if(not module.npcHandler:isFocused(cid)) then
  422. return false
  423. end
  424.  
  425. if shop_npcuid[cid] ~= getNpcCid() then
  426. return false
  427. end
  428.  
  429. local npcHandler = module.npcHandler
  430.  
  431. local parentParameters = node:getParent():getParameters()
  432. local cost = shop_cost[cid]
  433. local destination = shop_destination[cid]
  434. local premium = shop_premium[cid]
  435.  
  436. if(not isPlayerPremiumCallback or isPlayerPremiumCallback(cid) or shop_premium[cid] ~= true) then
  437. if(doPlayerRemoveMoney(cid, cost) ~= TRUE) then
  438. npcHandler:say("You do not have enough money!", cid)
  439. elseif(isPlayerPzLocked(cid)) then
  440. npcHandler:say("Get out of there with this blood.", cid)
  441. else
  442. npcHandler:say("It was a pleasure doing business with you.", cid)
  443. npcHandler:releaseFocus(cid)
  444. doTeleportThing(cid, destination, 0)
  445. doSendMagicEffect(destination, 10)
  446. end
  447. else
  448. npcHandler:say("I can only allow premium players to travel there.", cid)
  449. end
  450.  
  451. npcHandler:resetNpc()
  452. return true
  453. end
  454.  
  455. -- onDecline keyword callback function. Generally called when the player sais "no" after wanting to buy an item.
  456. function TravelModule.onDecline(cid, message, keywords, parameters, node)
  457. local module = parameters.module
  458. if(not module.npcHandler:isFocused(cid)) or shop_npcuid[cid] ~= getNpcCid() then
  459. return false
  460. end
  461. local parentParameters = node:getParent():getParameters()
  462. local parseInfo = {
  463. [TAG_PLAYERNAME] = getCreatureName(cid),
  464. }
  465. local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_DECLINE), parseInfo)
  466. module.npcHandler:say(msg, cid)
  467. module.npcHandler:resetNpc()
  468. return true
  469. end
  470.  
  471. function TravelModule.bringMeTo(cid, message, keywords, parameters, node)
  472. local module = parameters.module
  473. if(not module.npcHandler:isFocused(cid)) then
  474. return false
  475. end
  476.  
  477. local cost = parameters.cost
  478. local destination = parameters.destination
  479. local premium = parameters.premium
  480.  
  481. if(not isPlayerPremiumCallback or isPlayerPremiumCallback(cid) or parameters.premium ~= true) then
  482. if(doPlayerRemoveMoney(cid, cost) == TRUE) then
  483. doTeleportThing(cid, destination, 0)
  484. doSendMagicEffect(destination, 10)
  485. end
  486. end
  487. return true
  488. end
  489.  
  490. function TravelModule.listDestinations(cid, message, keywords, parameters, node)
  491. local module = parameters.module
  492. if(not module.npcHandler:isFocused(cid)) then
  493. return false
  494. end
  495.  
  496. local msg = "I can bring you to "
  497. --local i = 1
  498. local maxn = table.maxn(module.destinations)
  499. for i, destination in pairs(module.destinations) do
  500. msg = msg .. destination
  501. if(i == maxn -1) then
  502. msg = msg .. " and "
  503. elseif(i == maxn) then
  504. msg = msg .. "."
  505. else
  506. msg = msg .. ", "
  507. end
  508. i = i + 1
  509. end
  510.  
  511. module.npcHandler:say(msg, cid)
  512. module.npcHandler:resetNpc()
  513. return true
  514. end
  515.  
  516. ShopModule = {
  517. npcHandler = nil,
  518. yesNode = nil,
  519. noNode = nil,
  520. noText = "",
  521. maxCount = 100,
  522. amount = 0
  523. }
  524.  
  525. -- Add it to the parseable module list.
  526. Modules.parseableModules["module_shop"] = ShopModule
  527.  
  528. -- Creates a new instance of ShopModule
  529. function ShopModule:new()
  530. local obj = {}
  531. setmetatable(obj, self)
  532. self.__index = self
  533. return obj
  534. end
  535.  
  536. -- Parses all known parameters.
  537. function ShopModule:parseParameters()
  538. local ret = NpcSystem.getParameter("shop_buyable")
  539. if(ret ~= nil) then
  540. self:parseBuyable(ret)
  541. end
  542.  
  543. local ret = NpcSystem.getParameter("shop_sellable")
  544. if(ret ~= nil) then
  545. self:parseSellable(ret)
  546. end
  547.  
  548. local ret = NpcSystem.getParameter("shop_buyable_containers")
  549. if(ret ~= nil) then
  550. self:parseBuyableContainers(ret)
  551. end
  552. end
  553.  
  554. -- Parse a string contaning a set of buyable items.
  555. function ShopModule:parseBuyable(data)
  556. for item in string.gmatch(data, "[^;]+") do
  557. local i = 1
  558.  
  559. local name = nil
  560. local itemid = nil
  561. local cost = nil
  562. local subType = nil
  563. local realName = nil
  564.  
  565. for temp in string.gmatch(item, "[^,]+") do
  566. if(i == 1) then
  567. name = temp
  568. elseif(i == 2) then
  569. itemid = tonumber(temp)
  570. elseif(i == 3) then
  571. cost = tonumber(temp)
  572. elseif(i == 4) then
  573. subType = tonumber(temp)
  574. elseif(i == 5) then
  575. realName = temp
  576. else
  577. print("[Warning : " .. getCreatureName(getNpcCid()) .. "] NpcSystem:", "Unknown parameter found in buyable items parameter.", temp, item)
  578. end
  579. i = i + 1
  580. end
  581.  
  582. if(SHOPMODULE_MODE == SHOPMODULE_MODE_TRADE) then
  583. if(itemid ~= nil and cost ~= nil) then
  584. if((isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) and subType == nil) then
  585. print("[Warning : " .. getCreatureName(getNpcCid()) .. "] NpcSystem:", "SubType missing for parameter item:", item)
  586. else
  587. self:addBuyableItem(nil, itemid, cost, subType, realName)
  588. end
  589. else
  590. print("[Warning] NpcSystem:", "Parameter(s) missing for item:", itemid, cost)
  591. end
  592. else
  593. if(name ~= nil and itemid ~= nil and cost ~= nil) then
  594. if((isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) and subType == nil) then
  595. print("[Warning : " .. getCreatureName(getNpcCid()) .. "] NpcSystem:", "SubType missing for parameter item:", item)
  596. else
  597. local names = {}
  598. table.insert(names, name)
  599. self:addBuyableItem(names, itemid, cost, subType, realName)
  600. end
  601. else
  602. print("[Warning] NpcSystem:", "Parameter(s) missing for item:", name, itemid, cost)
  603. end
  604. end
  605. end
  606. end
  607.  
  608. -- Parse a string contaning a set of sellable items.
  609. function ShopModule:parseSellable(data)
  610. for item in string.gmatch(data, "[^;]+") do
  611. local i = 1
  612.  
  613. local name = nil
  614. local itemid = nil
  615. local cost = nil
  616. local realName = nil
  617.  
  618. for temp in string.gmatch(item, "[^,]+") do
  619. if(i == 1) then
  620. name = temp
  621. elseif(i == 2) then
  622. itemid = tonumber(temp)
  623. elseif(i == 3) then
  624. cost = tonumber(temp)
  625. elseif(i == 4) then
  626. realName = temp
  627. elseif(i == 5) then
  628. subType = tonumber(temp)
  629. else
  630. print("[Warning : " .. getCreatureName(getNpcCid()) .. "] NpcSystem:", "Unknown parameter found in sellable items parameter.", temp, item)
  631. end
  632. i = i + 1
  633. end
  634.  
  635. if(SHOPMODULE_MODE == SHOPMODULE_MODE_TRADE) then
  636. if(itemid ~= nil and cost ~= nil) then
  637. self:addSellableItem(nil, itemid, cost, realName, subType)
  638. else
  639. print("[Warning] NpcSystem:", "Parameter(s) missing for item:", itemid, cost)
  640. end
  641. else
  642. if(name ~= nil and itemid ~= nil and cost ~= nil) then
  643. local names = {}
  644. table.insert(names, name)
  645. self:addSellableItem(names, itemid, cost, realName, subType)
  646. else
  647. print("[Warning] NpcSystem:", "Parameter(s) missing for item:", name, itemid, cost)
  648. end
  649. end
  650. end
  651. end
  652.  
  653. -- Parse a string contaning a set of buyable items.
  654. function ShopModule:parseBuyableContainers(data)
  655. for item in string.gmatch(data, "[^;]+") do
  656. local i = 1
  657.  
  658. local name = nil
  659. local container = nil
  660. local itemid = nil
  661. local cost = nil
  662. local subType = nil
  663. local realName = nil
  664.  
  665. for temp in string.gmatch(item, "[^,]+") do
  666. if(i == 1) then
  667. name = temp
  668. elseif(i == 2) then
  669. itemid = tonumber(temp)
  670. elseif(i == 3) then
  671. itemid = tonumber(temp)
  672. elseif(i == 4) then
  673. cost = tonumber(temp)
  674. elseif(i == 5) then
  675. subType = tonumber(temp)
  676. elseif(i == 6) then
  677. realName = temp
  678. else
  679. print("[Warning : " .. getCreatureName(getNpcCid()) .. "] NpcSystem:", "Unknown parameter found in buyable items parameter.", temp, item)
  680. end
  681. i = i + 1
  682. end
  683.  
  684. if(name ~= nil and container ~= nil and itemid ~= nil and cost ~= nil) then
  685. if((isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) and subType == nil) then
  686. print("[Warning : " .. getCreatureName(getNpcCid()) .. "] NpcSystem:", "SubType missing for parameter item:", item)
  687. else
  688. local names = {}
  689. table.insert(names, name)
  690. self:addBuyableItemContainer(names, container, itemid, cost, subType, realName)
  691. end
  692. else
  693. print("[Warning] NpcSystem:", "Parameter(s) missing for item:", name, container, itemid, cost)
  694. end
  695. end
  696. end
  697.  
  698. -- Initializes the module and associates handler to it.
  699. function ShopModule:init(handler)
  700. self.npcHandler = handler
  701. self.yesNode = KeywordNode:new(SHOP_YESWORD, ShopModule.onConfirm, {module = self})
  702. self.noNode = KeywordNode:new(SHOP_NOWORD, ShopModule.onDecline, {module = self})
  703. self.noText = handler:getMessage(MESSAGE_DECLINE)
  704.  
  705. if(SHOPMODULE_MODE ~= SHOPMODULE_MODE_TALK) then
  706. for i, word in pairs(SHOP_TRADEREQUEST) do
  707. local obj = {}
  708. table.insert(obj, word)
  709. obj.callback = SHOP_TRADEREQUEST.callback or ShopModule.messageMatcher
  710. handler.keywordHandler:addKeyword(obj, ShopModule.requestTrade, {module = self})
  711. end
  712. end
  713.  
  714. return true
  715. end
  716.  
  717. -- Custom message matching callback function for requesting trade messages.
  718. function ShopModule.messageMatcher(keywords, message)
  719. for i, word in pairs(keywords) do
  720. if(type(word) == "string") then
  721. if string.find(message, word) and not string.find(message, "[%w+]" .. word) and not string.find(message, word .. "[%w+]") then
  722. return true
  723. end
  724. end
  725. end
  726.  
  727. return false
  728. end
  729.  
  730. -- Resets the module-specific variables.
  731. function ShopModule:reset()
  732. self.amount = 0
  733. end
  734.  
  735. -- Function used to match a number value from a string.
  736. function ShopModule:getCount(message)
  737. local ret = 1
  738. local b, e = string.find(message, PATTERN_COUNT)
  739. if b ~= nil and e ~= nil then
  740. ret = tonumber(string.sub(message, b, e))
  741. end
  742.  
  743. if(ret <= 0) then
  744. ret = 1
  745. elseif(ret > self.maxCount) then
  746. ret = self.maxCount
  747. end
  748.  
  749. return ret
  750. end
  751.  
  752. -- Adds a new buyable item.
  753. -- names = A table containing one or more strings of alternative names to this item. Used only for old buy/sell system.
  754. -- itemid = The itemid of the buyable item
  755. -- cost = The price of one single item
  756. -- subType - The subType of each rune or fluidcontainer item. Can be left out if it is not a rune/fluidcontainer. Default value is 1.
  757. -- realName - The real, full name for the item. Will be used as ITEMNAME in MESSAGE_ONBUY and MESSAGE_ONSELL if defined. Default value is nil (getItemName will be used)
  758. function ShopModule:addBuyableItem(names, itemid, cost, subType, realName)
  759. if(SHOPMODULE_MODE ~= SHOPMODULE_MODE_TALK) then
  760. if(self.npcHandler.shopItems[itemid] == nil) then
  761. self.npcHandler.shopItems[itemid] = {buyPrice = -1, sellPrice = -1, subType = 1, realName = ""}
  762. end
  763.  
  764. self.npcHandler.shopItems[itemid].buyPrice = cost
  765. self.npcHandler.shopItems[itemid].realName = realName or getItemName(itemid)
  766. self.npcHandler.shopItems[itemid].subType = subType or 1
  767. end
  768.  
  769. if(names ~= nil and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE) then
  770. for i, name in pairs(names) do
  771. local parameters = {
  772. itemid = itemid,
  773. cost = cost,
  774. eventType = SHOPMODULE_BUY_ITEM,
  775. module = self,
  776. realName = realName or getItemName(itemid),
  777. subType = subType or 1
  778. }
  779.  
  780. keywords = {}
  781. table.insert(keywords, "buy")
  782. table.insert(keywords, name)
  783. local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
  784. node:addChildKeywordNode(self.yesNode)
  785. node:addChildKeywordNode(self.noNode)
  786. end
  787. end
  788.  
  789. if(npcs_loaded_shop[getNpcCid()] == nil) then
  790. npcs_loaded_shop[getNpcCid()] = getNpcCid()
  791. self.npcHandler.keywordHandler:addKeyword({'yes'}, ShopModule.onConfirm, {module = self})
  792. self.npcHandler.keywordHandler:addKeyword({'no'}, ShopModule.onDecline, {module = self})
  793. end
  794. end
  795.  
  796. -- Adds a new buyable container of items.
  797. -- names = A table containing one or more strings of alternative names to this item.
  798. -- container = Backpack, bag or any other itemid of container where bought items will be stored
  799. -- itemid = The itemid of the buyable item
  800. -- cost = The price of one single item
  801. -- subType - The subType of each rune or fluidcontainer item. Can be left out if it is not a rune/fluidcontainer. Default value is 1.
  802. -- realName - The real, full name for the item. Will be used as ITEMNAME in MESSAGE_ONBUY and MESSAGE_ONSELL if defined. Default value is nil (getItemName will be used)
  803. function ShopModule:addBuyableItemContainer(names, container, itemid, cost, subType, realName)
  804. if(names ~= nil) then
  805. for i, name in pairs(names) do
  806. local parameters = {
  807. container = container,
  808. itemid = itemid,
  809. cost = cost,
  810. eventType = SHOPMODULE_BUY_ITEM_CONTAINER,
  811. module = self,
  812. realName = realName or getItemName(itemid),
  813. subType = subType or 1
  814. }
  815.  
  816. keywords = {}
  817. table.insert(keywords, "buy")
  818. table.insert(keywords, name)
  819. local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
  820. node:addChildKeywordNode(self.yesNode)
  821. node:addChildKeywordNode(self.noNode)
  822. end
  823. end
  824. end
  825.  
  826. -- Adds a new sellable item.
  827. -- names = A table containing one or more strings of alternative names to this item. Used only by old buy/sell system.
  828. -- itemid = The itemid of the sellable item
  829. -- cost = The price of one single item
  830. -- realName - The real, full name for the item. Will be used as ITEMNAME in MESSAGE_ONBUY and MESSAGE_ONSELL if defined. Default value is nil (getItemName will be used)
  831. function ShopModule:addSellableItem(names, itemid, cost, realName, subType)
  832. if(SHOPMODULE_MODE ~= SHOPMODULE_MODE_TALK) then
  833. if(self.npcHandler.shopItems[itemid] == nil) then
  834. self.npcHandler.shopItems[itemid] = {buyPrice = 0, sellPrice = 0, subType = 0, realName = ""}
  835. end
  836.  
  837. self.npcHandler.shopItems[itemid].sellPrice = cost
  838. self.npcHandler.shopItems[itemid].realName = realName or getItemName(itemid)
  839. end
  840.  
  841. if subType ~= nil then
  842. self.npcHandler.shopItems[itemid].subType = subType
  843. end
  844.  
  845. if(names ~= nil and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE) then
  846. for i, name in pairs(names) do
  847. local parameters = {
  848. itemid = itemid,
  849. cost = cost,
  850. eventType = SHOPMODULE_SELL_ITEM,
  851. module = self,
  852. realName = realName or getItemName(itemid)
  853. }
  854.  
  855. keywords = {}
  856. table.insert(keywords, "sell")
  857. table.insert(keywords, name)
  858. local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
  859. node:addChildKeywordNode(self.yesNode)
  860. node:addChildKeywordNode(self.noNode)
  861. end
  862. end
  863. end
  864.  
  865. -- onModuleReset callback function. Calls ShopModule:reset()
  866. function ShopModule:callbackOnModuleReset()
  867. self:reset()
  868. return true
  869. end
  870.  
  871. -- Callback onBuy() function. If you wish, you can change certain Npc to use your onBuy().
  872. function ShopModule:callbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks)
  873. if(self.npcHandler.shopItems[itemid] == nil) then
  874. error("[ShopModule.onBuy]", "items[itemid] == nil")
  875. return false
  876. end
  877.  
  878. if(self.npcHandler.shopItems[itemid].buyPrice == -1) then
  879. error("[ShopModule.onSell]", "Attempt to buy a non-buyable item")
  880. return false
  881. end
  882.  
  883. local backpack = 1988
  884. local totalCost = amount * self.npcHandler.shopItems[itemid].buyPrice
  885. if(inBackpacks) then
  886. totalCost = isItemStackable(itemid) == TRUE and totalCost + 20 or totalCost + (math.max(1, math.floor(amount / getContainerCapById(backpack))) * 20)
  887. end
  888.  
  889. local parseInfo = {
  890. [TAG_PLAYERNAME] = getPlayerName(cid),
  891. [TAG_ITEMCOUNT] = amount,
  892. [TAG_TOTALCOST] = totalCost,
  893. [TAG_ITEMNAME] = self.npcHandler.shopItems[itemid].realName
  894. }
  895.  
  896. if(getPlayerMoney(cid) < totalCost) then
  897. local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
  898. msg = self.npcHandler:parseMessage(msg, parseInfo)
  899. doPlayerSendCancel(cid, msg)
  900. return false
  901. end
  902.  
  903. local subType = self.npcHandler.shopItems[itemid].subType or 1
  904. local a, b = doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
  905. if(a < amount) then
  906. local msgId = MESSAGE_NEEDMORESPACE
  907. if(a == 0) then
  908. msgId = MESSAGE_NEEDSPACE
  909. end
  910.  
  911. local msg = self.npcHandler:getMessage(msgId)
  912. parseInfo[TAG_ITEMCOUNT] = a
  913. msg = self.npcHandler:parseMessage(msg, parseInfo)
  914. doPlayerSendCancel(cid, msg)
  915. self.npcHandler.talkStart[cid] = os.time()
  916.  
  917. if(a > 0) then
  918. doPlayerRemoveMoney(cid, ((a * self.npcHandler.shopItems[itemid].buyPrice) + (b * 20)))
  919. return true
  920. end
  921.  
  922. return false
  923. else
  924. local msg = self.npcHandler:getMessage(MESSAGE_BOUGHT)
  925. msg = self.npcHandler:parseMessage(msg, parseInfo)
  926. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
  927. doPlayerRemoveMoney(cid, totalCost)
  928. self.npcHandler.talkStart[cid] = os.time()
  929. return true
  930. end
  931. end
  932.  
  933. -- Callback onSell() function. If you wish, you can change certain Npc to use your onSell().
  934. function ShopModule:callbackOnSell(cid, itemid, subType, amount, ignoreCap, inBackpacks)
  935. if(self.npcHandler.shopItems[itemid] == nil) then
  936. error("[ShopModule.onSell]", "items[itemid] == nil")
  937. return false
  938. end
  939.  
  940. if(self.npcHandler.shopItems[itemid].sellPrice == -1) then
  941. error("[ShopModule.onSell]", "Attempt to sell a non-sellable item")
  942. return false
  943. end
  944.  
  945. local parseInfo = {
  946. [TAG_PLAYERNAME] = getPlayerName(cid),
  947. [TAG_ITEMCOUNT] = amount,
  948. [TAG_TOTALCOST] = amount * self.npcHandler.shopItems[itemid].sellPrice,
  949. [TAG_ITEMNAME] = self.npcHandler.shopItems[itemid].realName
  950. }
  951.  
  952. if isItemFluidContainer(itemid) == FALSE then
  953. subType = -1
  954. end
  955.  
  956. if(doPlayerRemoveItem(cid, itemid, amount, subType) == TRUE) then
  957. local msg = self.npcHandler:getMessage(MESSAGE_SOLD)
  958. msg = self.npcHandler:parseMessage(msg, parseInfo)
  959. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
  960. doPlayerAddMoney(cid, amount * self.npcHandler.shopItems[itemid].sellPrice)
  961. self.npcHandler.talkStart[cid] = os.time()
  962. return true
  963. else
  964. local msg = self.npcHandler:getMessage(MESSAGE_NEEDITEM)
  965. msg = self.npcHandler:parseMessage(msg, parseInfo)
  966. doPlayerSendCancel(cid, msg)
  967. self.npcHandler.talkStart[cid] = os.time()
  968. return false
  969. end
  970. end
  971.  
  972. -- Callback for requesting a trade window with the NPC.
  973. function ShopModule.requestTrade(cid, message, keywords, parameters, node)
  974. local module = parameters.module
  975. if(not module.npcHandler:isFocused(cid)) then
  976. return false
  977. end
  978.  
  979. if(not module.npcHandler:onTradeRequest(cid)) then
  980. return false
  981. end
  982.  
  983. local itemWindow = {}
  984. for itemid, attr in pairs(module.npcHandler.shopItems) do
  985. local item = {id = itemid, buy = attr.buyPrice, sell = attr.sellPrice, subType = attr.subType, name = attr.realName}
  986. table.insert(itemWindow, item)
  987. end
  988.  
  989. if(itemWindow[1] == nil) then
  990. local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
  991. local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_NOSHOP), parseInfo)
  992. module.npcHandler:say(msg, cid)
  993. return true
  994. end
  995.  
  996. local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
  997. local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_SENDTRADE), parseInfo)
  998. openShopWindow(cid, itemWindow,
  999. function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks) end,
  1000. function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onSell(cid, itemid, subType, amount, ignoreCap, inBackpacks) end)
  1001. module.npcHandler:say(msg, cid)
  1002. return true
  1003. end
  1004.  
  1005. -- onConfirm keyword callback function. Sells/buys the actual item.
  1006. function ShopModule.onConfirm(cid, message, keywords, parameters, node)
  1007. local module = parameters.module
  1008. if(not module.npcHandler:isFocused(cid)) or shop_npcuid[cid] ~= getNpcCid() then
  1009. return false
  1010. end
  1011. shop_npcuid[cid] = 0
  1012.  
  1013. local parentParameters = node:getParent():getParameters()
  1014. local parseInfo = {
  1015. [TAG_PLAYERNAME] = getPlayerName(cid),
  1016. [TAG_ITEMCOUNT] = shop_amount[cid],
  1017. [TAG_TOTALCOST] = shop_cost[cid] * shop_amount[cid],
  1018. [TAG_ITEMNAME] = shop_rlname[cid]
  1019. }
  1020.  
  1021. if(shop_eventtype[cid] == SHOPMODULE_SELL_ITEM) then
  1022. local ret = doPlayerSellItem(cid, shop_itemid[cid], shop_amount[cid], shop_cost[cid] * shop_amount[cid])
  1023. if(ret == LUA_NO_ERROR) then
  1024. local msg = module.npcHandler:getMessage(MESSAGE_ONSELL)
  1025. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1026. module.npcHandler:say(msg, cid)
  1027. else
  1028. local msg = module.npcHandler:getMessage(MESSAGE_MISSINGITEM)
  1029. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1030. module.npcHandler:say(msg, cid)
  1031. end
  1032. elseif(shop_eventtype[cid] == SHOPMODULE_BUY_ITEM) then
  1033. local cost = shop_cost[cid] * shop_amount[cid]
  1034. if getPlayerMoney(cid) < cost then
  1035. local msg = module.npcHandler:getMessage(MESSAGE_MISSINGMONEY)
  1036. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1037. module.npcHandler:say(msg, cid)
  1038. return false
  1039. end
  1040.  
  1041. local a, b = doNpcSellItem(cid, shop_itemid[cid], shop_amount[cid], shop_subtype[cid], false, false, 1988)
  1042. if(a < shop_amount[cid]) then
  1043. local msgId = MESSAGE_NEEDMORESPACE
  1044. if(a == 0) then
  1045. msgId = MESSAGE_NEEDSPACE
  1046. end
  1047.  
  1048. local msg = module.npcHandler:getMessage(msgId)
  1049. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1050. module.npcHandler:say(msg, cid)
  1051. if(a > 0) then
  1052. doPlayerRemoveMoney(cid, a * shop_cost[cid])
  1053. if shop_itemid[cid] == ITEM_PARCEL then
  1054. doNpcSellItem(cid, ITEM_LABEL, shop_amount[cid], shop_subtype[cid], true, false, 1988)
  1055. end
  1056. return true
  1057. end
  1058. return false
  1059. else
  1060. local msg = module.npcHandler:getMessage(MESSAGE_ONBUY)
  1061. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1062. module.npcHandler:say(msg, cid)
  1063. doPlayerRemoveMoney(cid, cost)
  1064. if shop_itemid[cid] == ITEM_PARCEL then
  1065. doNpcSellItem(cid, ITEM_LABEL, shop_amount[cid], shop_subtype[cid], true, false, 1988)
  1066. end
  1067. return true
  1068. end
  1069. elseif(shop_eventtype[cid] == SHOPMODULE_BUY_ITEM_CONTAINER) then
  1070. local ret = doPlayerBuyItemContainer(cid, shop_container[cid], shop_itemid[cid], shop_amount[cid], shop_cost[cid] * shop_amount[cid], shop_subtype[cid])
  1071. if(ret == LUA_NO_ERROR) then
  1072. local msg = module.npcHandler:getMessage(MESSAGE_ONBUY)
  1073. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1074. module.npcHandler:say(msg, cid)
  1075. else
  1076. local msg = module.npcHandler:getMessage(MESSAGE_MISSINGMONEY)
  1077. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1078. module.npcHandler:say(msg, cid)
  1079. end
  1080. end
  1081.  
  1082. module.npcHandler:resetNpc()
  1083. return true
  1084. end
  1085.  
  1086. -- onDecline keyword callback function. Generally called when the player sais "no" after wanting to buy an item.
  1087. function ShopModule.onDecline(cid, message, keywords, parameters, node)
  1088. local module = parameters.module
  1089. if(not module.npcHandler:isFocused(cid)) or shop_npcuid[cid] ~= getNpcCid() then
  1090. return false
  1091. end
  1092. shop_npcuid[cid] = 0
  1093.  
  1094. local parentParameters = node:getParent():getParameters()
  1095. local parseInfo = {
  1096. [TAG_PLAYERNAME] = getPlayerName(cid),
  1097. [TAG_ITEMCOUNT] = shop_amount[cid],
  1098. [TAG_TOTALCOST] = shop_cost[cid] * shop_amount[cid],
  1099. [TAG_ITEMNAME] = shop_rlname[cid]
  1100. }
  1101.  
  1102. local msg = module.npcHandler:parseMessage(module.noText, parseInfo)
  1103. module.npcHandler:say(msg, cid)
  1104. module.npcHandler:resetNpc()
  1105. return true
  1106. end
  1107.  
  1108. -- tradeItem callback function. Makes the npc say the message defined by MESSAGE_BUY or MESSAGE_SELL
  1109. function ShopModule.tradeItem(cid, message, keywords, parameters, node)
  1110. local module = parameters.module
  1111. if(not module.npcHandler:isFocused(cid)) then
  1112. return false
  1113. end
  1114.  
  1115. if(not module.npcHandler:onTradeRequest(cid)) then
  1116. return true
  1117. end
  1118.  
  1119. local count = module:getCount(message)
  1120. module.amount = count
  1121.  
  1122. shop_amount[cid] = module.amount
  1123. shop_cost[cid] = parameters.cost
  1124. shop_rlname[cid] = parameters.realName
  1125. shop_itemid[cid] = parameters.itemid
  1126. shop_container[cid] = parameters.container
  1127. shop_npcuid[cid] = getNpcCid()
  1128. shop_eventtype[cid] = parameters.eventType
  1129. shop_subtype[cid] = parameters.subType
  1130.  
  1131. local parseInfo = {
  1132. [TAG_PLAYERNAME] = getPlayerName(cid),
  1133. [TAG_ITEMCOUNT] = shop_amount[cid],
  1134. [TAG_TOTALCOST] = shop_cost[cid] * shop_amount[cid],
  1135. [TAG_ITEMNAME] = shop_rlname[cid]
  1136. }
  1137.  
  1138. if(shop_eventtype[cid] == SHOPMODULE_SELL_ITEM) then
  1139. local msg = module.npcHandler:getMessage(MESSAGE_SELL)
  1140. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1141. module.npcHandler:say(msg, cid)
  1142. elseif(shop_eventtype[cid] == SHOPMODULE_BUY_ITEM) then
  1143. local msg = module.npcHandler:getMessage(MESSAGE_BUY)
  1144. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1145. module.npcHandler:say(msg, cid)
  1146. elseif(shop_eventtype[cid] == SHOPMODULE_BUY_ITEM_CONTAINER) then
  1147. local msg = module.npcHandler:getMessage(MESSAGE_BUY)
  1148. msg = module.npcHandler:parseMessage(msg, parseInfo)
  1149. module.npcHandler:say(msg, cid)
  1150. end
  1151. return true
  1152. end
  1153. end
Add Comment
Please, Sign In to add comment