• 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!

With quest and Shop?

tosse12

Panchira Project Member
Joined
Jun 10, 2007
Messages
864
Reaction score
9
Location
Sweden
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 :D
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)
 
hei :D that contains some of my code ;oo I've probably released a piece of code elsewhere

Anyway,
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local storage = 20000 -- Change to your own Storage (unique)

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:addBuyableItem({"fish"}, 2667, 5, "fish")

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 "..getCreatureName(cid)..", 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
		elseif getPlayerStorageValue(cid, storage) == 1 then
			selfSay("Do you have the iron piece?", cid, TRUE) -- What the npc shall response if you have accepted the quest
		elseif getPlayerStorageValue(cid, storage) == 2 then
			selfSay("Hello "..getCreatureName(cid)..", I am selling weapons and armors!", cid, TRUE) -- What the npc shall say when you have completed the quest
		end
		npcHandler:addFocus(cid)
		Topic[talkUser] = getPlayerStorageValue(cid, storage) == 1 and 1 or 0
	elseif(not npcHandler:isFocused(cid)) then
		return false
	elseif 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)
		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
		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)
		end
		Topic[talkUser] = getPlayerStorageValue(cid, storage) == 1 and 1 or 0
	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)
				local player_level = getPlayerLevel(cid)
				doPlayerAddExperience(cid, player_level * player_level) -- 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)
 
Last edited:
Okey I got a new problem if u are able to answear :D

When I say "hi" to this npc he won't open up the "npcs" channel, is it possible to do that automatic when u say hi? if so how do I do that? :D

Toki.lua:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local storage = 20000 -- Change to your own Storage (unique)

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:addBuyableItem({"fish"}, 2667, 5, "fish")

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 "..getCreatureName(cid)..", 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
		elseif getPlayerStorageValue(cid, storage) == 1 then
			selfSay("Do you have the iron piece?", cid, TRUE) -- What the npc shall response if you have accepted the quest
		elseif getPlayerStorageValue(cid, storage) == 2 then
			selfSay("Hello "..getCreatureName(cid)..", I am selling weapons and armors!", cid, TRUE) -- What the npc shall say when you have completed the quest
		end
		npcHandler:addFocus(cid)
		Topic[talkUser] = getPlayerStorageValue(cid, storage) == 1 and 1 or 0
	elseif(not npcHandler:isFocused(cid)) then
		return false
	elseif 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)
		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
		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)
		end
		Topic[talkUser] = getPlayerStorageValue(cid, storage) == 1 and 1 or 0
	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 3.000.000 experience points and 1 crystal coin!", cid) -- the reward
				doPlayerAddItem(cid, 2160, 1)
				local player_level = getPlayerLevel(cid)
				doPlayerAddExperience(cid, 3000000) -- 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)

Toki.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Toki" script="toki.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="133" head="20" body="39" legs="45" feet="7" addons="0"/>
</npc>
If these help u :D
 
NOOOOES :( I am using TFS 0.3.5

NVM.... changed every "Selfsay" to "npcHandler:say"..... Working now
Thanks for your help :D
 
Last edited:
Back
Top