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

Lua Npc problem

Santi

Theres no way im stopping
Joined
Aug 29, 2010
Messages
1,975
Reaction score
152
Location
00
Whats wrong with it? He ain't replying when I say hi.. no errors displayed.

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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	
	function doNPCTalkALot(msgs,interval,pcid)
	local e={}
	local ret={}
	if interval==nil then interval=10000 end --10 seconds is default time between messages
		for aux=1,table.getn(msgs) do
		e[aux]={}
		doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux],pcid)
		table.insert(ret,e[aux])
	end
	return(ret)
end

   if msgcontains(msg, 'hi') then
      selfsay("Greetings, player. I do not see your face, but I can read a thousand things in your voice!")
        talkState[talkUser] = 1
    
   elseif talkState[talkUser] == 1 then
    if  msgcontains(msg, 'word of greeting') and getPlayerStorageValue(cid,35000) == -1 then
    doNPCTalkALot({"The djinns have an ancient code of honour. This code includes a special concept of hospitality. Anybody who utters the word of greeting must not be attacked even if he is an enemy. Well, at least that is what the code says. .... ...", "I have found out, though, that this does not work at all times. There is no point to say the word of greeting to an enraged djinn. .... ...", "I can tell you the word of greeting if you're interested. It is DJANNI'HAH. Remember this word well, stranger. It might save your life one day. .... ...", "And keep in mind that you must choose sides in this conflict. You can only follow the Efreet or the Marid - once you have made your choice there is no way back. I know from experience that djinn do not tolerate double-crossing.."}, 5000, cid)
	setPlayerStorageValue(cid,35000,1)	
        talkState[talkUser] = 2
		
  elseif msgcontains(msg, 'bye') then
         selfsay('Farewell, stranger. May Uman the Wise guide your steps in this treacherous land.')
   
   elseif talkState[talkUser] == 1 then
   if msgcontains(msg, 'word of greeting') and getPlayerStorageValue(cid,35000) == 1 then
   selfsay("Go and choose a side, I've already told you the word!")
         
  end
  end
  end
  return true
  end
 
Lua:
local keywordHandler = KeywordHandler:new()
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
 
function doNPCTalkALot(msgs,interval,pcid)
	local e={}
	local ret={}
	interval = interval or 10000
	for aux = 1, #msgs do
		e[aux]={}
		doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux],pcid)
		table.insert(ret,e[aux])
	end
	return ret
end

function creatureSayCallback(cid, type, msg)
	if (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'greetings')) and not npcHandler:isFocused(cid) then
		if getPlayerSex(cid) == 0 then
			npcHandler:say('Welcome, ' .. getCreatureName(cid) .. '! The lovely sound of your voice shines like a beam of light through my solitary darkness!', cid)
		else
			npcHandler:say('Greetings, ' .. getCreatureName(cid) .. '. I do not see your face, but I can read a thousand things in your voice!', cid)
		end
		npcHandler:addFocus(cid)
	elseif not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'bye') then
		npcHandler:say('Farewell, stranger. May Uman the Wise guide your steps in this treacherous land.', cid)
		npcHandler:releaseFocus(cid)
	elseif (msgcontains(msg, 'greeting') or msgcontains(msg, 'word')) and getPlayerStorageValue(cid, 35000) < 2 then
		doNPCTalkALot({"The djinns have an ancient code of honour. This code includes a special concept of hospitality. Anybody who utters the word of greeting must not be attacked even if he is an enemy. Well, at least that is what the code says. .... ...", "I have found out, though, that this does not work at all times. There is no point to say the word of greeting to an enraged djinn. .... ...", "I can tell you the word of greeting if you're interested. It is DJANNI'HAH. Remember this word well, stranger. It might save your life one day. .... ...", "And keep in mind that you must choose sides in this conflict. You can only follow the Efreet or the Marid - once you have made your choice there is no way back. I know from experience that djinn do not tolerate double-crossing.."}, 10000, cid)
		setPlayerStorageValue(cid, 35000, 1)
	elseif msgcontains(msg, 'djanni\'hah') and getPlayerStorageValue(cid, 35000) < 2 then
		npcHandler:say('You know the traditional djinn word of greeting DJANNI\'HAH. Use it wisely!', cid)
		setPlayerStorageValue(cid, 35000, 1)
	end
	return true
end
  
npcHandler:setMessage(MESSAGE_WALKAWAY, 'May the light be with you.')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
It aint working

