• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[NPC]NPC Sells item only if player have quest done

Zikerus

Nutria Developer
Joined
Mar 13, 2008
Messages
193
Reaction score
0
Location
Poole, UK
Hello everyone, I've done a script, but it doesn't really work :D and I am not sure why :/ How it works? It should add items to trade item list if player tell 'hi' and have quest done or if player say other word ;D This is my code:

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local storvalue = 17000

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

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return FALSE
	end
if msgcontains(msg, 'MagicWord') then
    setPlayerStorageValue(cid, storvalue, 1)
       npcHandler:say('So, you know about MagicWord... Ahh... You disturbed my reading! Anyway, what do you want? Some items for me?', cid)
shopModule:addSellableItem({'Springsprout Rod'},8912,8000,'Springsprout Rod')
shopModule:addSellableItem({'Underworld Rod'},8910,15000,'Underworld Rod')

shopModule:addSellableItem({'Wand of Starstorm'},8920,7500,'Wand of Starstorm')
shopModule:addSellableItem({'Wand of Voodoo'},8922,13750,'Wand of Voodoo')

shopModule:addSellableItem({'Ferumbars' Hat'},5903,1500000,'Ferumbars' Hat')
shopModule:addSellableItem({'Helmet of the Deep'},5461,5000,'Helmet of the Deep')
shopModule:addSellableItem({'Batwing Hat'},10016,1500,'Batwing Hat')
shopModule:addSellableItem({'Yalahari Mask'},9778,65000,'Yalahari Mask')
shopModule:addSellableItem({'Dwarven Helmet'},2502,245000,'Dwarven Helmet')
shopModule:addSellableItem({'Beholder Helmet'},3972,32000,'Beholder Helmet')
shopModule:addSellableItem({'Skull Helmet'},5741,35000,'Skull Helmet')
shopModule:addSellableItem({'Horned Helmet'},2496,2250000,'Horned Helmet')
shopModule:addSellableItem({'Witchhunter's Cloak'},8821,11000,'Witchhunter's Cloak')
shopModule:addSellableItem({'Dragon Robe'},8867,19500,'Dragon Robe')
shopModule:addSellableItem({'Greenwood Coat'},8869,13000,'Greenwood Coat')
shopModule:addSellableItem({'Robe of the Underworld'},8890,25000,'Robe of the Underworld')
shopModule:addSellableItem({'Crystalline Armor'},8878,15700,'Crystalline Armor')
shopModule:addSellableItem({'Divine Plate'},8885,34000,'Divine Plate')
shopModule:addSellableItem({'Frozen Plate'},8887,32500,'Frozen Plate')
shopModule:addSellableItem({'Skullcracker Armor'},8889,31500,'Skullcracker Armor')
shopModule:addSellableItem({'Dragon Scale Mail'},2492,38000,'Dragon Scale Mail')
shopModule:addSellableItem({'Magic Plate Armor'},2472,230000,'Magic Plate Armor')
shopModule:addSellableItem({'Yalahari Armor'},9776,120000,'Yalahari Armor')

shopModule:addSellableItem({'Yalahari Leg Piece'},9777,70000,'Yalahari Leg Piece')
shopModule:addSellableItem({'Golden Legs'},2470,65000,'Golden Legs')


shopModule:addSellableItem({'Spellbook of Dark Mysteries'},8918,65000,'Spellbook of Dark Mysteries')
shopModule:addSellableItem({'Spellbook of Prophecies'},8904,44200,'Spellbook of Prophecies')

shopModule:addBuyableItem({'Helmet of the Deep'},5461,12000,'Helmet of the Deep')
    end
if msgcontains(msg, 'hi') then
    if (getPlayerStorageValue(cid, storvalue) == 1) then
       npcHandler:say('It\'s you again, what can I do for you?.', cid)
shopModule:addSellableItem({'Springsprout Rod'},8912,8000,'Springsprout Rod')
shopModule:addSellableItem({'Underworld Rod'},8910,15000,'Underworld Rod')

shopModule:addSellableItem({'Wand of Starstorm'},8920,7500,'Wand of Starstorm')
shopModule:addSellableItem({'Wand of Voodoo'},8922,13750,'Wand of Voodoo')

shopModule:addSellableItem({'Ferumbars' Hat'},5903,1500000,'Ferumbars' Hat')
shopModule:addSellableItem({'Helmet of the Deep'},5461,5000,'Helmet of the Deep')
shopModule:addSellableItem({'Batwing Hat'},10016,1500,'Batwing Hat')
shopModule:addSellableItem({'Yalahari Mask'},9778,65000,'Yalahari Mask')
shopModule:addSellableItem({'Dwarven Helmet'},2502,245000,'Dwarven Helmet')
shopModule:addSellableItem({'Beholder Helmet'},3972,32000,'Beholder Helmet')
shopModule:addSellableItem({'Skull Helmet'},5741,35000,'Skull Helmet')
shopModule:addSellableItem({'Horned Helmet'},2496,2250000,'Horned Helmet')
shopModule:addSellableItem({'Witchhunter's Cloak'},8821,11000,'Witchhunter's Cloak')
shopModule:addSellableItem({'Dragon Robe'},8867,19500,'Dragon Robe')
shopModule:addSellableItem({'Greenwood Coat'},8869,13000,'Greenwood Coat')
shopModule:addSellableItem({'Robe of the Underworld'},8890,25000,'Robe of the Underworld')
shopModule:addSellableItem({'Crystalline Armor'},8878,15700,'Crystalline Armor')
shopModule:addSellableItem({'Divine Plate'},8885,34000,'Divine Plate')
shopModule:addSellableItem({'Frozen Plate'},8887,32500,'Frozen Plate')
shopModule:addSellableItem({'Skullcracker Armor'},8889,31500,'Skullcracker Armor')
shopModule:addSellableItem({'Dragon Scale Mail'},2492,38000,'Dragon Scale Mail')
shopModule:addSellableItem({'Magic Plate Armor'},2472,230000,'Magic Plate Armor')
shopModule:addSellableItem({'Yalahari Armor'},9776,120000,'Yalahari Armor')

shopModule:addSellableItem({'Yalahari Leg Piece'},9777,70000,'Yalahari Leg Piece')
shopModule:addSellableItem({'Golden Legs'},2470,65000,'Golden Legs')


shopModule:addSellableItem({'Spellbook of Dark Mysteries'},8918,65000,'Spellbook of Dark Mysteries')
shopModule:addSellableItem({'Spellbook of Prophecies'},8904,44200,'Spellbook of Prophecies')

shopModule:addBuyableItem({'Helmet of the Deep'},5461,12000,'Helmet of the Deep')

    else
       npcHandler:say('Psssssh... I am reading.', cid)
end
return TRUE
end


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

What exacly does not work? When I put
Code:
	<parameters>
		<parameter key="module_shop" value="1"/>
	</parameters>
Into my XML, it says that he has nothing to trade (after -> MagicWord -> trade or hi (with quest) -> trade), when I leave XML without this parameter it doesn't do anything when I say 'trade' :D I don't really know NPC Systems, so I beg you for help ;)
 
Idea is great, but it can't be done in this way ; p

But its not hard to do. You need to modify NPC lib, add optional parameter to addSellableItem & addBuyableItem, which will be a storage needed. Next there is check needed in ShopModule.requestTrade.
 
Idea is great, but it can't be done in this way ; p

But its not hard to do. You need to modify NPC lib, add optional parameter to addSellableItem & addBuyableItem, which will be a storage needed. Next there is check needed in ShopModule.requestTrade.

I will modify those :p can I actually just modify requestTrade? Because I want NPC to trade items only with ppl that finished quest (So I will just make a normal trade list and then... exactly :D how to use modified requestTrade?;p Is that possible, it would be easier, than adding queststorage, storagevalue to every single item <ofc I have some sort of automatization with creating npc sell/buy list, that's why I don't really want to modify my program again :D but if I will have to... :p>

@edit
I tried to make it, editing npc system isn't something hard :D but I have problems with npc, should I leave him like he looks like at the moment or what should he looks like?;p I also would like to know, if it's possible, how to get rid of greeting msg, cuz it's really annoying ;( (I know I can change it, but I would like to put whole content into lua, like you can see in first post).

@edit2
I was thinking about that and your idea looks more complex than mine :D so I made like u said, I've added to item 'class' questNeed i questValue and then made a check in request trade (just simply add items if player have needed storage or questNeed is 0) Could you also give me function that will release this focus (eg. when we say 'hi' without quest, he will say what he should and ignore player after that), I found this function in npchandler.lua:

function NpcHandler:releaseFocus(focus)
but I am not sure I can use it (actually, I am confused a bit and don't know what should I put as argument, since there is multi-focus system ;D)

@EDIT3

I've done that using my way, I was missing some part <obviously>, I just added:
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
before adding things and it works =] anyway thanks for help to everyone, I will use your @Slawkens idea for other purposes ;)

Now I just need to know how to totally get rid of greetings msg (just for one npc), because I can't trade after 'hi', because it uses msg greet (and don't create item trade list, fail =/)
 
Last edited:
NpcHandler:resetNpc()

will remove the stuffs from "trade" but the buy/sell itemname will still be there.


However, I recommanded you using LightWeight NPC System Instead.
 
NpcHandler:resetNpc()

will remove the stuffs from "trade" but the buy/sell itemname will still be there.


However, I recommanded you using LightWeight NPC System Instead.

What is that?:D I never heard of it, could you give me some examples and system lib?;p

(I would appreciate, if you can remake my NPC in this system, so I will have some clue about it)

P.S. What you mean by removing stuff from trade?:p I have no problem with that ;) I just need to get rid of greetings msg, since I have 2 options (for ppl with quest and for ppl without quest) and I can't do that using Jiddo's System ;(
 
Last edited:
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local storvalue = 17000

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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addSellableItem({'Springsprout Rod'},8912,8000,'Springsprout Rod')
shopModule:addSellableItem({'Underworld Rod'},8910,15000,'Underworld Rod')

shopModule:addSellableItem({'Wand of Starstorm'},8920,7500,'Wand of Starstorm')
shopModule:addSellableItem({'Wand of Voodoo'},8922,13750,'Wand of Voodoo')

shopModule:addSellableItem({'Ferumbars' Hat'},5903,1500000,'Ferumbars' Hat')
shopModule:addSellableItem({'Helmet of the Deep'},5461,5000,'Helmet of the Deep')
shopModule:addSellableItem({'Batwing Hat'},10016,1500,'Batwing Hat')
shopModule:addSellableItem({'Yalahari Mask'},9778,65000,'Yalahari Mask')
shopModule:addSellableItem({'Dwarven Helmet'},2502,245000,'Dwarven Helmet')
shopModule:addSellableItem({'Beholder Helmet'},3972,32000,'Beholder Helmet')
shopModule:addSellableItem({'Skull Helmet'},5741,35000,'Skull Helmet')
shopModule:addSellableItem({'Horned Helmet'},2496,2250000,'Horned Helmet')
shopModule:addSellableItem({'Witchhunter's Cloak'},8821,11000,'Witchhunter's Cloak')
shopModule:addSellableItem({'Dragon Robe'},8867,19500,'Dragon Robe')
shopModule:addSellableItem({'Greenwood Coat'},8869,13000,'Greenwood Coat')
shopModule:addSellableItem({'Robe of the Underworld'},8890,25000,'Robe of the Underworld')
shopModule:addSellableItem({'Crystalline Armor'},8878,15700,'Crystalline Armor')
shopModule:addSellableItem({'Divine Plate'},8885,34000,'Divine Plate')
shopModule:addSellableItem({'Frozen Plate'},8887,32500,'Frozen Plate')
shopModule:addSellableItem({'Skullcracker Armor'},8889,31500,'Skullcracker Armor')
shopModule:addSellableItem({'Dragon Scale Mail'},2492,38000,'Dragon Scale Mail')
shopModule:addSellableItem({'Magic Plate Armor'},2472,230000,'Magic Plate Armor')
shopModule:addSellableItem({'Yalahari Armor'},9776,120000,'Yalahari Armor')

shopModule:addSellableItem({'Yalahari Leg Piece'},9777,70000,'Yalahari Leg Piece')
shopModule:addSellableItem({'Golden Legs'},2470,65000,'Golden Legs')


shopModule:addSellableItem({'Spellbook of Dark Mysteries'},8918,65000,'Spellbook of Dark Mysteries')
shopModule:addSellableItem({'Spellbook of Prophecies'},8904,44200,'Spellbook of Prophecies')

shopModule:addBuyableItem({'Helmet of the Deep'},5461,12000,'Helmet of the Deep')

function greetCallback(cid)
    if (getPlayerStorageValue(cid, storvalue) < 1) then
        npcHandler:say('Reading...', cid)
        return false
    else
        return true
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())

This npc will only talk to people with storage key 17000 when storage value > 0
 
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local storvalue = 17000

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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addSellableItem({'Springsprout Rod'},8912,8000,'Springsprout Rod')
shopModule:addSellableItem({'Underworld Rod'},8910,15000,'Underworld Rod')

shopModule:addSellableItem({'Wand of Starstorm'},8920,7500,'Wand of Starstorm')
shopModule:addSellableItem({'Wand of Voodoo'},8922,13750,'Wand of Voodoo')

shopModule:addSellableItem({'Ferumbars' Hat'},5903,1500000,'Ferumbars' Hat')
shopModule:addSellableItem({'Helmet of the Deep'},5461,5000,'Helmet of the Deep')
shopModule:addSellableItem({'Batwing Hat'},10016,1500,'Batwing Hat')
shopModule:addSellableItem({'Yalahari Mask'},9778,65000,'Yalahari Mask')
shopModule:addSellableItem({'Dwarven Helmet'},2502,245000,'Dwarven Helmet')
shopModule:addSellableItem({'Beholder Helmet'},3972,32000,'Beholder Helmet')
shopModule:addSellableItem({'Skull Helmet'},5741,35000,'Skull Helmet')
shopModule:addSellableItem({'Horned Helmet'},2496,2250000,'Horned Helmet')
shopModule:addSellableItem({'Witchhunter's Cloak'},8821,11000,'Witchhunter's Cloak')
shopModule:addSellableItem({'Dragon Robe'},8867,19500,'Dragon Robe')
shopModule:addSellableItem({'Greenwood Coat'},8869,13000,'Greenwood Coat')
shopModule:addSellableItem({'Robe of the Underworld'},8890,25000,'Robe of the Underworld')
shopModule:addSellableItem({'Crystalline Armor'},8878,15700,'Crystalline Armor')
shopModule:addSellableItem({'Divine Plate'},8885,34000,'Divine Plate')
shopModule:addSellableItem({'Frozen Plate'},8887,32500,'Frozen Plate')
shopModule:addSellableItem({'Skullcracker Armor'},8889,31500,'Skullcracker Armor')
shopModule:addSellableItem({'Dragon Scale Mail'},2492,38000,'Dragon Scale Mail')
shopModule:addSellableItem({'Magic Plate Armor'},2472,230000,'Magic Plate Armor')
shopModule:addSellableItem({'Yalahari Armor'},9776,120000,'Yalahari Armor')

shopModule:addSellableItem({'Yalahari Leg Piece'},9777,70000,'Yalahari Leg Piece')
shopModule:addSellableItem({'Golden Legs'},2470,65000,'Golden Legs')


shopModule:addSellableItem({'Spellbook of Dark Mysteries'},8918,65000,'Spellbook of Dark Mysteries')
shopModule:addSellableItem({'Spellbook of Prophecies'},8904,44200,'Spellbook of Prophecies')

shopModule:addBuyableItem({'Helmet of the Deep'},5461,12000,'Helmet of the Deep')

function greetCallback(cid)
    if (getPlayerStorageValue(cid, storvalue) < 1) then
        npcHandler:say('Reading...', cid)
        return false
    else
        return true
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())

This npc will only talk to people with storage key 17000 when storage value > 0

Thanks :D That's what I need ;p Is that LightWeight NPC System?:D It looks almost same like Jiddo's one ;d
 
Back
Top