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

Npc Error

7amo

New Member
Joined
Feb 16, 2011
Messages
147
Reaction score
3
Location
egypt
All Npcs Of My Server Give Me This Error

[Error - Npc interface]
[31/05/2014 05:51:56] data/npc/scripts/food.lua
[31/05/2014 05:51:56] Description:
[31/05/2014 05:51:56] data/npc/scripts/food.lua:1: attempt to index global 'KeywordHandler' (a nil value)
[31/05/2014 05:51:56] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/food.lua
[31/05/2014 05:51:57] cannot open data/npc/lib/npc.lua: No such file or directory

How To Fix ?
 
Are you other npc files working? In that case post npc/scripts/food.lua otherwise replace your npc/lib/... files with those from the tfs version you are using.
 
This Is My Scripts Of Npc
<npc name="Donald" script="data/npc/scripts/food.lua" autowalk="25" floorchange="0" access="5" level="1" maglevel="1">
<health now="150" max="150"/>
<look type="128" head="20" body="100" legs="50" feet="99" corpse="2212"/>
<parameters>
<parameter key="module_shop" value="1" />
<parameter key="message_greet" value="Hello |PLAYERNAME|. I sell dragon ham, ham, meat, carrots, apples, brown breads, brown mushrooms and eggs (everything for 8 gold coins)!" />
<parameter key="shop_buyable" value="brown bread,2691,8;dragon ham,2672,10;ham,2671,8;carrot,2684,8;meat,2666,8;apple,2674,8;brown mushroom,2789,8;egg,2695,8" />
</parameters>
</npc>

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

-- OTServ event handling functions start
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
-- OTServ event handling functions end

npcHandler:addModule(FocusModule:new())
 
something is wrong with the libs

edit: [31/05/2014 05:51:57] cannot open data/npc/lib/npc.lua: No such file or directory

you dont have that script (this is what i got tfs 0.4)

npcs/scripts/libs/npc.lua (add it here and see if it works)
Code:
-- Include external classes.
dofile('data/npc/scripts/lib/npcsystem/npcsystem.lua')

-- get the distance to a creature
function getDistanceToCreature(id)
    if id == 0 or id == nil then
        selfGotoIdle()
    end
   
    cx, cy, cz = creatureGetPosition(id)
    sx, sy, sz = selfGetPosition()
   
    if cx == nil then
        return nil
    end
   
    return math.max(math.abs(sx-cx), math.abs(sy-cy))
end

-- do one step to reach position
function moveToPosition(x,y,z)
    selfMoveTo(x, y, z)
end

-- do one step to reach creature
function moveToCreature(id)
    if id == 0 or id == nil then
        selfGotoIdle()
    end
    tx,ty,tz=creatureGetPosition(id)
    if tx == nil then
        selfGotoIdle()
    else
       moveToPosition(tx, ty, tz)
   end
end

-- stop talking
function selfGotoIdle()
    following = false
    attacking = false
    selfAttackCreature(0)
    target = 0
end

-- getCount function by Jiddo
function getCount(msg)
    b, e = string.find(msg, "%d+")
   
    if b == nil or e == nil then
        count = 1
    else
        count = tonumber(string.sub(msg, b, e))
    end
   
    if count > 2000 then
        count = 2000
    elseif count == 0 then
        count = 1
    end
   
    return count
end

-- buy an item
function buy(cid, itemid, count, cost)
    cost = count*cost
    amount = count
    if doPlayerRemoveMoney(cid, cost) == 1 then
        if getItemStackable(itemid) then
            while count > 100 do
                doPlayerAddItem(cid, itemid, 100)
                count = count - 100
            end
           
            doPlayerAddItem(cid, itemid, count) -- add the last items, if there is left
        else
            while count > 0 do
                doPlayerAddItem(cid, itemid, 1)
                count = count - 1
            end
        end
       
        if amount <= 1 then
            selfSay('Here is your '.. getItemName(itemid) .. '!')
        else
            selfSay('Here are your '.. amount ..' '.. getItemName(itemid) .. 's!')       
        end
    else
        selfSay('Sorry, you do not have enough money.')
    end
end

function buyFluidContainer(cid, itemid, count, cost, fluidtype)
    cost = count*cost
    amount = count
    if doPlayerRemoveMoney(cid, cost) == 1 then
        while count > 0 do
            doPlayerAddItem(cid, itemid, fluidtype)
            count = count - 1
        end
       
        if amount <= 1 then
            selfSay('Here is your '.. getItemName(itemid) .. '!')
        else
            selfSay('Here are your '.. amount ..' '.. getItemName(itemid) .. 's!')       
        end
    else
        selfSay('Sorry, you do not have enough money.')
    end