Code:
[16/11/2010 17:16:15] [Error - Npc interface] 
[16/11/2010 17:16:15] data/npc/scripts/melchior.lua:onCreatureSay
[16/11/2010 17:16:15] Description: 
[16/11/2010 17:16:15] data/npc/scripts/melchior.lua:16: attempt to call global 'doCreatureSayWithDelay' (a nil value)
[16/11/2010 17:16:15] stack traceback:
[16/11/2010 17:16:15] 	data/npc/scripts/melchior.lua:16: in function 'doNPCTalkALot'
[16/11/2010 17:16:15] 	data/npc/scripts/melchior.lua:36: in function 'callback'
[16/11/2010 17:16:15] 	data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[16/11/2010 17:16:15] 	data/npc/scripts/melchior.lua:7: in function <data/npc/scripts/melchior.lua:7>

By the way, could someone see whats wrong with this 1?, same thing that up there, it wont reply if i say hi.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local voc = {}
 
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 storage = 35000
local s = getPlayerStorageValue(cid, storage)	

function creatureSayCallback(cid, type, msg)
if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'hey') and not npcHandler:isFocused(cid) then
   npcHandler:say('Hello ' .. GetCreatureName(cid) .. ' to start a mission say task!', cid)
   npcHandler:addFocus(cid)
   elseif not npcHandler:isFocused(cid) then
return false

elseif msgcontains(msg, 'bye') or msgcontains(msg, 'good bye') then
npcHandler:say('Good bye ' .. GetCreatureName(cid) .. ' come back if you want more missions!', cid)
npcHandler:releaseFocus(cid)

elseif msgcontains(msg, 'task') and getPlayerStorageValue(cid,storage) == -1 then ---- Start mission 1
npcHandler:say('You have started task number 1, bring me 10 wolf furs to complete it!', cid)
setPlayerStorageValue(cid,storage,1)
elseif s == 1 then
npcHandler:say('You are still in task number 1!', cid)
elseif s == 2 then ---- Start mission 2
npcHandler:say('You have started task number 2, bring me 20 red dragon scales to complete it!', cid)
setPlayerStorageValue(cid,storage,3)
elseif s == 3 then
npcHandler:say('You are already in task number 2!', cid)
elseif s == 4 then ---- Start mission 3
npcHandler:say('You have started task number 3, bring me 10 iron ores and 15 morgaroth\'s heart to complete it!', cid)
setPlayerStorageValue(cid,storage,5)
elseif s == 5 then
pcHandler:say('You are already in task number 3!', cid)


elseif msgcontains(msg, 'report') and s == 1 and getPlayerItemCount(cid,11228) >= 10 then --- Finish mission 1
doPlayerRemoveItem(cid,11228,10)
doPlayerAddExp(cid, 500)
pcHandler:say('Congratulations, you have finished mission 1!', cid)
setPlayerStorageValue(cid,storage,2)
elseif s == 3 and getPlayerItemCount(cid,5882) >= 20 then --- Finish mission 2
doPlayerRemoveItem(cid,5882,20)
doPlayerAddExp(cid, 2000)
pcHandler:say('Congratulations, you have finished mission 2!', cid)
setPlayerStorageValue(cid,storage,4)
else if s == 5 and getPlayerItemCount(cid,5880) >= 10 and getPlayerItemCount(cid,5943) >= 15 then --- Finish mission 3
doPlayerRemoveItem(cid,5880,10)
doPlayerRemoveItem(cid,5943,15)
doPlayerAddExp(cid, 5000)
pcHandler:say('Congratulations, you have finished mission 3 and now you are able to go with Josh, who will have more missions for you!', cid)
setPlayerStorageValue(cid, 35001)

end
return true
end
end
end
npcHandler:setMessage(MESSAGE_WALKAWAY, 'How rude!')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
Thanks in advanced and rep+ for whoever helpsss
 
Just as I thought, you're missing the other function.
Lua:
function doCreatureSayWithDelay(cid,text,type,delay,e)
	if delay <= 0 then
		doCreatureSay(cid,text,type)
	else
		local func=function(pars)
			doCreatureSay(pars.cid,pars.text,pars.type)
			pars.e.done=true
		end
		e.done=false
		e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e})
	end
end

Lua:
local keywordHandler = KeywordHandler:new()
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

local storage = 35000

