• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Windows NPC Database "onThink" Error

Justin123456

New Member
Joined
Mar 24, 2011
Messages
177
Reaction score
4
I randomly get this Error in my database
Code:
[26/06/2012 13:56:48] [Error - Npc interface] 
[26/06/2012 13:56:48] data/npc/scripts/greeter.lua:onThink
[26/06/2012 13:56:48] Description: 
[26/06/2012 13:56:48] data/npc/scripts/greeter.lua:97: attempt to compare number with nil
[26/06/2012 13:56:48] stack traceback:
[26/06/2012 13:56:48] 	data/npc/scripts/greeter.lua:97: in function <data/npc/scripts/greeter.lua:89>

Is there any way how to fix it? Because it keeps spamming. Also, here's my Greeter.lua:
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('Have fun in VIP Island.')
          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) .. '! Welcome to Train Island go south if you wenna find new hunting zones for hight levels!')
  		focus = cid
  		talk_start = os.clock()

  	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. getCreatureName(cid) .. ' im talking with another player wait for your turn..')

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

		if msgcontains(msg, 'shovel221') then
			buy(cid,2554,getCount(msg),20)
		elseif msgcontains(msg, 'backp2ack') then
			buy(cid,1988,getCount(msg),10)
		elseif msgcontains(msg, 'bp manafluids2') then
			buyContainer(cid, 2002, 2006, 7, 2000)
		elseif msgcontains(msg, 'manaflui2d') or msgcontains(msg, 'man2a fluid') then
			buyFluidContainer(cid,2006,getCount(msg),100,7)
		elseif msgcontains(msg, 'lifefl2uid') or msgcontains(msg, 'li2fe fluid') then
			buyFluidContainer(cid,2006,getCount(msg),60,10)
		elseif msgcontains(msg, 'fishi2ng rod') then
			buy(cid,2580,getCount(msg),100)
		elseif msgcontains(msg, 'to2rch') then
			buy(cid,2050,getCount(msg),2)
		elseif msgcontains(msg, 'ro2pe') then
			buy(cid,2120,getCount(msg),50)
		elseif msgcontains(msg, 'ao2l') then
			buy(cid,2173,getCount(msg),10000)	
		elseif msgcontains(msg, 'via2l') or msgcontains(msg, 'fla2sk') then
			sell(cid,2006,getCount(msg),10)
		elseif msgcontains(msg, 'obsid2ian knife') or msgcontains(msg, 'kni2fe') then
			sell(cid,5908,getCount(msg),10000)
		elseif msgcontains(msg, 'bless2ed wooden stake') or msgcontains(msg, 'blesse2d wooden stake') then
			sell(cid,5942,getCount(msg),6000)

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


function onCreatureChangeOutfit(creature)

end


function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Have fun in new hunting Island!')
  		end
  			focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Have fun in new hunting Island!')
 			focus = 0
 		end
 	end
end

I'm using TFS 0.3.6
I'll REP whoever helps me :D
 
Try this mate :)

LUA:
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('Have fun in VIP Island.')
          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) .. '! Welcome to Train Island go south if you wenna find new hunting zones for hight levels!')
  		focus = cid
  		talk_start = os.clock()

  	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. getCreatureName(cid) .. ' im talking with another player wait for your turn..')

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

		if msgcontains(msg, 'shovel221') then
			buy(cid,2554,getCount(msg),20)
		elseif msgcontains(msg, 'backp2ack') then
			buy(cid,1988,getCount(msg),10)
		elseif msgcontains(msg, 'bp manafluids2') then
			buyContainer(cid, 2002, 2006, 7, 2000)
		elseif msgcontains(msg, 'manaflui2d') or msgcontains(msg, 'man2a fluid') then
			buyFluidContainer(cid,2006,getCount(msg),100,7)
		elseif msgcontains(msg, 'lifefl2uid') or msgcontains(msg, 'li2fe fluid') then
			buyFluidContainer(cid,2006,getCount(msg),60,10)
		elseif msgcontains(msg, 'fishi2ng rod') then
			buy(cid,2580,getCount(msg),100)
		elseif msgcontains(msg, 'to2rch') then
			buy(cid,2050,getCount(msg),2)
		elseif msgcontains(msg, 'ro2pe') then
			buy(cid,2120,getCount(msg),50)
		elseif msgcontains(msg, 'ao2l') then
			buy(cid,2173,getCount(msg),10000)	
		elseif msgcontains(msg, 'via2l') or msgcontains(msg, 'fla2sk') then
			sell(cid,2006,getCount(msg),10)
		elseif msgcontains(msg, 'obsid2ian knife') or msgcontains(msg, 'kni2fe') then
			sell(cid,5908,getCount(msg),10000)
		elseif msgcontains(msg, 'bless2ed wooden stake') or msgcontains(msg, 'blesse2d wooden stake') then
			sell(cid,5942,getCount(msg),6000)

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


function onCreatureChangeOutfit(creature)

end


function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Have fun in new hunting Island!')
  		end
  			focus = 0
  	end
 	if focus > 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Have fun in new hunting Island!')
 			focus = 0
 		end
 	end
end
 
Thanks :D I'll try it out for a bit and see if it doesn't do it again :D
~Edit: It worked! :D Except there was one little error that I found but I changed it :D It was just "CreatureGetName" I had to change to "Getcreaturename" and then it worked :D Thanks I gave you Rep!


Also I got another error : /
Whenever I open the book with writing in it that has the id of 1964, it gives me this error:
Code:
[26/06/2012 14:24:26] [Error - Action Interface] 
[26/06/2012 14:24:26] data/actions/scripts/rwitems.lua:onUse
[26/06/2012 14:24:26] Description: 
[26/06/2012 14:24:26] data/actions/scripts/rwitems.lua:5: attempt to call global 'doShowTextWindow' (a nil value)
[26/06/2012 14:24:26] stack traceback:
[26/06/2012 14:24:26] 	data/actions/scripts/rwitems.lua:5: in function <data/actions/scripts/rwitems.lua:1>

Here's my rwitems script:
Code:
function onUse(cid, item, frompos, item2, topos)
   	rw = getItemRWInfo(item.uid)
   	if rw and 1 then
   		if rw and 2 then
   			doShowTextWindow(item.uid,100,1)
   		else
   			doShowTextWindow(item.uid,100,1)
   		end
   	else
   		if item.itemid == 2598 then
   			doShowTextWindow(item.uid,0,0)
   		end
   	end
   
   	return 1
    
   end
 
Last edited:
PHP:
function onUse(cid, item, frompos, item2, topos)
   	rw = getItemRWInfo(item.uid)
   	if rw and 1 then
   		if rw and 2 then
   			doShowTextDialog(cid, 2598, text)
   		else
   			doShowTextDialog(cid, 2598, text)
   		end
   	else
   		if item.itemid == 2598 then
   			doShowTextDialog(cid, 2598, text)
   		end
   	end
   
   	return TRUE
    
   end

:3 try this
 
Back
Top