end

function buyContainer(cid, container, itemid, count, money)
    if doPlayerRemoveMoney(cid, money) == 1 then
        bp = doPlayerAddItem(cid, container, 1)
        x = 0
       
        while x < 20 do
            doAddContainerItem(bp, itemid, count)
            x = x + 1
        end
       
        selfSay('Here you are.')
    else
        selfSay('Sorry, you don\'t have enough money.')
    end
end

-- sell an item
function sell(cid, itemid, count, cost)
    cost = count*cost
    if doPlayerRemoveItem(cid, itemid, count) == 1 then
        doPlayerAddMoney(cid, cost)
       
        if cost > 0 then
            selfSay('You couldn\'t retrieve '.. cost ..' gold pieces, please contact the admin.')
        end
       
        if count <= 1 then
            selfSay('Thanks for this '.. getItemName(itemid) .. '!')
        else
            selfSay('Thanks for these '.. count..' '.. getItemName(itemid) .. 's!')       
        end
    else
        selfSay('Sorry, you do not have this item.')
    end
end

-- pay for anything?
function pay(cid, cost)
    if doPlayerRemoveMoney(cid, cost) == 1 then
        return true
    else
        return false
    end
end

-- learn spell
function learnSpell(cid, spell, cost)
    x,y,z = creatureGetPosition(cid)
    if doPlayerLearnSpell(cid, spell) == 1 then
        if doPlayerRemoveMoney(cid, cost) == 1 then
            doSendMagicEffect({x=x, y=y, z=z}, 14)
            selfSay('To use it say: '.. spell ..'.')
        else
            selfSay('Sorry, you do not have this item.')
        end
    else
        selfSay('You already know this spell.')
    end
end

-- Travel player
function travel(cid, x, y, z)
    destpos = {x = x, y = y, z = z}
    doTeleportThing(cid, destpos)
    doSendMagicEffect(destpos, 10)
end

-- add all addons
function addon(cid, addon)
    if getPlayerSex(cid) == 1 then
        for x = 128, 134 do
            doPlayerAddAddon(cid, x, addon)
        end

        for y = 143, 146 do
            doPlayerAddAddon(cid, y, addon)
        end
       
        for z = 151, 154 do
            doPlayerAddAddon(cid, z, addon)
        end
    else   
        for x = 136, 142 do
            doPlayerAddAddon(cid, x, addon)
        end

        for y = 147, 150 do
            doPlayerAddAddon(cid, y, addon)
        end
       
        for z = 155, 158 do
            doPlayerAddAddon(cid, z, addon)
        end
    end
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
 
Last edited:
something is wrong with the libs

edit: [31/05/2014 05:51:57] cannot open data/npc/lib/npc.lua: No such file or directory

you dont have that script (this is what i got tfs 0.4)

npcs/scripts/libs/npc.lua (add it here and see if it works)
Code:
-- Include external classes.
dofile('data/npc/scripts/lib/npcsystem/npcsystem.lua')

-- get the distance to a creature
function getDistanceToCreature(id)
    if id == 0 or id == nil then
        selfGotoIdle()
    end
  
    cx, cy, cz = creatureGetPosition(id)
    sx, sy, sz = selfGetPosition()
  
    if cx == nil then
        return nil
    end
  
    return math.max(math.abs(sx-cx), math.abs(sy-cy))
end

-- do one step to reach position
function moveToPosition(x,y,z)
    selfMoveTo(x, y, z)
end

-- do one step to reach creature
function moveToCreature(id)
    if id == 0 or id == nil then
        selfGotoIdle()
    end
    tx,ty,tz=creatureGetPosition(id)
    if tx == nil then
        selfGotoIdle()
    else
       moveToPosition(tx, ty, tz)
   end
end

-- stop talking
function selfGotoIdle()
    following = false
    attacking = false
    selfAttackCreature(0)
    target = 0
end

-- getCount function by Jiddo
function getCount(msg)
    b, e = string.find(msg, "%d+")
  
    if b == nil or e == nil then
        count = 1
    else
        count = tonumber(string.sub(msg, b, e))
    end
  
    if count > 2000 then
        count = 2000
    elseif count == 0 then
        count = 1
    end
  
    return count
end