function creatureSayCallback(cid, type, msg)
	if (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'hey')) and not npcHandler:isFocused(cid) then
		npcHandler:say('Hello ' .. getCreatureName(cid) .. '! To start a mission say {task}!', cid)
		npcHandler:addFocus(cid)
	elseif not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'bye') or msgcontains(msg, 'goodbye') then
		npcHandler:say('Good bye ' .. getCreatureName(cid) .. '! Come back if you want more missions!', cid)
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, 'task') then
		local s = getPlayerStorageValue(cid, storage)
		if s < 1 then ---- Start mission 1
			npcHandler:say('You have started task number 1, bring me 10 wolf furs to complete it!', cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif s == 1 then
			npcHandler:say('You are still in task number 1!', cid)
		elseif s == 2 then ---- Start mission 2
			npcHandler:say('You have started task number 2, bring me 20 red dragon scales to complete it!', cid)
			setPlayerStorageValue(cid, storage, 3)
		elseif s == 3 then
			npcHandler:say('You are already in task number 2!', cid)
		elseif s == 4 then ---- Start mission 3
			npcHandler:say('You have started task number 3, bring me 10 iron ores and 15 morgaroth\'s heart to complete it!', cid)
			setPlayerStorageValue(cid, storage, 5)
		elseif s == 5 then
			npcHandler:say('You are already in task number 3!', cid)
		elseif s == 6 then
			npcHandler:say('You have completed all my tasks!', cid)
		end
	elseif msgcontains(msg, 'report') then
		local s = getPlayerStorageValue(cid, storage)
		if s == 1 and doPlayerRemoveItem(cid, 11228, 10) then --- Finish mission 1
			doPlayerAddExp(cid, 500)
			npcHandler:say('Congratulations, you have finished mission 1!', cid)
			setPlayerStorageValue(cid, storage, 2)
		elseif s == 3 and doPlayerRemoveItem(cid, 5882, 20) then --- Finish mission 2
			doPlayerAddExp(cid, 2000)
			npcHandler:say('Congratulations, you have finished mission 2!', cid)
			setPlayerStorageValue(cid, storage, 4)
		elseif s == 5 and getPlayerItemCount(cid,5880) >= 10 and doPlayerRemoveItem(cid, 5943, 15) then --- Finish mission 3
			doPlayerRemoveItem(cid, 5880, 10)
			doPlayerAddExp(cid, 5000)
			npcHandler:say('Congratulations, you have finished mission 3 and now you are able to go with Josh, who will have more missions for you!', cid)
			setPlayerStorageValue(cid, 35000, 6)
			setPlayerStorageValue(cid, 35001, 1)
		end
	end
	return true
end

npcHandler:setMessage(MESSAGE_WALKAWAY, 'How rude!')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited:
Haha, awesome, its working now, thanks a lot :).
Btw, not to be annoying could you see whats wrong in the other file ?
You must spread some Reputation around before giving it to Cykotitan again.
:l
 
Ok, ofc yours work cause you're pro xD, but I just want to know why mine doesnt, I try fixing it taking some stuff and ideas from yours but I still cant make it work and I don't get why <.<.
The one you fixed:
Lua:
local keywordHandler = KeywordHandler:new()
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
 
local storage = 35000
 
function creatureSayCallback(cid, type, msg)
	if (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'hey')) and not npcHandler:isFocused(cid) then
		npcHandler:say('Hello ' .. getCreatureName(cid) .. '! To start a mission say {task}!', cid)
		npcHandler:addFocus(cid)
	elseif not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'bye') or msgcontains(msg, 'goodbye') then
		npcHandler:say('Good bye ' .. getCreatureName(cid) .. '! Come back if you want more missions!', cid)
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, 'task') then
		local s = getPlayerStorageValue(cid, storage)
		if s < 1 then ---- Start mission 1
			npcHandler:say('You have started task number 1, bring me 10 wolf furs to complete it!', cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif s == 1 then
			npcHandler:say('You are still in task number 1!', cid)
		elseif s == 2 then ---- Start mission 2
			npcHandler:say('You have started task number 2, bring me 20 red dragon scales to complete it!', cid)
			setPlayerStorageValue(cid, storage, 3)
		elseif s == 3 then
			npcHandler:say('You are already in task number 2!', cid)
		elseif s == 4 then ---- Start mission 3
			npcHandler:say('You have started task number 3, bring me 10 iron ores and 15 morgaroth\'s heart to complete it!', cid)
			setPlayerStorageValue(cid, storage, 5)
		elseif s == 5 then
			npcHandler:say('You are already in task number 3!', cid)
		elseif s == 6 then
			npcHandler:say('You have completed all my tasks!', cid)
		end
	elseif msgcontains(msg, 'report') then
		local s = getPlayerStorageValue(cid, storage)
		if s == 1 and doPlayerRemoveItem(cid, 11228, 10) then --- Finish mission 1
			doPlayerAddExp(cid, 500)
			npcHandler:say('Congratulations, you have finished mission 1!', cid)
			setPlayerStorageValue(cid, storage, 2)
		elseif s == 3 and doPlayerRemoveItem(cid, 5882, 20) then --- Finish mission 2
			doPlayerAddExp(cid, 2000)
			npcHandler:say('Congratulations, you have finished mission 2!', cid)
			setPlayerStorageValue(cid, storage, 4)
		elseif s == 5 and getPlayerItemCount(cid,5880) >= 10 and doPlayerRemoveItem(cid, 5943, 15) then --- Finish mission 3
			doPlayerRemoveItem(cid, 5880, 10)
			doPlayerAddExp(cid, 5000)
			npcHandler:say('Congratulations, you have finished mission 3 and now you are able to go with Josh, who will have more missions for you!', cid)
			setPlayerStorageValue(cid, 35000, 6)
			setPlayerStorageValue(cid, 35001, 1)
		end
	end
	return true
end
 
npcHandler:setMessage(MESSAGE_WALKAWAY, 'How rude!')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Mine:
Lua:
local keywordHandler = KeywordHandler:new()
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
 
local storage = 35000
local s = getPlayerStorageValue(cid, storage)
local r = doPlayerRemoveItem	
 
function creatureSayCallback(cid, type, msg)
if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'hey') and not npcHandler:isFocused(cid) then
   npcHandler:say('Hello ' .. GetCreatureName(cid) .. ' to start a mission say task!', cid)
   npcHandler:addFocus(cid)
   elseif not npcHandler:isFocused(cid) then
