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

[help] fix a bug with npc

sleepy chronos

.::MaPpEr::.
Joined
Jul 13, 2007
Messages
131
Reaction score
0
Location
Santa Cruz-Bolivia
i make this script looking on some examples but i have a bug, plis someone can help me...

this is the scrip:

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)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
local storage = 7001
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

if (msgcontains(msg, 'mission') or msgcontains(msg, 'quest')) then
        if(getPlayerStorageValue(cid, storage) < 1) then
                              npcHandler:say("bla bla bla", cid)
                              talkState[talkUser] = 1
                              setPlayerStorageValue(cid, storage, 1)
		elseif(getPlayerStorageValue(cid, storage) == 1) then
                              npcHandler:say("bla {bla} bla", cid)
 	                          talkState[talkUser] = 1
		elseif(getPlayerStorageValue(cid, storage) == 2) then
                              npcHandler:say("Sorry, you have already done the quest.", cid)
                             
              end
        elseif (msgcontains(msg, 'item') and talkState[talkUser] == 1) then
              if getPlayerItemCount(cid,7433) >= 1 then
              if doPlayerRemoveItem(cid,7433,1) == 1 then
              npcHandler:say("Oh... you gonna be a brave knight take this scroll and go to knight training center.",cid)
              doPlayerAddItem(cid,7529,1)
              setPlayerStorageValue(cid, storage, 2)
              end
        else
        npcHandler:say("I need a item for give you a knights scroll document. Come back when you have them.", cid)
        talk_state = 0
        end
     elseif msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
     npcHandler:say("Ok.. Good bye then!!", cid)
     talk_state = 0
     end

return true 
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
works fine but give me an error on console

[17/06/2009 14:46:28] Lua Script Error: [Npc interface]
[17/06/2009 14:46:28] data/npc/scripts/quest/knightquestvoc2.lua:eek:nCreatureSay

[17/06/2009 14:46:28] data/npc/scripts/quest/knightquestvoc2.lua:20: attempt to index global 'talkState' (a nil value)
[17/06/2009 14:46:28] stack traceback:
[17/06/2009 14:46:28] data/npc/scripts/quest/knightquestvoc2.lua:20: in function 'callback'
[17/06/2009 14:46:28] data/npc/lib/npcsystem/npchandler.lua:384: in function 'onCreatureSay'
[17/06/2009 14:46:28] data/npc/scripts/quest/knightquestvoc2.lua:9: in function <data/npc/scripts/quest/knightquestvoc2.lua:9>

help plis with this simple problem
 
@up
The "cid" are there to make it talk in the NPC channel :p


Test this:

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)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
local storage = 7001

		if msgcontains(msg, 'mission') and getPlayerStorageValue(cid, storage) < 1 then
			npcHandler:say('bla bla bla', cid)
			talkState = 1
			setPlayerStorageValue(cid, storage, 1)
		end
		elseif msgcontains(msg, 'mission') and getPlayerStorageValue(cid, storage) == 1 then
			npcHandler:say('bla {bla} bla', cid)
			talkState = 1
		elseif msgcontains(msg, 'mission') and getPlayerStorageValue(cid, storage) == 2 then
			npcHandler:say('Sorry, you have already done the quest.', cid)
		
		elseif msgcontains(msg, 'item') and talkState == 1 then
			if getPlayerItemCount(cid,7433) >= 1 then
				if doPlayerRemoveItem(cid,7433,1) == 1 then
					npcHandler:say('Oh... you gonna be a brave knight take this scroll and go to knight training center.',cid)
					doPlayerAddItem(cid,7529,1)
					setPlayerStorageValue(cid, storage, 2)
					else
					npcHandler:say('I need a item for give you a knights scroll document. Come back when you have them.', cid)
					talkState = 0
					end
				end
			end
		elseif msgcontains(msg, 'no') then
			npcHandler:say('Ok.. Good bye then!!', cid)
			talkState = 0
		end
		return true 
	end

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

I think it works xd
 
Last edited:
Back
Top