leandroluck
New Member
- Joined
- Dec 24, 2010
- Messages
- 104
- Reaction score
- 1
Code:
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 tradeOffers = {
-- SELL OFFERS
{id=27610, buy=0, sell=10000, name='Bones of Zorvora'},
{id=27608, buy=0, sell=10000, name='Tooth of Tazhadur'},
{id=27607, buy=0, sell=10000, name='Scale of Gelidrazah'},
{id=27606, buy=0, sell=550, name='Dragon Tongue'},
{id=27609, buy=0, sell=10000, name='Horn of Kalyassa'},
{id=27605, buy=0, sell=700, name='Dragon Blood'},
-- BUY OFFERS
{id=2197, buy=5000, sell=0, name='stone skin amulet'},
{id=7887, buy=1500, sell=0, name='terra amulet'},
{id=10219, buy=3000, sell=0, name='sacred tree amulet'},
}
local items, data = {}
for i = 1, #tradeOffers do
data = tradeOffers[i]
items[data.id] = {id = data.id, buy = data.buy, sell = data.sell, name = ItemType(data.id):getName():lower()}
end
local function greetCallback(cid)
npcHandler:setMessage(MESSAGE_GREET, 'Welcome |PLAYERNAME| ... !')
return true
end
local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
local player = Player(cid)
if not ignoreCap and player:getFreeCapacity() < ItemType(items[item].id):getWeight(amount) then
return player:sendTextMessage(MESSAGE_INFO_DESCR, 'You don\'t have enough cap.')
end
if items[item].buy then
if player:removeMoneyNpc(amount * items[item].buy) then
if player:addItem(items[item].id, amount) then
return player:sendTextMessage(MESSAGE_INFO_DESCR, 'Bought '..amount..'x '..items[item].name..' for '..items[item].buy * amount..' gold coins.')
end
end
end
return true
end
local function onSell(cid, item, subType, amount, ignoreCap, inBackpacks)
local player = Player(cid)
if items[item].sell then
if player:addMoney(items[item].sell * amount) then
if player:removeItem(items[item].id, amount) then
return player:sendTextMessage(MESSAGE_INFO_DESCR, 'Sold '..amount..'x '..items[item].name..' for '..items[item].sell * amount..' gold coins.')
end
end
end
return true
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then return false end
local player = Player(cid)
msg = msg:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end)
if msgcontains('trade', msg) then
local tradeItems = {}
if player:isVip() then
tradeItems = tradeOffers
openShopWindow(cid, tradeItems, onBuy, onSell)
return npcHandler:say('It\'s my offer.', cid)
else
return npcHandler:say('You don\'t have vip account.', cid)
end
end
end
npcHandler:setMessage(MESSAGE_FAREWELL, 'Happy hunting, old chap!')
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
my problem is in the sale of the amulet when the player puts to comra 20 amulet the npc discounts the value of 20 plus delivery only 1