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

[NPC]Bless error!

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,682
Solutions
126
Reaction score
1,121
Location
Germany
GitHub
slawkens
My NPC with blessing work good. I can buy all, NPC respond, but sometimes i get msg in my TFS console:
Code:
Lua Script Error: [Npc interface] 
data/npc/scripts/bless.lua:onCreatureSay

data/npc/scripts/bless.lua:32: attempt to compare number with nil
I don't know why it is. But its not make crash and nothink, only this msg in console.

And here is my bless.lua file:
Code:
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 creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return FALSE
			end
	if msgcontains(msg, 'blessing') or msgcontains(msg, 'blessings') or msgcontains(msg, 'help') or msgcontains(msg, 'offer') then
		selfSay("I can provide you with five blessings... the 'first bless', 'second bless', 'third bless', 'fourth bless' and the 'fifth bless', they cost 10000 gold coins each.")
		talkState = 0
	elseif msgcontains(msg, 'first bless') then
		selfSay("Do you want to buy the first blessing for 10000 gold?")
		talkState = 1
	elseif msgcontains(msg, 'second bless') then
		selfSay("Do you want to buy the second blessing for 10000 gold?")
		talkState = 2
	elseif msgcontains(msg, 'third bless') then
		selfSay("Do you want to buy the third blessing for 10000 gold?")
		talkState = 3
	elseif msgcontains(msg, 'fourth bless') then
		selfSay("Do you want to buy the fourth blessing for 10000 gold?")
		talkState = 4
	elseif msgcontains(msg, 'fifth bless') then
		selfSay("Do you want to buy the fifth blessing for 10000 gold?")
		talkState = 5
	elseif talkState > 0 then
		if msgcontains(msg, 'yes') then
			if getPlayerBlessing(cid, talkState) then
				selfSay("A god has already blessed you with this blessing.")
			else
				if isPremium(cid) == TRUE then
					if doPlayerRemoveMoney(cid, 10000) == TRUE then
						doPlayerAddBlessing(cid, talkState)
						selfSay("You have been blessed by one of the five gods!")
					else
						selfSay("You don't have enough money.")
					end
				else
					selfSay("You need a premium account to buy blessings.")
				end
			end
		elseif msgcontains(msg, 'no') then
			selfSay("Then not.")
		end
		talk_state = 0
	end
	return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

My 32 line:
Code:
	elseif talkState > 0 then
 
Last edited:
Try this bless script it got an minor bug fix

Code:
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 creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return FALSE
	end

	if msgcontains(msg, 'blessing') or msgcontains(msg, 'blessings') or msgcontains(msg, 'help') or msgcontains(msg, 'offer') then
		selfSay("I can provide you with five blessings... the 'first bless', 'second bless', 'third bless', 'fourth bless' and the 'fifth bless', they cost 10000 gold coins each.")
		talkState = 0
	elseif msgcontains(msg, 'first bless') then
		selfSay("Do you want to buy the first blessing for 10000 gold?")
		talkState = 1
	elseif msgcontains(msg, 'second bless') then
		selfSay("Do you want to buy the second blessing for 10000 gold?")
		talkState = 2
	elseif msgcontains(msg, 'third bless') then
		selfSay("Do you want to buy the third blessing for 10000 gold?")
		talkState = 3
	elseif msgcontains(msg, 'fourth bless') then
		selfSay("Do you want to buy the fourth blessing for 10000 gold?")
		talkState = 4
	elseif msgcontains(msg, 'fifth bless') then
		selfSay("Do you want to buy the fifth blessing for 10000 gold?")
		talkState = 5
	elseif talkState > 0 then
		if msgcontains(msg, 'yes') then
			if getPlayerBlessing(cid, talkState) then
				selfSay("A god has already blessed you with this blessing.")
			elseif isPremium(cid) == TRUE then
				if doPlayerRemoveMoney(cid, 10000) == TRUE then
					doPlayerAddBlessing(cid, talkState)
					selfSay("You have been blessed by one of the five gods!")
				else
					selfSay("You don't have enough money.")
				end
			else
				selfSay("You need a premium account to buy blessings.")
			end
		elseif msgcontains(msg, 'no') then
			selfSay("Then not.")
		end
		talk_state = 0
	end
	return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
No, it isn't fixed. Still i get this error in console:

Code:
Lua Script Error: [Npc interface] 
data/npc/scripts/bless.lua:onCreatureSay

data/npc/scripts/bless.lua:33: attempt to compare number with nil

Now i just know how its make. You must say hi to NPC and now you must wait. The error message will be msg in colsole. =\
 
Try this bless script it got an minor bug fix

Code:
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 creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return FALSE
	end

	if msgcontains(msg, 'blessing') or msgcontains(msg, 'blessings') or msgcontains(msg, 'help') or msgcontains(msg, 'offer') then
		selfSay("I can provide you with five blessings... the 'first bless', 'second bless', 'third bless', 'fourth bless' and the 'fifth bless', they cost 10000 gold coins each.")
		talkState = 0
	elseif msgcontains(msg, 'first bless') then
		selfSay("Do you want to buy the first blessing for 10000 gold?")
		talkState = 1
	elseif msgcontains(msg, 'second bless') then
		selfSay("Do you want to buy the second blessing for 10000 gold?")
		talkState = 2
	elseif msgcontains(msg, 'third bless') then
		selfSay("Do you want to buy the third blessing for 10000 gold?")
		talkState = 3
	elseif msgcontains(msg, 'fourth bless') then
		selfSay("Do you want to buy the fourth blessing for 10000 gold?")
		talkState = 4
	elseif msgcontains(msg, 'fifth bless') then
		selfSay("Do you want to buy the fifth blessing for 10000 gold?")
		talkState = 5
	elseif talkState > 0 then
		if msgcontains(msg, 'yes') then
			if getPlayerBlessing(cid, talkState) then
				selfSay("A god has already blessed you with this blessing.")
			elseif isPremium(cid) == TRUE then
				if doPlayerRemoveMoney(cid, 10000) == TRUE then
					doPlayerAddBlessing(cid, talkState)
					selfSay("You have been blessed by one of the five gods!")
				else
					selfSay("You don't have enough money.")
				end
			else
				selfSay("You need a premium account to buy blessings.")
			end
		elseif msgcontains(msg, 'no') then
			selfSay("Then not.")
		end
		talk_state = 0
	end
	return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

This one worked perfect for me. Thanks Mokerhamer!
 
how i add effect on this code?

ex:
doSendMagicEffect(pos, 12)

Cya.

put that there (u should see where) instead of old one:
Code:
				if doPlayerRemoveMoney(cid, 10000) == TRUE then
					doPlayerAddBlessing(cid, talkState)
                                        doSendMagicEffect(getPlayerPosition(cid), 12)
					selfSay("You have been blessed by one of the five gods!")
 
Back
Top