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

Lua Npc are not responding, 0.3.7

niti

New Member
Joined
Nov 22, 2009
Messages
258
Reaction score
2
Hello all. I'm using TFS 0.3.7, and the npc:S are not responding to me when I say Hi, What's wrong?

[21:36:07.926] [Error - NpcScript Interface]
[21:36:07.926] data/npc/scripts/runes.lua:eek:nCreatureSay
[21:36:07.926] Description:
[21:36:07.926] data/npc/lib/npc.lua:51: attempt to call global 'isValidPosition' (a nil value)
[21:36:07.926] stack traceback:
[21:36:07.926] data/npc/lib/npc.lua:51: in function 'getNpcDistanceTo'
[21:36:07.926] data/npc/lib/npcsystem/npchandler.lua:631: in function 'isInRange'
[21:36:07.926] data/npc/lib/npcsystem/npchandler.lua:446: in function 'onCreatureSay'
[21:36:07.926] data/npc/scripts/runes.lua:8: in function <data/npc/scripts/runes.lua:8>
This is the respond in the Distro. What should I do?

bump
 
Last edited by a moderator:
attempt to call global 'isValidPosition' (a nil value)
Anytime you see a nil value for a function that usually means the function doesn't exist. In this case that function is: isValidPosition(position)

Add this function to your 032-position.lua lib:

Code:
function isValidPosition(position)
    return (isNumeric(position.x .. position.y .. position.z) and position.x > 0
        and position.y > 0 and position.z >= 0 and position.z <= 15)
end

Also if you continue to run into missing functions then maybe you need to update your libraries.
 
Anytime you see a nil value for a function that usually means the function doesn't exist. In this case that function is: isValidPosition(position)

Add this function to your 032-position.lua lib:

Code:
function isValidPosition(position)
    return (isNumeric(position.x .. position.y .. position.z) and position.x > 0
        and position.y > 0 and position.z >= 0 and position.z <= 15)
end

Also if you continue to run into missing functions then maybe you need to update your libraries.
Hi, could you edit it to my script? Would be helpful since I dunno how to do it.


Code:
function isInRange(position, fromPosition, toPosition)
    return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end

function getDistanceBetween(fromPosition, toPosition)
    local x, y = math.abs(fromPosition.x - toPosition.x), math.abs(fromPosition.y - toPosition.y)
    local diff = math.max(x, y)
    if(fromPosition.z ~= toPosition.z) then
        diff = diff + 9 + 6
    end

    return diff
end

function getDirectionTo(pos1, pos2)
    local dir = NORTH
    if(pos1.x > pos2.x) then
        dir = WEST
        if(pos1.y > pos2.y) then
            dir = NORTHWEST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHWEST
        end
    elseif(pos1.x < pos2.x) then
        dir = EAST
        if(pos1.y > pos2.y) then
            dir = NORTHEAST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHEAST
        end
    else
        if(pos1.y > pos2.y) then
            dir = NORTH
        elseif(pos1.y < pos2.y) then
            dir = SOUTH
        end
    end

    return dir
end

function getCreatureLookPosition(cid)
    return getPosByDir(getThingPos(cid), getCreatureLookDirection(cid))
end

function getPositionByDirection(position, direction, size)
    local n = size or 1
    if(direction == NORTH) then
        position.y = position.y - n
    elseif(direction == SOUTH) then
        position.y = position.y + n
    elseif(direction == WEST) then
        position.x = position.x - n
    elseif(direction == EAST) then
        position.x = position.x + n
    elseif(direction == NORTHWEST) then
        position.y = position.y - n
        position.x = position.x - n
    elseif(direction == NORTHEAST) then
        position.y = position.y - n
        position.x = position.x + n
    elseif(direction == SOUTHWEST) then
        position.y = position.y + n
        position.x = position.x - n
    elseif(direction == SOUTHEAST) then
        position.y = position.y + n
        position.x = position.x + n
    end

    return position
end

function doComparePositions(position, positionEx)
    return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
end

function getArea(position, x, y)
    local t = {}
    for i = (position.x - x), (position.x + x) do
        for j = (position.y - y), (position.y + y) do
            table.insert(t, {x = i, y = j, z = position.z})
        end
    end

    return t
end
 
Hi, could you edit it to my script? Would be helpful since I dunno how to do it.


Code:
function isInRange(position, fromPosition, toPosition)
    return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end

function getDistanceBetween(fromPosition, toPosition)
    local x, y = math.abs(fromPosition.x - toPosition.x), math.abs(fromPosition.y - toPosition.y)
    local diff = math.max(x, y)
    if(fromPosition.z ~= toPosition.z) then
        diff = diff + 9 + 6
    end

    return diff
end

function getDirectionTo(pos1, pos2)
    local dir = NORTH
    if(pos1.x > pos2.x) then
        dir = WEST
        if(pos1.y > pos2.y) then
            dir = NORTHWEST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHWEST
        end
    elseif(pos1.x < pos2.x) then
        dir = EAST
        if(pos1.y > pos2.y) then
            dir = NORTHEAST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHEAST
        end
    else
        if(pos1.y > pos2.y) then
            dir = NORTH
        elseif(pos1.y < pos2.y) then
            dir = SOUTH
        end
    end

    return dir
end

function getCreatureLookPosition(cid)
    return getPosByDir(getThingPos(cid), getCreatureLookDirection(cid))
end

