• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Quest NPC doesn't work

OldXar

Member
Joined
Feb 17, 2009
Messages
215
Reaction score
6
Hey all,

I'm trying to make a quest Npc but .Lua ain't my strongest side,...
However I would like to learn what I'm doing wrong.
This script isn't complete, I didn't add a reward yet, etc,.. but at this point I'm just testing.
My issue, while saying "quest" my npc doesn't seem to react and I have no clue why.

Any ideas what the problem might be ? :p

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

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

npcHandler:addModule(FocusModule:new())



function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'quest') then
	npcHandler:say('Did you find my diary ?', cid)		
			if msgcontains(msg, 'yes') then
			doPlayerRemoveItem(cid, 1961)
			npcHandler:say('Thank you, Ive been looking for that book for ages now,...', cid)		
			end
	elseif msgcontains(msg, 'no') then 
	npcHandler:say('Ok, no reward for you then,...', cid)
	return false		
	end
end

Kind regards,
 
You just wasted a post, it could have been the answer I was looking for, instead you keep yourself busy acting as forum police. Ai Ai Cpt Dicklock
 
You just wasted a post, it could have been the answer I was looking for, instead you keep yourself busy acting as forum police. Ai Ai Cpt Dicklock

Don't be acting like an asshole or people wont help you. Plus Azzkaban was right, you need to wait 24hrs to bump a thread. Read the rules before you do stuff.
 
Don't be acting like an asshole or people wont help you. Plus Azzkaban was right, you need to wait 24hrs to bump a thread. Read the rules before you do stuff.

The reason I acted like a dick is because people are always so damn quick to reply when you break a rule while they aren't even a moderator, but once you ask help with a common quest npc I need to wait for hours. Ok you are right, I need to wait 24-hours I can however explain that it has been ages since I've been using this forum so in all honnesty it did slip my mind.
 
The reason I acted like a dick is because people are always so damn quick to reply when you break a rule while they aren't even a moderator, but once you ask help with a common quest npc I need to wait for hours. Ok you are right, I need to wait 24-hours I can however explain that it has been ages since I've been using this forum so in all honnesty it did slip my mind.

I'm sure she came in the thread to see what the bump was for and saw you violated the rules and tried to correct you.
 
LUA:
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
 
npcHandler:addModule(FocusModule:new())
 
 
 
function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    -- You can make an if statement checking if the player completed her/his request! if he did not complete it, it will say the things at the bottom, otherwise it can say something like 'Thanks for your help [PLAYERNAME], if I have anything else that I need help I\'ll ask again!'
    npcHandler:say('Oh my, I can\'t seem to find my {diary}.', cid)
    npcHandler:say('Oh!, hello, sorry I\'m very absentminded at the moment!', cid)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if msgcontains(msg, 'diary') then
        npcHandler:say('Have you seen my diary?', cid)
        talkState[talkUser] = 1	
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        doPlayerRemoveItem(cid, 1961)
        npcHandler:say('Thank you, I\'ve been looking for that book for ages...', cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then 
        npcHandler:say('Oh, sorry for asking...', cid)
        talkState[talkUser] = 0
    return false		
    end
return true
end

Edit:
Made a small comment on it to improve the story along it!

Hint: talkUser and talkState.
 
Last edited:
Thank you for your reply and effort Shinmaru !
But now I'm getting the following error:
Code:
[29/05/2012 23:07:17] [Error - Npc interface] 
[29/05/2012 23:07:17] data/npc/scripts/story_quest.lua
[29/05/2012 23:07:17] Description: 
[29/05/2012 23:07:17] data/npc/lib/npcsystem/modules.lua:715: attempt to index field 'keywordHandler' (a nil value)

Am I missing something in my lib or is there an error in the script ?

Kind Regards,

Edit: Just for learning purposes could you explain the following line please ?
Code:
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
Back
Top