Good morning, NPC Yaman shows items to sell that the player doesn't have. Any solution?
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Yaman" script="Yaman.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100" />
<look type="103" />
<parameters>
<parameter key="module_shop" value="1" />
<parameter key="shop_buyable" value="
dragon necklace, 2201, 1000,200;
dwarven ring, 2213, 2000;
energy ring, 2167, 2000;
life ring, 2168, 900;
might ring, 2164, 5000,20;
protection amulet, 2200, 700,250;
ring of healing, 2216, 2000;
silver amulet, 2170, 100,200;
strange talisman, 2161, 100,200;
time ring, 2169, 2000" />
<parameter key="shop_sellable" value="
ankh, 2327, 100;
dragon necklace, 2201,100;
dwarven ring, 2213, 100;
energy ring, 2167, 100;
glacial rod, 18412, 6500;
hailstorm rod, 2183, 3000;
life ring, 2168, 50;
might ring, 2164, 250;
moonlight rod, 2186, 200;
muck rod, 18411, 6000;
mysterious fetish, 2194, 50;
necrotic rod, 2185, 1000;
northwind rod, 8911, 1500;
protection amulet, 2200, 100;
ring of healing, 2216, 100;
silver amulet, 2170, 50;
snakebite rod, 2182, 100;
springsprout rod, 8912, 3600;
strange talisman, 2161, 30;
terra rod, 2181, 2000;
time ring, 2169, 100;
underworld rod, 8910, 4400" />
</parameters>
</npc>
Lua:
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 function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if isInArray({"enchanted chicken wing", "boots of haste", "Enchanted Chicken Wing", "Boots of Haste"}, msg) then
npcHandler:say('Do you want to trade Boots of haste for Enchanted Chicken Wing?', cid)
npcHandler.topic[cid] = 1
elseif isInArray({"warrior sweat", "warrior helmet", "Warrior Sweat", "Warrior Helmet"}, msg) then
npcHandler:say('Do you want to trade 4 Warrior Helmet for Warrior Sweat?', cid)
npcHandler.topic[cid] = 2
elseif isInArray({"fighting spirit", "royal helmet", "Fighting Spirit", "Royal Helmet"}, msg) then
npcHandler:say('Do you want to trade 2 Royal Helmet for Fighting Spirit', cid)
npcHandler.topic[cid] = 3
elseif isInArray({"magic sulphur", "fire sword", "Magic Sulphur", "Fire Sword"}, msg) then
npcHandler:say('Do you want to trade 3 Fire Sword for Magic Sulphur', cid)
npcHandler.topic[cid] = 4
elseif isInArray({"job", "items", "Items", "Job"}, msg) then
npcHandler:say('I trade Enchanted Chicken Wing for Boots of Haste, Warrior Sweat for 4 Warrior Helmets, Fighting Spirit for 2 Royal Helmet Magic Sulphur for 3 Fire Swords', cid)
npcHandler.topic[cid] = 0
elseif msgcontains(msg, 'cookie') then
if player:getStorageValue(Storage.WhatAFoolishQuest.Questline) == 31
and player:getStorageValue(Storage.WhatAFoolishQuest.CookieDelivery.Djinn) ~= 1 then
npcHandler:say('You brought cookies! How nice of you! Can I have one?', cid)
npcHandler.topic[cid] = 5
end
elseif msgcontains(msg,'yes') then
if npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 4 then
local trade = {
{ NeedItem = 2195, Ncount = 1, GiveItem = 5891, Gcount = 1}, -- Enchanted Chicken Wing
{ NeedItem = 2475, Ncount = 4, GiveItem = 5885, Gcount = 1}, -- Flask of Warrior's Sweat
{ NeedItem = 2498, Ncount = 2, GiveItem = 5884, Gcount = 1}, -- Spirit Container
{ NeedItem = 2392, Ncount = 3, GiveItem = 5904, Gcount = 1} -- Magic Sulphur
}
if player:getItemCount(trade[npcHandler.topic[cid]].NeedItem) >= trade[npcHandler.topic[cid]].Ncount then
player:removeItem(trade[npcHandler.topic[cid]].NeedItem, trade[npcHandler.topic[cid]].Ncount)
player:addItem(trade[npcHandler.topic[cid]].GiveItem, trade[npcHandler.topic[cid]].Gcount)
return npcHandler:say('Here you are.', cid)
else
npcHandler:say('Sorry but you don\'t have the item.', cid)
end
elseif npcHandler.topic[cid] == 5 then
if not player:removeItem(8111, 1) then
npcHandler:say('You have no cookie that I\'d like.', cid)
npcHandler.topic[cid] = 0
return true
end
player:setStorageValue(Storage.WhatAFoolishQuest.CookieDelivery.Djinn, 1)
if player:getCookiesDelivered() == 10 then
player:addAchievement('Allow Cookies?')
end
Npc():getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
npcHandler:say('You see, good deeds like this will ... YOU ... YOU SPAWN OF EVIL! I WILL MAKE SURE THE MASTER LEARNS ABOUT THIS!', cid)
npcHandler:releaseFocus(cid)
npcHandler:resetNpc(cid)
end
elseif msgcontains(msg,'no') then
if npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 4 then
npcHandler:say('Ok then.', cid)
npcHandler.topic[cid] = 0
elseif npcHandler.topic[cid] == 5 then
npcHandler:say('I see.', cid)
npcHandler.topic[cid] = 0
end
end
return true
end
local function onTradeRequest(cid)
local player = Player(cid)
if player:getStorageValue(Storage.DjinnWar.EfreetFaction.Mission03) ~= 3 then
npcHandler:say('I\'m sorry, but you don\'t have Malor\'s permission to trade with me.', cid)
return false
end
return true
end
npcHandler:setMessage(MESSAGE_GREET, "Be greeted, human |PLAYERNAME|. How can a humble djinn be of service?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, human.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell, human.")
npcHandler:setMessage(MESSAGE_SENDTRADE, 'At your service, just browse through my wares.')
npcHandler:setCallback(CALLBACK_ONTRADEREQUEST, onTradeRequest)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
local focusModule = FocusModule:new()
focusModule:addGreetMessage('hi')
focusModule:addGreetMessage('hello')
focusModule:addGreetMessage('djanni\'hah')
npcHandler:addModule(focusModule)