return false
 
elseif msgcontains(msg, 'bye') or msgcontains(msg, 'good bye') then
npcHandler:say('Good bye ' .. GetCreatureName(cid) .. ' come back if you want more missions!', cid)
npcHandler:releaseFocus(cid)
 
elseif msgcontains(msg, 'task') and s == -1 then ---- Start mission 1
npcHandler:say('You have started task number 1, bring me 10 wolf furs to complete it!', cid)
setPlayerStorageValue(cid,storage,1)
elseif s == 1 then
npcHandler:say('You are still in task number 1!', cid)
elseif s == 2 then ---- Start mission 2
npcHandler:say('You have started task number 2, bring me 20 red dragon scales to complete it!', cid)
setPlayerStorageValue(cid,storage,3)
elseif s == 3 then
npcHandler:say('You are already in task number 2!', cid)
elseif s == 4 then ---- Start mission 3
npcHandler:say('You have started task number 3, bring me 10 iron ores and 15 morgaroth\'s heart to complete it!', cid)
setPlayerStorageValue(cid,storage,5)
elseif s == 5 then
npcHandler:say('You are already in task number 3!', cid)
elseif s == 6 then
npcHandler:say('Hey my old friend, all my asignments with you are done, go with Josh for more missions!', cid)
 
 
elseif msgcontains(msg, 'report') and s == 1 and r(cid,11228, 10) then --- Finish mission 1
doPlayerAddExp(cid, 500)
npcHandler:say('Congratulations, you have finished mission 1!', cid)
setPlayerStorageValue(cid,storage,2)
elseif s == 3 and r(cid,5882, 20) then --- Finish mission 2
doPlayerAddExp(cid, 2000)
npcHandler:say('Congratulations, you have finished mission 2!', cid)
setPlayerStorageValue(cid,storage,4)
else if s == 5 and r(cid,5880, 10) and r(cid,5943, 15) then --- Finish mission 3
doPlayerAddExp(cid, 5000)
npcHandler:say('Congratulations, you have finished mission 3 and now you are able to go with Josh, who will have more missions for you!', cid)
setPlayerStorageValue(cid,storage,6)
setPlayerStorageValue(cid, 35001)
 
end
return true
end
end
npcHandler:setMessage(MESSAGE_WALKAWAY, 'How rude!')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Code:
[16/11/2010 23:12:30] [Error - Npc interface] 
[16/11/2010 23:12:30] data/npc/scripts/mission.lua:onCreatureSay
[16/11/2010 23:12:30] Description: 
[16/11/2010 23:12:30] data/npc/scripts/mission.lua:16: attempt to call global 'GetCreatureName' (a nil value)
[16/11/2010 23:12:30] stack traceback:
[16/11/2010 23:12:30] 	data/npc/scripts/mission.lua:16: in function 'callback'
[16/11/2010 23:12:30] 	data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[16/11/2010 23:12:30] 	data/npc/scripts/mission.lua:7: in function <data/npc/scripts/melchior.lua:7>

I just want to know, cuz I'm learning and I want to learn :p. Thanks a lot for everything tho
 
Lua is case-sensitive when it comes to variable and function names.
You could've noticed that GetCreatureName is not the same as getCreatureName.
 
Back
Top