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

Solved Help with my NPC script please!

kaspertje100

Member
Joined
May 8, 2008
Messages
236
Reaction score
7
my script:

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
 
	if(msgcontains(msg, 'north gate')) then
		selfSay('Do you want to travel to the north gate for 50 gold coins?', cid)
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if getPlayerlevel(cid) <= 30 then
			if(doPlayerRemoveMoney(cid, 50)) then
				doTeleportThing(cid, {x= 828, y=1137, z=7})
				selfSay('There you go!', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		elseif getPlayerlevel(cid) <= 30 then
			if(doPlayerRemoveMoney(cid, 50)) then
				doTeleportThing(cid, {x= 828, y=1137, z=7})
				selfSay('There you go!', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you are too high level', cid)
		end
	elseif(msgcontains(msg, 'no') and isInArray({1})) then
		selfSay('Ok then.', cid)
	end

error msg:
Code:
[19/05/2013 19:00:32] [Error - Npc interface] 
[19/05/2013 19:00:32] data/npc/scripts/huifkar.lua
[19/05/2013 19:00:32] Description: 
[19/05/2013 19:00:32] data/npc/lib/npc.lua:54: attempt to index local 'message' (a nil value)
[19/05/2013 19:00:32] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/huifkar.lua

so this npc should be able to teleport players of level <= 30 and ask 50 GP for that.
My problem is that the NPC doesn't even talk at all.
 
Use (under this line: function onThink() npcHandler:eek:nThink() end)
Lua:
function creatureSayCallback(cid, type, msg)

It's also missing more things, you use talkUser, so add this.
Lua:
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
And add this under the function, so it only response when focused.
Lua:
	if(not npcHandler:isFocused(cid)) then
		return false
	end

And this at the end of the script, for the function creatureSayCallback and to add focus on greet.
Lua:
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Also don't forget to use return true and end the function.
 
Code:
[19/05/2013 19:24:16] [Warning] NpcSystem:
[19/05/2013 19:24:16] Parameter(s) missing for item:
[19/05/2013 19:24:16] christmas tree

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(not npcHandler:isFocused(cid)) then
		return false
	end
if(msgcontains(msg, 'north gate')) then
	selfSay('Do you want to travel to the north gate for 50 gold coins?', cid)
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
	if getPlayerlevel(cid) <= 30 then
		if(doPlayerRemoveMoney(cid, 50)) then
			doTeleportThing(cid, {x= 828, y=1137, z=7})
			selfSay('There you go!', cid)
		else
			selfSay('Sorry, you don\'t have enough gold.', cid)
		end
	elseif getPlayerlevel(cid) <= 30 then
		if(doPlayerRemoveMoney(cid, 50)) then
			doTeleportThing(cid, {x= 828, y=1137, z=7})
			selfSay('There you go!', cid)
		else
			selfSay('Sorry, you don\'t have enough gold.', cid)
		end
	else
		selfSay('Sorry, you are too high level', cid)
	end
elseif(msgcontains(msg, 'no') and isInArray({1})) then
	selfSay('Ok then.', cid)
	
	npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
	npcHandler:addModule(FocusModule:new())
	return true
end
end

the npc still dont wanna talk to me xD
 
Add this at the end of the script, under all ends.
Lua:
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Also use return true above the last end, else it's only if someone says no.
 
So I say north gate and it asks me if i wanna go to north gate for 50gp but then when I say yes nothing happens the npc dont talk I wont get tp, no error in console only christmas tree shit I mean wtf is that anyways xD

- - - Updated - - -

[19/05/2013 20:02:45] [Error - Npc interface]
[19/05/2013 20:02:46] data/npc/scripts/huifkar.lua:eek:nCreatureSay
[19/05/2013 20:02:46] Description:
[19/05/2013 20:02:46] data/npc/lib/npcsystem/modules.lua:487: attempt to concatenate local 'msg' (a nil value)
[19/05/2013 20:02:46] stack traceback:
[19/05/2013 20:02:46] data/npc/lib/npcsystem/modules.lua:487: in function 'callback'
[19/05/2013 20:02:46] data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
[19/05/2013 20:02:46] data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
[19/05/2013 20:02:46] data/npc/lib/npcsystem/keywordhandler.lua:128: in function 'processMessage'
[19/05/2013 20:02:46] data/npc/lib/npcsystem/npchandler.lua:387: in function 'onCreatureSay'
[19/05/2013 20:02:46] data/npc/scripts/huifkar.lua:8: in function <data/npc/scripts/huifkar.lua:8>
 
In the yes line you check for talkState[talkUser] == 1, but it's not set when you say north gate.
So add this.
Lua:
talkState[talkUser] = 1
Also, you are checking 2x for the same thing.
Lua:
if getPlayerlevel(cid) <= 30 then
elseif getPlayerlevel(cid) <= 30 then
 
error:
Code:
[19/05/2013 20:19:03] [Error - Npc interface] 
[19/05/2013 20:19:03] data/npc/scripts/huifkar.lua:onCreatureSay
[19/05/2013 20:19:03] Description: 
[19/05/2013 20:19:03] data/npc/scripts/huifkar.lua:20: attempt to call global 'getPlayerlevel' (a nil value)
[19/05/2013 20:19:03] stack traceback:
[19/05/2013 20:19:03] 	data/npc/scripts/huifkar.lua:20: in function 'callback'
[19/05/2013 20:19:03] 	data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[19/05/2013 20:19:03] 	data/npc/scripts/huifkar.lua:8: in function <data/npc/scripts/huifkar.lua:8>

code:
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(not npcHandler:isFocused(cid)) then
		return false
	end
if(msgcontains(msg, 'north gate')) then
	talkState[talkUser] = 1
	selfSay('Do you want to travel to the north gate for 50 gold coins?', cid)
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
	if(getPlayerlevel(cid)) <= 30 then
		if(doPlayerRemoveMoney(cid, 50)) then
			doTeleportThing(cid, {x= 828, y=1137, z=7})
			selfSay('There you go!', cid)
		else
			selfSay('Sorry, you don\'t have enough gold.', cid)
		end
	elseif getPlayerlevel(cid) <= 30 then
		if(doPlayerRemoveMoney(cid, 50)) then
			doTeleportThing(cid, {x= 828, y=1137, z=7})
			selfSay('There you go!', cid)
		else
			selfSay('Sorry, you don\'t have enough gold.', cid)
		end
	else
		selfSay('Sorry, you are too high level', cid)
	end
elseif(msgcontains(msg, 'no') and isInArray({1})) then
	selfSay('Ok then.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 

Similar threads

Back
Top