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

Problem with TFS npc's

christiandb

Member
Joined
Feb 5, 2008
Messages
2,469
Reaction score
5
Location
010
Hey,

I've added some others npc's to my TFS server but when I say hi they aren't responding. The bug I get:

[26/08/2008 20:55:10] Lua Script Error: [Npc interface]
[26/08/2008 20:55:11] data/npc/scripts/seller.lua:onCreatureSay

[26/08/2008 20:55:11] data/npc/scripts/seller.lua:39: attempt to call global 'getDistanceToCreature' (a nil value)
[26/08/2008 20:55:11] stack traceback:
[26/08/2008 20:55:11] data/npc/scripts/seller.lua:39: in function <data/npc/scripts/seller.lua:36>

Does anyone know how to fix this?

Thanks in advance,

Chris~
 
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, ' .. creatureGetName(cid) .. '! I sell ropes (50gp), shovels (20gp), backpacks (10gp), manafluids (100gp), lifefluids (60gp), fishing rods (100gp), amulet of loss (10k), and torches (2gp). I buy vials (10gp).')
          focus = cid
          talk_start = os.clock()

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

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

        if msgcontains(msg, 'shovel') then
            buy(cid,2554,getCount(msg),20)
        elseif msgcontains(msg, 'backpack') then
            buy(cid,1988,getCount(msg),10)
        elseif msgcontains(msg, 'manafluid') or msgcontains(msg, 'mana fluid') then
            buyFluidContainer(cid,2006,getCount(msg),100,7)
        elseif msgcontains(msg, 'lifefluid') or msgcontains(msg, 'life fluid') then
            buyFluidContainer(cid,2006,getCount(msg),60,10)
        elseif msgcontains(msg, 'fishing rod') then
            buy(cid,2580,getCount(msg),100)
        elseif msgcontains(msg, 'torch') then
            buy(cid,2050,getCount(msg),2)
        elseif msgcontains(msg, 'aol') then
            buy(cid,2173,getCount(msg),10000)    
        elseif msgcontains(msg, 'vial') or msgcontains(msg, 'flask') then
            sell(cid,2006,getCount(msg),10)

        elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
            selfSay('Good 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('Next Please...')
          end
              focus = 0
      end
     if focus ~= 0 then
         if getDistanceToCreature(focus) > 5 then
             selfSay('Good bye then.')
             focus = 0
         end
     end
end


btw i have it with ALL the npcs
 
[26/08/2008 20:55:11] data/npc/scripts/seller.lua:39: attempt to call global 'getDistanceToCreature' (a nil value)



Chris~

This is sayin that that command "getdistancetocreature" is not a command the server recognizes, i had this problem before with rune npc when tryin to do bp sd as a buyable item.

I have not yet figured this out but im close when i do ill let u know.

HOWEVER! for the shovel and those single items try this :

<parameter key="shop_buyable" value="backpack,1988,20;pick,2553,10;shovel,2554,20;rope,2120,50"/>

(if the script is in npcname.xml file)Make sure each added item has :shovel,2554,20; formate.
shovel = name, 2554 = item id, 20 = price. and always end with a ";"

(if script is in the .lau file)In rune script and such use this format.
shopModule:addBuyableItem({'wand of vortex', 'vortex'}, 2190, 500, 'wand of vortex')

change the name, itemid(2190), price(500) and thats a working script right there

Hope i help you. I am a ultra noob scripter.
 
Last edited:
Using what distro and version?

The newest TFS

This is sayin that that command "getdistancetocreature" is not a command the server recognizes, i had this problem before with rune npc when tryin to do bp sd as a buyable item.

I have not yet figured this out but im close when i do ill let u know.

HOWEVER! for the shovel and those single items try this :



(if the script is in npcname.xml file)Make sure each added item has :shovel,2554,20; formate.
shovel = name, 2554 = item id, 20 = price. and always end with a ";"

(if script is in the .lau file)In rune script and such use this format.
shopModule:addBuyableItem({'wand of vortex', 'vortex'}, 2190, 500, 'wand of vortex')

change the name, itemid(2190), price(500) and thats a working script right there

Hope i help you. I am a ultra noob scripter.

You helped me, but the problem is when I need to do that with all the NPC's it will take ages to fix it :p
 
Back
Top