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

Help with this NPC

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
Hello, i'm using TFS v0.3 beta 2 and i have the following errors with this npc

Code:
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
  		selfSay('Hello ' .. getCreatureName(cid) .. '!, I can give you the first Demon Hunter Addon.', cid)
  		focus = cid
  		talk_start = os.clock()

  	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk to you in a minute.', cid)

	elseif focus == cid then
		talk_start = os.clock()

	if msgcontains(msg, 'help') then
			selfSay('I can give you the first Demon Hunter Addon', cid)


	elseif msgcontains(msg, 'addon') then
                 if getPlayerStorageValue(cid,35417) == 2 then
					selfSay('You already have the first Demon Hunter addon.', cid)
					talk_state = 0
		else
				selfSay('Do you have done The Inquisition Quest?.', cid)
					talk_state = 1
	end
	elseif msgcontains(msg, 'yes') and talk_state == 1 then
                 if getPlayerStorageValue(cid,35417) == -1 then
		  			selfSay('Sorry, i can not give you the present.', cid)
					talk_state = 0
                 elseif getPlayerStorageValue(cid,35417) == 2 then  
					selfSay('You already have the first Demon Hunter addon.', cid)
					talk_state = 0
		else
			selfSay('Congratulations, here is your reward.', cid)
			if getPlayerSex(cid) == 0 then
		    doPlayerAddOutfit(cid, 288, 1)
			doPlayerAddOutfit(cid, 289, 1)
		    setPlayerStorageValue(cid,35417,2)
			else
			doPlayerAddOutfit(cid, 289, 1)
		    doPlayerAddOutfit(cid, 288, 1)
			setPlayerStorageValue(cid,35417,2)
			end
        end	
  	

        elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
            selfSay('Good Bye ' .. getCreatureName(cid) .. '', cid)
            focus = 0
            talk_start = 0
	end
    end
end

function onCreatureChangeOutfit(creature)
end

function onThink()
    doNpcSetCreatureFocus(focus)
    if (os.clock() - talk_start) > 30 then
        if focus > 0 then
            selfSay('Next Please...')
        end
        focus = 0
        talk_start = 0
    end
    if focus ~= 0 then
        if getDistanceToCreature(focus) > 5 then
            selfSay('Good Bye', cid)
            focus = 0
            talk_start = 0
        end
    end
end

Here are the following errors...

Code:
[29/12/2008 12:05:21] Lua Script Error: [Npc interface] 
[29/12/2008 12:05:21] data/npc/scripts/first_inquisition_demonhunter.lua:onCreatureSay

[29/12/2008 12:05:21] data/npc/scripts/first_inquisition_demonhunter.lua:39: attempt to compare nil with number
[29/12/2008 12:05:21] stack traceback:
[29/12/2008 12:05:21] 	data/npc/scripts/first_inquisition_demonhunter.lua:39: in function <data/npc/scripts/first_inquisition_demonhunter.lua:36>

What is wrong? (In TFS v0.2 it works)
 
Last edited:
Here is...

Code:
[29/12/2008 12:05:21] Lua Script Error: [Npc interface] 
[29/12/2008 12:05:21] data/npc/scripts/first_inquisition_demonhunter.lua:onCreatureSay

[29/12/2008 12:05:21] data/npc/scripts/first_inquisition_demonhunter.lua:39: attempt to compare nil with number
[29/12/2008 12:05:21] stack traceback:
[29/12/2008 12:05:21] 	data/npc/scripts/first_inquisition_demonhunter.lua:39: in function <data/npc/scripts/first_inquisition_demonhunter.lua:36>
 
The problem is here:
Code:
getDistanceToCreature(cid)
This function not exist...
So LUA take it as nill...
You can use it:
Code:
if (msgcontains(msg, 'hi') and (focus == 0)) then

I think it gonna work.

EDIT--

Ah, you must take all getDistanceToCreature...
 
Back
Top