function getPositionByDirection(position, direction, size)
    local n = size or 1
    if(direction == NORTH) then
        position.y = position.y - n
    elseif(direction == SOUTH) then
        position.y = position.y + n
    elseif(direction == WEST) then
        position.x = position.x - n
    elseif(direction == EAST) then
        position.x = position.x + n
    elseif(direction == NORTHWEST) then
        position.y = position.y - n
        position.x = position.x - n
    elseif(direction == NORTHEAST) then
        position.y = position.y - n
        position.x = position.x + n
    elseif(direction == SOUTHWEST) then
        position.y = position.y + n
        position.x = position.x - n
    elseif(direction == SOUTHEAST) then
        position.y = position.y + n
        position.x = position.x + n
    end

    return position
end

function doComparePositions(position, positionEx)
    return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
end

function getArea(position, x, y)
    local t = {}
    for i = (position.x - x), (position.x + x) do
        for j = (position.y - y), (position.y + y) do
            table.insert(t, {x = i, y = j, z = position.z})
        end
    end

    return t
end
Your script is fine. Update your library in data/lib/ as instructed.
If we edit your script, then you'll have to patch every script that wants to use this function.
 
Your script is fine. Update your library in data/lib/ as instructed.
If we edit your script, then you'll have to patch every script that wants to use this function.
Thanks for helping me, but what should I edit there? and where in LIB what lua should I ediT?
 
Thanks for helping me, but what should I edit there? and where in LIB what lua should I ediT?
Anytime you see a nil value for a function that usually means the function doesn't exist. In this case that function is: isValidPosition(position)

Add this function to your 032-position.lua lib:

Code:
function isValidPosition(position)
    return (isNumeric(position.x .. position.y .. position.z) and position.x > 0
        and position.y > 0 and position.z >= 0 and position.z <= 15)
end

Also if you continue to run into missing functions then maybe you need to update your libraries.
 
Hi! I just did what you told me to now this came up,


Code:
[12:40:17.957] [Error - NpcScript Interface]
[12:40:17.957] data/npc/scripts/default.lua:onCreatureSay
[12:40:17.957] Description:
[12:40:17.957] data/lib/032-position.lua:78: attempt to call global 'isNumeric' (a nil value                        )
[12:40:17.957] stack traceback:
[12:40:17.957]  data/lib/032-position.lua:78: in function 'isValidPosition'
[12:40:17.957]  data/npc/lib/npc.lua:51: in function 'getNpcDistanceTo'
[12:40:17.957]  data/npc/lib/npcsystem/npchandler.lua:631: in function 'isInRange'
[12:40:17.957]  data/npc/lib/npcsystem/npchandler.lua:446: in function 'onCreatureSay'
[12:40:17.957]  data/npc/scripts/default.lua:7: in function <data/npc/scripts/default.lua:7>
And this is how I added the script that you told me to add:
Data/lib/032-position.lua:

Code:
function isInRange(position, fromPosition, toPosition)
    return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end

function getDistanceBetween(fromPosition, toPosition)
    local x, y = math.abs(fromPosition.x - toPosition.x), math.abs(fromPosition.y - toPosition.y)
    local diff = math.max(x, y)
    if(fromPosition.z ~= toPosition.z) then
        diff = diff + 9 + 6
    end

    return diff
end

function getDirectionTo(pos1, pos2)
    local dir = NORTH
    if(pos1.x > pos2.x) then
        dir = WEST
        if(pos1.y > pos2.y) then
            dir = NORTHWEST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHWEST
        end
    elseif(pos1.x < pos2.x) then
        dir = EAST
        if(pos1.y > pos2.y) then
            dir = NORTHEAST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHEAST
        end
    else
        if(pos1.y > pos2.y) then
            dir = NORTH
        elseif(pos1.y < pos2.y) then
            dir = SOUTH
        end
    end

    return dir
end

function getCreatureLookPosition(cid)
    return getPosByDir(getThingPos(cid), getCreatureLookDirection(cid))
end

function getPositionByDirection(position, direction, size)
    local n = size or 1
    if(direction == NORTH) then
        position.y = position.y - n
    elseif(direction == SOUTH) then
        position.y = position.y + n
    elseif(direction == WEST) then
        position.x = position.x - n
    elseif(direction == EAST) then
        position.x = position.x + n
    elseif(direction == NORTHWEST) then
        position.y = position.y - n
        position.x = position.x - n
    elseif(direction == NORTHEAST) then
        position.y = position.y - n
        position.x = position.x + n
    elseif(direction == SOUTHWEST) then
        position.y = position.y + n
        position.x = position.x - n
    elseif(direction == SOUTHEAST) then
        position.y = position.y + n
        position.x = position.x + n
    end

    return position
end

function doComparePositions(position, positionEx)
    return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
end

function isValidPosition(position)
    return (isNumeric(position.x .. position.y .. position.z) and position.x > 0
        and position.y > 0 and position.z >= 0 and position.z <= 15)
end

function getArea(position, x, y)
    local t = {}
    for i = (position.x - x), (position.x + x) do
        for j = (position.y - y), (position.y + y) do
            table.insert(t, {x = i, y = j, z = position.z})
        end
    end

    return t
end
I dunno if it's right, but yea check it out^^
 
You just have to find the correct name of the function in your files. A function in a code is a reference to another .cpp file (depending on language) that has another code on it. You just need to find the correct name of the file, if missing replace it.
 
Back
Top Bottom