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

[8.54][TFS][LUA] What is wrong with this NPC? Console errors included.

pikaboy

New Member
Joined
Mar 10, 2010
Messages
37
Reaction score
0
Hiya there,

I use the following code in a NPC I made.

Lua:
if msgcontains(msg, 'fix') then
    
	  if(getPlayerItemCount(cid, 1111) >= 1) then
			selfSay('Are you sure? I will give you 1 item in return.', cid)
			talkState[talkUser] = 1
		else
			selfSay('You do not have any items.', cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 1111) >= 1) then
			if(doPlayerTakeItem(cid, 1111, 1) == TRUE) then
				doPlayerGiveItem(cid, 2222, 1)
				selfSay('Here you are.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the requested item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

It asks for a single item, and if you say fix, yes, you trade the item for a other item. (2222). However, when I say yes, nothing happens.

Console error;

[23/02/2011 21:45:30] [Error - Npc interface]
[23/02/2011 21:45:30] data/npc/scripts/healer.lua:eek:nCreatureSay
[23/02/2011 21:45:30] Description:
[23/02/2011 21:45:30] data/npc/scripts/healer.lua:27: table index is nil
[23/02/2011 21:45:30] stack traceback:
[23/02/2011 21:45:30] data/npc/scripts/healer.lua:27: in function 'callback'
[23/02/2011 21:45:30] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[23/02/2011 21:45:30] data/npc/scripts/healer.lua:8: in function <data/npc/scripts/healer.lua:8>



Any idea?

Thanks in advance.
 
It happens because talkUser is nil. Either change it to 'cid' or paste this line before your code:

Code:
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
Thanks for your reply.
Pasting your code, I get this as a result saying fix, yes;

[24/02/2011 16:32:02] [Error - Npc interface]
[24/02/2011 16:32:02] data/npc/scripts/healer.lua:eek:nCreatureSay
[24/02/2011 16:32:02] Description:
[24/02/2011 16:32:02] data/npc/scripts/healer.lua:28: table index is nil
[24/02/2011 16:32:02] stack traceback:
[24/02/2011 16:32:02] data/npc/scripts/healer.lua:28: in function 'callback'
[24/02/2011 16:32:02] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[24/02/2011 16:32:02] data/npc/scripts/healer.lua:9: in function <data/npc/scripts/healer.lua:9>
 
Back
Top