-- buy an item
function buy(cid, itemid, count, cost)
    cost = count*cost
    amount = count
    if doPlayerRemoveMoney(cid, cost) == 1 then
        if getItemStackable(itemid) then
            while count > 100 do
                doPlayerAddItem(cid, itemid, 100)
                count = count - 100
            end
          
            doPlayerAddItem(cid, itemid, count) -- add the last items, if there is left
        else
            while count > 0 do
                doPlayerAddItem(cid, itemid, 1)
                count = count - 1
            end
        end
      
        if amount <= 1 then
            selfSay('Here is your '.. getItemName(itemid) .. '!')
        else
            selfSay('Here are your '.. amount ..' '.. getItemName(itemid) .. 's!')      
        end
    else
        selfSay('Sorry, you do not have enough money.')
    end
end

function buyFluidContainer(cid, itemid, count, cost, fluidtype)
    cost = count*cost
    amount = count
    if doPlayerRemoveMoney(cid, cost) == 1 then
        while count > 0 do
            doPlayerAddItem(cid, itemid, fluidtype)
            count = count - 1
        end
      
        if amount <= 1 then
            selfSay('Here is your '.. getItemName(itemid) .. '!')
        else
            selfSay('Here are your '.. amount ..' '.. getItemName(itemid) .. 's!')      
        end
    else
        selfSay('Sorry, you do not have enough money.')
    end
end

function buyContainer(cid, container, itemid, count, money)
    if doPlayerRemoveMoney(cid, money) == 1 then
        bp = doPlayerAddItem(cid, container, 1)
        x = 0
      
        while x < 20 do
            doAddContainerItem(bp, itemid, count)
            x = x + 1
        end
      
        selfSay('Here you are.')
    else
        selfSay('Sorry, you don\'t have enough money.')
    end
end

-- sell an item
function sell(cid, itemid, count, cost)
    cost = count*cost
    if doPlayerRemoveItem(cid, itemid, count) == 1 then
        doPlayerAddMoney(cid, cost)
      
        if cost > 0 then
            selfSay('You couldn\'t retrieve '.. cost ..' gold pieces, please contact the admin.')
        end
      
        if count <= 1 then
            selfSay('Thanks for this '.. getItemName(itemid) .. '!')
        else
            selfSay('Thanks for these '.. count..' '.. getItemName(itemid) .. 's!')      
        end
    else
        selfSay('Sorry, you do not have this item.')
    end
end

-- pay for anything?
function pay(cid, cost)
    if doPlayerRemoveMoney(cid, cost) == 1 then
        return true
    else
        return false
    end
end

-- learn spell
function learnSpell(cid, spell, cost)
    x,y,z = creatureGetPosition(cid)
    if doPlayerLearnSpell(cid, spell) == 1 then
        if doPlayerRemoveMoney(cid, cost) == 1 then
            doSendMagicEffect({x=x, y=y, z=z}, 14)
            selfSay('To use it say: '.. spell ..'.')
        else
            selfSay('Sorry, you do not have this item.')
        end
    else
        selfSay('You already know this spell.')
    end
end

-- Travel player
function travel(cid, x, y, z)
    destpos = {x = x, y = y, z = z}
    doTeleportThing(cid, destpos)
    doSendMagicEffect(destpos, 10)
end

-- add all addons
function addon(cid, addon)
    if getPlayerSex(cid) == 1 then
        for x = 128, 134 do
            doPlayerAddAddon(cid, x, addon)
        end

        for y = 143, 146 do
            doPlayerAddAddon(cid, y, addon)
        end
      
        for z = 151, 154 do
            doPlayerAddAddon(cid, z, addon)
        end
    else  
        for x = 136, 142 do
            doPlayerAddAddon(cid, x, addon)
        end

        for y = 147, 150 do
            doPlayerAddAddon(cid, y, addon)
        end
      
        for z = 155, 158 do
            doPlayerAddAddon(cid, z, addon)
        end
    end
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

You should never do that, either upload all of the files or none.
Its VERY rare that they only change one thing when updating stuff, so what you would do now is probbly give him another error while maybe fixing the old one.
 
You should never do that, either upload all of the files or none.
Its VERY rare that they only change one thing when updating stuff, so what you would do now is probbly give him another error while maybe fixing the old one.

yea but who knows haha maybe he deleted the file by accident

tell us which tfs are you using
 
yea but who knows haha maybe he deleted the file by accident

tell us which tfs are you using

Just that you have to ask in that case what tfs he is using is another thing, by you just uploading your script can cause other bugs, tell him where he can find the older tfs revs and how to download them.
 
Back
Top