local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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 config = {
ranks = {
rank1 = {{id=2389, buy=9, sell=0, name='spear'},
{id=2389, buy=9, sell=0, name='spear'},
{id=2389, buy=9, sell=0, name='spear'},
{id=2389, buy=9, sell=0, name='spear'},},
rank2 = {{id=7378, buy=15, sell=0, name='royal spear'},
{id=7378, buy=15, sell=0, name='royal spear'},
{id=7378, buy=15, sell=0, name='royal spear'},
{id=7378, buy=15, sell=0, name='royal spear'},},
}
}
local Topic = {}
function greetCallback(cid)
Topic[cid] = 0
return true
end
local function setNewTradeTable(table)
local items = {}
for _, v in ipairs(table) do
items[v.id] = {itemId = v.id, buyPrice = v.buy, sellPrice = v.sell, subType = 0, realName = v.name}
end
return items
end
local function setNewLineTable(oldTable, newTable)
for k, v in pairs(oldTable) do
table.insert(newTable, k, v)
end
return true
end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if isInArray({"trade"}, msg:lower()) then
if getPlayerStorageValue(cid, 10102) ~= 1 then
tradeConfig = config.ranks.rank2
else
tradeConfig = config.ranks.rank1
end
local items = setNewTradeTable(tradeConfig)
local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
if ignoreCap == false and (getPlayerFreeCap(cid) < getItemWeight(items[item].itemId, amount) or inBackpacks and getPlayerFreeCap(cid) < (getItemWeight(items[item].itemId, amount) + getItemWeight(1988, 1))) then
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You don\'t have enough cap.')
end
if items[item].buyPrice then
for i = 1, amount do
if inBackpacks then
doPlayerRemoveMoney(cid, amount * items[item].buyPrice + 20)
local backpack = doPlayerAddItem(cid, 1988, 1)
doAddContainerItem(backpack, items[item].itemId, amount)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..(items[item].buyPrice * amount + 20)..' gold coins.')
else
doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
doPlayerAddItem(cid, items[item].itemId, amount, true)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.')
end
end
end
return true
end
local function onSell(cid, item, subType, amount, ignoreCap, inBackpacks)
if items[item].sellPrice then
doPlayerAddMoney(cid, items[item].sellPrice * amount)
doPlayerRemoveItem(cid, items[item].itemId, amount)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You sold '..amount..'x '..items[item].realName..' for '..items[item].sellPrice * amount..' gold coins.')
end
return true
end
openShopWindow(cid, tradeConfig, onBuy, onSell)
return selfSay('It\'s my offer.', cid)
end
if(getPlayerStorageValue(cid, 10101) == -1) then
if(msgcontains(msg, 'help') or msgcontains(msg, 'mission')) then
npcHandler:say("I\'m looking for {sniper gloves}, I can give you a nice addon if you bring it to me. Will you help me with this gloves?", cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerStorageValue(cid, 10101) == -1) then
npcHandler:say("Come back when you get the legendary {sniper gloves}, I think sometime you can kill some hunters in hunter tower.", cid)
setPlayerStorageValue(cid, 10100, 1)
setPlayerStorageValue(cid, 10101, 1)
else
npcHandler:say("Then dont lose my time.", cid)
end
elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
npcHandler:say("Come back if you got that gloves.", cid)
end
elseif(getPlayerStorageValue(cid, 10101) == 1 and getPlayerStorageValue(cid, 10102) == -1) then
if(msgcontains(msg, 'help') or msgcontains(msg, 'mission') or msgcontains(msg, 'sniper gloves')) then
npcHandler:say("Did you get a {sniper gloves} for me?", cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(doPlayerRemoveItem(cid, 5875, 1)) then
npcHandler:say("Thank you, there is your reward. And from now you can {trade} with me.", cid)
doSendMagicEffect(getPlayerPosition(cid), 13)
setPlayerStorageValue(cid,10103,1)
doPlayerAddOutfit(cid, 129, 2)
doPlayerAddOutfit(cid, 137, 1)
setPlayerStorageValue(cid, 10101, 1)
setPlayerStorageValue(cid, 10102, 1)
setPlayerStorageValue(cid, 10103, 1)
setPlayerStorageValue(cid, 10100, -1)
else
npcHandler:say("Come back when you get {sniper gloves} for me!", cid)
end
elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
npcHandler:say("Come back if you got that gloves.", cid)
end
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())