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 config = {
ranks = {
rank1 = {
{id = 2597, buy=0, sell = 8, name='letter', name='letter'}, ----- EDIT HERE THE ITEMS IF YOU WANT WITH STORAGE
{id = 2595, buy=0, sell = 15, name='parcel', name='parcel'}
},
rank2 = {
{id = 2597, buy=0, sell = 5, name='letter', name='letter'}, ----- EDIT HERE THE ITEMS IF YOU WANT WITH STORAGE
{id = 2595, buy=0, sell = 10, name='parcel', name='parcel'}
}
}
}
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(npcHandler.focus ~= cid) then
return false
end
local talkUser = cid
if msgcontains(msg, 'trade') then
if getPlayerStorageValue(cid, 60200) == 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
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())