• 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 Script not working, help to fix!

eyteew

es neko nesaprotu :D
Joined
Nov 25, 2009
Messages
104
Reaction score
0
Location
Thais
Hello!
I remade npc script to this, and it wont work...
-me- Hi!
-npc- hello, im poor man...can you help me?
-me- help
-npc- can you find wyvern fang?
-me- yes
-npc- <dont answer>

Will be very thankful if u will help me to find mistake :peace:


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

local Topic = {}

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 thinkCallback(cid)
	local random = math.random(250)
	if random == 1 then
		npcHandler:say("Sir, Ma'am, have a gold coin to spare?")
	elseif random == 2 then
		npcHandler:say("I need help! Please help me!")
	elseif random == 3 then
		npcHandler:say("Alms! Alms for the poor!")
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
		npcHandler:say("Hello " .. getCreatureName(cid) .. ". I am a poor man. Please HELP me!", cid, TRUE)
		Topic[cid] = 0
		npcHandler:addFocus(cid)
	elseif(not npcHandler:isFocused(cid)) then
		return false
	elseif Topic[cid] == 1 then
		if msgcontains(msg, "yes") then
			if doPlayerRemoveItem(cid,7408,1) == TRUE then
				npcHandler:say("Thank you very much! Take your reward!", cid)
				local key = doCreateItemEx(2087, 1)
				doItemSetAttribute(key, "aid", 3940)
				doPlayerAddItemEx(cid, key, 1)
			else
				npcHandler:say("You don't have it.", cid)
			end
		else
			npcHandler:say("Ok... No problem!", cid)
		end
		Topic[cid] = 0
	elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
		npcHandler:say("Have a nice day.", cid, TRUE)
		Topic[cid] = 0
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "help") then
		npcHandler:say("I need wyvern fang. Can you find it for me?", cid)
		Topic[talkUser] = 1
	end
	return true
end

npcHandler:setMessage(MESSAGE_WALKAWAY, "Have a nice day.")
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited:
Code:
[30/05/2010 14:58:04] Lua Script Error: [Npc interface] 
[30/05/2010 14:58:04] data/npc/scripts/Pedro.lua:onCreatureSay

[30/05/2010 14:58:04] data/npc/scripts/Pedro.lua:51: table index is nil
[30/05/2010 14:58:04] stack traceback:
[30/05/2010 14:58:04] 	data/npc/scripts/Pedro.lua:51: in function 'callback'
[30/05/2010 14:58:04] 	data/npc/lib/npcsystem/npchandler.lua:374: in function 'onCreatureSay'
[30/05/2010 14:58:04] 	data/npc/scripts/Pedro.lua:9: in function <data/npc/scripts/Pedro.lua:9>

0.3.1 v1

im not scripter, so there can be stupid mistake :D
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}

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 thinkCallback(cid)
	local random = math.random(250)
	if random == 1 then
		npcHandler:say("Sir, Ma'am, have a gold coin to spare?")
	elseif random == 2 then
		npcHandler:say("I need help! Please help me!")
	elseif random == 3 then
		npcHandler:say("Alms! Alms for the poor!")
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
		npcHandler:say("Hello " .. getCreatureName(cid) .. ". I am a poor man. Please HELP me!", cid, TRUE)
		Topic[cid] = 0
		npcHandler:addFocus(cid)
	elseif(not npcHandler:isFocused(cid)) then
		return false
	elseif Topic[cid] == 1 then
		if msgcontains(msg, "yes") then
			if doPlayerRemoveItem(cid,7408,1) == TRUE then
				npcHandler:say("Thank you very much! Take your reward!", cid)
				local key = doCreateItemEx(2087, 1)
				[COLOR="Red"][B]doSetItemActionId(key, 3940)[/B][/COLOR]
				doPlayerAddItemEx(cid, key, 1)
			else
				npcHandler:say("You don't have it.", cid)
			end
		else
			npcHandler:say("Ok... No problem!", cid)
		end
		Topic[cid] = 0
	elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
		npcHandler:say("Have a nice day.", cid, TRUE)
		Topic[cid] = 0
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "help") then
		npcHandler:say("I need wyvern fang. Can you find it for me?", cid)
		[B]Topic[[COLOR="Red"]cid[/COLOR]] = 1[/B]
	end
	return true
end

npcHandler:setMessage(MESSAGE_WALKAWAY, "Have a nice day.")
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Back
Top