local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
local talk = {}
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
shopModule:addBuyableItem({'Donator Helmet'}, 9778, 1700, 1, 'Donator Helmet')
shopModule:addBuyableItem({'Donator Armor'}, 9776, 2000, 1, 'Donator Armor')
shopModule:addBuyableItem({'Donator Legs'}, 9777, 2000, 1, 'Donator Legs')
shopModule:addBuyableItem({'Donator Boots'}, 11118, 1800, 1, 'Donator Boots')
shopModule:addBuyableItem({'Witchhunters Cloak'}, 8821, 2000, 1, 'Witchunters Cloak')
shopModule:addBuyableItem({'Donator Sword'}, 11307, 3000, 1, 'Donator Sword')
shopModule:addBuyableItem({'Donator Axe'}, 11323, 3000, 1, 'Donator Axe')
shopModule:addBuyableItem({'Donator Club'}, 11308, 3000, 1, 'Donator Club')
shopModule:addBuyableItem({'Donator Wand'}, 2453, 3000, 1, 'Donator Wand')
shopModule:addBuyableItem({'Donator Rod'}, 2184, 3000, 1, 'Donator Rod')
shopModule:addBuyableItem({'Donator Ring'}, 7697, 3650, 1, 'Donator Ring')
shopModule:addBuyableItem({'Donator Shield'}, 6433, 2000, 1, 'Donator Shield')
shopModule:addBuyableItem({'Donator Spellbook'}, 8903, 2000, 1, 'Donator Spellbook')
shopModule:addBuyableItem({'Donator Bow'}, 8858, 1000, 1, 'Donator Bow')
shopModule:addBuyableItem({'Donator Arrow'}, 2352, 2000, 1, 'Donator Arrow')
shopModule:addBuyableItem({'Frost Charm'}, 7289, 2800, 1, 'Frost Charm')
shopModule:addBuyableItem({'Donator Uh'}, 2270, 3000, 1, 'Donator Uh')
shopModule:addBuyableItem({'Donator Manarune'}, 2294, 3000, 1, 'Donator Manarune')
function callbackBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks)
local shopItem = nil
for _, item in ipairs(npcHandler.shopItems) do
if(item.id == itemid and item.subType == subType) then
shopItem = item
break
end
end
if(shopItem == nil) then
print("[ShopModule.onBuy]", "Item not found on shopItems list")
return false
end
if(shopItem.buy == -1) then
print("[ShopModule.onSell]", "Attempt to purchase an item which only sellable")
return false
end
if(amount <= 0) then
print("[ShopModule.onSell]", "Attempt to purchase " .. amount .. " items")
return false
end
local totalCost = amount * shopItem.buy
local parseInfo = {
[TAG_PLAYERNAME] = getPlayerName(cid),
[TAG_ITEMCOUNT] = amount,
[TAG_TOTALCOST] = totalCost,
[TAG_ITEMNAME] = shopItem.name
}
if(getPlayerItemCount(cid, 2157) < totalCost) then
local msg = npcHandler:getMessage(MESSAGE_NEEDMONEY)
doPlayerSendCancel(cid, npcHandler:parseMessage(msg, parseInfo))
return false
end
local subType = shopItem.subType or 1
local a, b = doNpcSellItem(cid, itemid, amount, subType, ignoreCap, false, backpack)
if(a < amount) then
local msgId = MESSAGE_NEEDMORESPACE
if(a == 0) then
msgId = MESSAGE_NEEDSPACE
end
local msg = npcHandler:getMessage(msgId)
parseInfo[TAG_ITEMCOUNT] = a
doPlayerSendCancel(cid, npcHandler:parseMessage(msg, parseInfo))
if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
npcHandler.talkStart[cid] = os.time()
else
npcHandler.talkStart = os.time()
end
if(a > 0) then
doPlayerRemoveItem(cid, 2157, a * shopItem.buy)
return true
end
return false
end
local msg = npcHandler:getMessage(MESSAGE_BOUGHT)
msg = string.reverse(string.gsub(string.reverse(msg), 'dlog', 'steggun dlog'))
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, npcHandler:parseMessage(msg, parseInfo))
doPlayerRemoveItem(cid, 2157, totalCost)
if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
npcHandler.talkStart[cid] = os.time()
else
npcHandler.talkStart = os.time()
end
return true
end
function callbackSell(cid, itemid, subType, amount, ignoreCap, inBackpacks)
local shopItem = nil
for _, item in ipairs(npcHandler.shopItems) do
if(item.id == itemid and item.subType == subType) then
shopItem = item
break
end
end
if(shopItem == nil) then
print("[ShopModule.onBuy]", "Item not found on shopItems list")
return false
end
if(shopItem.sell == -1) then
print("[ShopModule.onSell]", "Attempt to sell an item which is only buyable")
return false
end
local parseInfo = {
[TAG_PLAYERNAME] = getPlayerName(cid),
[TAG_ITEMCOUNT] = amount,
[TAG_TOTALCOST] = amount * shopItem.sell,
[TAG_ITEMNAME] = shopItem.name
}
if(subType < 1 or getItemInfo(itemid).stackable) then
subType = -1
end
if(doPlayerRemoveItem(cid, itemid, amount, subType)) then
local msg = npcHandler:getMessage(MESSAGE_SOLD)
msg = string.reverse(string.gsub(string.reverse(msg), 'dlog', 'steggun dlog'))
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, npcHandler:parseMessage(msg, parseInfo))
doPlayerAddItem(cid, 2157, amount * shopItem.sell)
if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
npcHandler.talkStart[cid] = os.time()
else
npcHandler.talkStart = os.time()
end
return true
end
local msg = npcHandler:getMessage(MESSAGE_NEEDITEM)
doPlayerSendCancel(cid, npcHandler:parseMessage(msg, parseInfo))
if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
npcHandler.talkStart[cid] = os.time()
else
npcHandler.talkStart = os.time()
end
return false
end
npcHandler:setCallback(CALLBACK_ONBUY, callbackBuy)
npcHandler:setCallback(CALLBACK_ONSELL, callbackSell)
npcHandler:addModule(FocusModule:new())