Is it possible for same npc to have both a quest and a shop?
If it's possible where and how can I add the shop system in this code?
If you don't understand what I mean, then I could explain
If it's possible where and how can I add the shop system in this code?
If you don't understand what I mean, then I could explain
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
local storage = 20000 -- Change to your own Storage (unique)
local player_level = getPlayerLevel(cid)
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)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, "hi") or msgcontains(msg, "hello") and (not npcHandler:isFocused(cid)) then -- which message you need to put to get the npc attention
if getPlayerStorageValue(cid, storage) < 1 then
selfSay("Hello |PLAYERNAME|, I am selling weapons and armors! By the way, I have a task for you.", cid, TRUE) -- What the npc shall answear if you don't have the quest or accept the quest
Topic[talkUser] = 0
elseif getPlayerStorageValue(cid, storage) == 1 then
selfSay("Doo you have the iron piece?", cid, TRUE) -- What the npc shall response if you have accepted the quest
Topic[talkUser] = 1
elseif getPlayerStorageValue(cid, storage) == 2 then
selfSay("Hello |PLAYERNAME|, I am selling weapons and armors!", cid, TRUE) -- What the npc shall say when you have completed the quest
Topic[talkUser] = 0
end
npcHandler:addFocus(cid)
return true
end
if(not npcHandler:isFocused(cid)) then
return false
end
if msgcontains(msg, "bye") or msgcontains(msg, "farewell") then -- when you want to loose the npc attention
selfSay("Good bye.", cid, TRUE)
Topic[talkUser] = 0
npcHandler:releaseFocus(cid)
elseif msgcontains(msg, "quest") or msgcontains(msg, "mission") or msgcontains(msg, "task") or msgcontains(msg, "help") or (msgcontains(msg, "medicine") and getPlayerStorageValue(cid, storage) > 0) then -- Message to get the quest
if getPlayerStorageValue(cid, storage) < 1 then
npcHandler:say("I need to repair the sword I have in my shop but, I don't have any piece of iron remaining. I know a girl inside of the sewers that have one piece of iron. Could you please go and ask her if she could give you it?", cid) -- What the npc shall say if you wonder what the quest is
setPlayerStorageValue(cid, storage, 1)
Topic[talkUser] = 0
elseif getPlayerStorageValue(cid, storage) == 1 then
selfSay("Have you brought the piece of iron?", cid, TRUE) -- what the npc shall say if you have accepted the quest
Topic[talkUser] = 1
elseif getPlayerStorageValue(cid, storage) == 2 then
selfSay("Thank you, for getting the piece of iron!", cid, TRUE) -- what the npc says when you have given him the quest item (completed the quest)
Topic[talkUser] = 0
end
elseif Topic[talkUser] == 1 then
if msgcontains(msg, "yes") then
if getPlayerItemCount(cid, 2225) >= 1 then -- The item which is needed
doPlayerRemoveItem(cid, 2225, 1) -- The item that's need to be removed
npcHandler:say("Thank you! as reward you will get your level multiplied your level as experience and 1 crystal coin!", cid) - the reward
doPlayerAddItem(cid, 2160, 1)
doPlayerAddExperience(cid, player_level * player_lever) -- the reward
setPlayerStorageValue(cid, storage, 2)
else
npcHandler:say("You didn't have the piece of iron I asked for.", cid) - If you don't have the quest item
end
else
npcHandler:say("Please could you get the piece of iron as soon as possible?", cid) -- if you say something else than yes
end
Topic[talkUser] = 0
end
return TRUE
end
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)