• 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 TROUBLE] This Quest npc isn't changing players storage :/

kessykins

Intermediate OT User
Joined
Mar 15, 2010
Messages
297
Reaction score
105
Ok so I attempted to create my first quest npc and failed miserably. The npc doesn't respond to anything but quest/apprentice. Each time it replies with the same thing x.x

What did noob Kes to wrong this time?
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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
	local storage = 1650
	local exp1 = 2000
	local exp2 = 4000
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'apprentice')) then
		if(getPlayerStorageValue(cid, storage) - 1) then
			npcHandler:say("You are interested in becoming an apprentice fisherman eh? The first step is to get a pole. Deep Sea Fishing Poles are quite expensive to make.. Bring me 1 Orshabaal brain, 10 Iron Ore, 10 Giant Spider Silk and 10 Yellow Pieces of Cloth. ", cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif(getPlayerStorageValue(cid, storage) == 1) then
			npcHandler:say("Did you bring me 1 Orshabaal brain, 10 Iron Ore, 10 Giant Spider Silk and 10 Yellow Pieces of Cloth?", cid)
			talkState[talkUser] = 1
		elseif(getPlayerStorageValue(cid, storage) == 2) then
			npcHandler:say("I knew I recognized you! You have already got. Go away!", cid)
		elseif(getPlayerStorageValue(cid, storage) == -3) then
			npcHandler:say("So! You now have your pole. The next step is to prove to me that you can fish. Bring me 10 Common Silmy Objects, 5 Uncommon Slimy Objects and 1 Rare Slimy Object.", cid)
			setPlayerStorageValue(cid, storage, 3)	
		elseif(getPlayerStorageValue(cid, storage) == 3) then
			npcHandler:say("Did you bring me Bring me 10 Common Silmy Objects, 5 Uncommon Slimy Objects and 1 Rare Slimy Object?", cid)
			talkState[talkUser] = 3
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if((doPlayerRemoveItem(cid, 5808, 1)) and (doPlayerremoveItem(cid, 5914, 10)) and (doPlayerremoveItem(cid, 5879, 10)) and (doPlayerremoveItem(cid, 5880, 10)) == TRUE) then
			npcHandler:say("Thanks! Go into my house and grab your new rod.", cid)
			doPlayerAddExp(cid, config.exp1)	
			setPlayerStorageValue(cid, storage, 2)
			talkState[talkUser] = 1
		else
			npcHandler:say("Sorry, you don\'t have everything I asked for.", cid)
			talkState[talkUser] = 0
		end
			elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
		if(doPlayerRemoveItem(cid, 10556, 10) and (doPlayerremoveItem(cid, 10553, 5)) and doPlayerremoveItem(cid, 10557, 1)) == TRUE then
			npcHandler:say("Well done! You are now officially an Apprentice Fisherman! Go talk to Polgara for your next step.", cid)
			doPlayerAddExp(cid, config.exp2)		
			setPlayerStorageValue(cid, storage, 3)
			talkState[talkUser] = 0
		else
			npcHandler:say("Sorry, you don\'t have everything I asked for.", cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
		npcHandler:say("Okay then.", cid)
		talkState[talkUser] = 0
	end
	return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

++REP for help
 
Quite impressive!

Change:
LUA:
		if(getPlayerStorageValue(cid, storage) - 1) then
to
LUA:
		if(getPlayerStorageValue(cid, storage) == -1) then

and i wonder if this one's malformed too
LUA:
		elseif(getPlayerStorageValue(cid, storage) == -3) then
 
Try
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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, 'quest') or msgcontains(msg, 'apprentice')) then
		if getPlayerStorageValue(cid, 1650) == -1 then
			npcHandler:say("You are interested in becoming an apprentice fisherman eh? The first step is to get a pole. Deep Sea Fishing Poles are quite expensive to make.. Bring me 1 Orshabaal brain, 10 Iron Ore, 10 Giant Spider Silk and 10 Yellow Pieces of Cloth. ", cid)
			setPlayerStorageValue(cid, 1650, 1)
		elseif getPlayerStorageValue(cid, 1650) == 1 then
			npcHandler:say("Did you bring me 1 Orshabaal brain, 10 Iron Ore, 10 Giant Spider Silk and 10 Yellow Pieces of Cloth?", cid)
			talkState[talkUser] = 1
		elseif getPlayerStorageValue(cid, 1650) == 2 then
			npcHandler:say("So! You now have your pole. The next step is to prove to me that you can fish. Bring me 10 Common Silmy Objects, 5 Uncommon Slimy Objects and 1 Rare Slimy Object.", cid)
			setPlayerStorageValue(cid, 1650, 3)	
		elseif getPlayerStorageValue(cid, 1650) == 3 then
			npcHandler:say("Did you bring me Bring me 10 Common Silmy Objects, 5 Uncommon Slimy Objects and 1 Rare Slimy Object?", cid)
			talkState[talkUser] = 3
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if doPlayerRemoveItem(cid, 5808, 1) == TRUE and doPlayerRemoveItem(cid, 5914, 10) == TRUE and doPlayerRemoveItem(cid, 5879, 10) == TRUE and doPlayerRemoveItem(cid, 5880, 10) == TRUE then
			npcHandler:say("Thanks! Go into my house and grab your new rod.", cid)
			doPlayerAddExp(cid, 2000)	
			setPlayerStorageValue(cid, 1650, 2)
			talkState[talkUser] = 1
		else
			npcHandler:say("Sorry, you don\'t have everything I asked for.", cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
		if doPlayerRemoveItem(cid, 10556, 10) == TRUE and doPlayerRemoveItem(cid, 10553, 5) == TRUE and doPlayerRemoveItem(cid, 10557, 1) == TRUE then
			npcHandler:say("Well done! You are now officially an Apprentice Fisherman! Go talk to Polgara for your next step.", cid)
			doPlayerAddExp(cid, 4000)		
			setPlayerStorageValue(cid, 1650, 3)
			talkState[talkUser] = 0
		else
			npcHandler:say("Sorry, you don\'t have everything I asked for.", cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
		npcHandler:say("Okay then.", cid)
		talkState[talkUser] = 0
	end
	return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Rep++ if it works
 
more minor fixes
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local storage = 1650
local exp1 = 2000
local exp2 = 4000

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
	elseif msgcontains(msg, 'quest') or msgcontains(msg, 'apprentice') then
		local v = getPlayerStorageValue(cid, storage)
		if v == -1 then
			npcHandler:say("You are interested in becoming an apprentice fisherman, eh? The first step is to get a pole. Deep Sea Fishing Poles are quite expensive to make... Bring me 1 Orshabaal brain, 10 Iron Ore, 10 Giant Spider Silk and 10 Yellow Pieces of Cloth.", cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif v == 1 then
			npcHandler:say("Did you bring me 1 Orshabaal brain, 10 Iron Ore, 10 Giant Spider Silk and 10 Yellow Pieces of Cloth?", cid)
			Topic[cid] = 1
		elseif v == 2 then
			npcHandler:say("So! You now have your pole. The next step is to prove to me that you can fish. Bring me 10 Common Silmy Objects, 5 Uncommon Slimy Objects and 1 Rare Slimy Object.", cid)
			setPlayerStorageValue(cid, storage, 3)	
		elseif v == 3 then
			npcHandler:say("Did you bring me 10 Common Silmy Objects, 5 Uncommon Slimy Objects and 1 Rare Slimy Object?", cid)
			Topic[cid] = 2
		elseif v == 4 then
			npcHandler:say("I knew I recognized you! You have already got. Go away!", cid)
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
		if getPlayerItemCount(cid, 5808) >= 1 and getPlayerItemCount(cid, 5914) >= 10 and getPlayerItemCount(cid, 5879) >= 10 and getPlayerItemCount(cid, 5880) >= 10 then
			doPlayerRemoveItem(cid, 5808, 1)
			doPlayerRemoveItem(cid, 5914, 10)
			doPlayerRemoveItem(cid, 5879, 10)
			doPlayerRemoveItem(cid, 5880, 10)
			npcHandler:say("Thanks! Go into my house and grab your new rod.", cid)
			doPlayerAddExp(cid, exp1)
			doSendMagicEffect(getThingPos(cid), exp1, 215)
			setPlayerStorageValue(cid, storage, 2)
			Topic[cid] = 1
		else
			npcHandler:say("Sorry, you don\'t have everything I asked for.", cid)
			Topic[cid] = 0
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
		if getPlayerItemCount(cid, 10556) >= 10 and getPlayerItemCount(cid, 10553) >= 5 and getPlayerItemCount(cid, 10557) >= 1 then
			doPlayerRemoveItem(cid, 10556, 10)
			doPlayerRemoveItem(cid, 10553, 5)
			doPlayerRemoveItem(cid, 10557, 1)
			npcHandler:say("Well done! You are now officially an Apprentice Fisherman! Go talk to Polgara for your next step.", cid)
			doPlayerAddExp(cid, exp2)
			doSendMagicEffect(getThingPos(cid), exp2, 215)
			setPlayerStorageValue(cid, storage, 4)
			Topic[cid] = 0
		else
			npcHandler:say("Sorry, you don\'t have everything I asked for.", cid)
			Topic[cid] = 0
		end
	elseif msgcontains(msg, 'no') and Topic[cid] > 0 then
		npcHandler:say("Okay then.", cid)
		Topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Sonical - !! The npc works but.. when a player gives him the items he reacts with "Sorry you dont have everything I asked for" instead of "Thanks! Go grab your new pole!"
Also after a player gives him the items he just keeps asking the same line "Did you bring me 1 Orshabaal brain, 10 Iron Ore, 10 Giant Spider Silk and 10 Yellow Pieces of Cloth?"


EDIT: Cykotitan I tried yours but the npc won't respond when a player says 'yes' after topic 1
This is the error it gives

[20/08/2010 13:50:00] [Error - Npc interface]
[20/08/2010 13:50:00] data/npc/scripts/alvin.lua:onCreatureSay
[20/08/2010 13:50:00] Description:
[20/08/2010 13:50:00] data/npc/scripts/alvin.lua:36: attempt to call global 'getPlayerItemCOunt' (a nil value)
[20/08/2010 13:50:00] stack traceback:
[20/08/2010 13:50:00] data/npc/scripts/alvin.lua:36: in function 'callback'
[20/08/2010 13:50:00] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[20/08/2010 13:50:00] data/npc/scripts/alvin.lua:12: in function <data/npc/scripts/alvin.lua:12>
 
Last edited:
Back
Top