• 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 attempt to index field `?' (a nil value)

Devlinn

Member
Joined
Mar 25, 2015
Messages
295
Reaction score
6
hello i have error when i say a,v,c,bv, g, etc
attempt to index field `?' (a nil value)

Code:
function onCreatureSay(cid, type, msg)
      msg = string.lower(msg)
    runeLocator = 0
  
      if (msgcontains(msg, 'hi') and (not isFocused(cid))) and getDistanceToCreature(cid) < 4 then
          selfSay('Hello ' .. creatureGetName(cid) .. '! I am a special rune seller. I sell "runes" in backpacks. Feel free to ask me about "runes\".',cid)
          addFocus(cid)
          talk_start = os.clock()

              elseif msgcontains(msg, 'runes') and isFandD(cid, 4) then
                   msg = "I sell runes in backpacks. Just say "
                   for i=1,getnTable(containerProducts) do
                       if i == getnTable(containerProducts) - 1 then
                           ends = " and "
                       elseif i == getnTable(containerProducts) then
                           ends = "."
                       else
                           ends = ", "
                       end
                       msg = msg.."\'bp "..containerProducts[i].name.."\' - ("..((containerProducts[i].pricePerOneRune*containerProducts[i].amountInOneRune*20)/10000).."cc)"..ends
                   end

                     selfSay(msg,cid)

      elseif isFandD(cid, 4) then
        --talk_start = os.clock()
          
            if msgcontains(msg, "bp") then
                for i=1,getnTable(containerProducts) do
                    if msgcontains(msg, containerProducts[i].name) then
                        runeLocator = i
                        break
                    end
                end      
      
          
        elseif msgcontains(msg, 'bye') and isFandD(cid, 4) and getDistanceToCreature(cid) < 4 then
            selfSay('Good bye, ' .. creatureGetName(cid) .. '!',cid)
            removeFocus(cid)
            talk_start = 0
                        move = true
        end
      
        if runeLocator == 0 and msgcontains(msg, "bp") then
            selfSay('lol u mad?',cid)
        else  
            BuyContainer(cid,containerProducts[runeLocator].runeId,containerProducts[runeLocator].amountInOneRune,(containerProducts[runeLocator].pricePerOneRune*containerProducts[runeLocator].amountInOneRune*20),containerProducts[runeLocator].bpId,1)
        end
      end
end
 
Last edited:
What is the purpose of this function?
Code:
function getnTable (t)
  if type(t.n) == "number" then return t.n end
  local max = 0
  for i, _ in t do
    if type(i) == "number" and i > max then max = i end
  end
  return max
end
 
Code:
focuses = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
target = 0
following = false
attacking = false
focus2 = 0
move = true

local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end

local function addFocus(cid)
    if(not isFocused(cid)) then
        for i, v in pairs(focuses) do
            if(v == 0)then
                focuses[i] = cid
                break
            end
        end  
    end
end

local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            focuses[i] = 0
            break
        end
    end
end

local function isFandD(cid, dist)
        if(isFocused(cid) and getDistanceToCreature(cid) < dist)then
            return true
        end
    return false
end

local runes = {
    ["uh"] = {runeId = 2273, bpId = 3940, pricePerOneRune = 100, amountInOneRune = 100}, -- uh
    ["sd"] = {runeId = 2268, bpId = 2003, pricePerOneRune = 50, amountInOneRune = 100},  -- sd
    ["mwall"] = {runeId = 2293, bpId = 1999, pricePerOneRune = 25, amountInOneRune = 100},  -- magwall
    ["blank"] = {runeId = 2260, bpId = 1998, pricePerOneRune = 1, amountInOneRune = 100},  -- blank
    ["gfb"] = {runeId = 2304, bpId = 2000, pricePerOneRune = 25, amountInOneRune = 100} , -- gfb
    ["manarune"] = {runeId = 2314, bpId = 3940, pricePerOneRune = 1800, amountInOneRune = 100},  -- manarune
    ["explo"] = {runeId = 2313, bpId = 2001, pricePerOneRune = 25, amountInOneRune = 100},  -- explo
    ["hmm"] = {runeId = 2311, bpId = 2001, pricePerOneRune = 25, amountInOneRune = 100}  -- hmm
}
                      
function onThingMove(creature, thing, oldpos, oldstackpos)
end

function onCreatureAppear(creature)
end

function onCreatureDisappear(cid, pos)
    if(isFocused(cid)) then
        selfSay('Good bye then.', cid)
        removeFocus(cid)
    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)
    runeLocator = 0
  
      if (msgcontains(msg, 'hi') and (not isFocused(cid))) and getDistanceToCreature(cid) < 4 then
          selfSay('Hello ' .. creatureGetName(cid) .. '! I am a special rune seller. I sell "runes" in backpacks. Feel free to ask me about "runes".',cid)
          addFocus(cid)
          talk_start = os.clock()
    elseif msgcontains(msg, 'runes') and isFandD(cid, 4) then
        msg = "I sell runes in backpacks of "
        for name in pairs(runes) do
            msg = msg..name..", "
        end
        msg = msg:sub(1, #msg - 2)..'.'
        selfSay(msg, cid)
      elseif isFandD(cid, 4) then
        --talk_start = os.clock()
        if msgcontains(msg, "bp") then
            for name in pairs(runes) do
                if msgcontains(msg, name) and runes[name] ~= nil then
                    runeLocator = name
                    break
                end
            end      
        elseif msgcontains(msg, 'bye') and isFandD(cid, 4) and getDistanceToCreature(cid) < 4 then
            selfSay('Good bye, ' .. creatureGetName(cid) .. '!',cid)
            removeFocus(cid)
            talk_start = 0
            move = true
        end
          
        if runeLocator == 0 and msgcontains(msg, "bp") then
            selfSay('lol u mad?',cid)
        else  
            BuyContainer(cid, runes[runeLocator].runeId, runes[runeLocator].amountInOneRune, (runes[runeLocator].pricePerOneRune * runes[runeLocator].amountInOneRune * 20), runes[runeLocator].bpId, 1)
        end
      end
end

function onCreatureChangeOutfit(creature)
end

function onThink()
    randmove = math.random(1,20)

    for i, focus in pairs(focuses) do
    if(focus > 0)then
        focus2 = focus
        move = false
    end
    if(focus ~= 0)then
        if getDistanceToCreature(focus) > 5 then
            selfSay('Good bye then.', focus)
            removeFocus(focus)
            move = true
        end
    end
    end
    if(focus2 == 0 or move)then
        cx, cy, cz = selfGetPosition()
            if randmove == 1 then
                nx = cx + 1
            end
            if randmove == 2 then
                nx = cx - 1
            end
            if randmove == 3 then
                ny = cy + 1
            end
            if randmove == 4 then
                ny = cy - 1
            end
            if randmove >= 5 then
                nx = cx
                ny = cy
            end
        moveToPosition(nx, ny, cz)
    end
end
 
Code:
focuses = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
target = 0
following = false
attacking = false
focus2 = 0
move = true

local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end

local function addFocus(cid)
    if(not isFocused(cid)) then
        for i, v in pairs(focuses) do
            if(v == 0)then
                focuses[i] = cid
                break
            end
        end 
    end
end

local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            focuses[i] = 0
            break
        end
    end
end

local function isFandD(cid, dist)
        if(isFocused(cid) and getDistanceToCreature(cid) < dist)then
            return true
        end
    return false
end

local runes = {
    ["uh"] = {runeId = 2273, bpId = 3940, pricePerOneRune = 100, amountInOneRune = 100}, -- uh
    ["sd"] = {runeId = 2268, bpId = 2003, pricePerOneRune = 50, amountInOneRune = 100},  -- sd
    ["mwall"] = {runeId = 2293, bpId = 1999, pricePerOneRune = 25, amountInOneRune = 100},  -- magwall
    ["blank"] = {runeId = 2260, bpId = 1998, pricePerOneRune = 1, amountInOneRune = 100},  -- blank
    ["gfb"] = {runeId = 2304, bpId = 2000, pricePerOneRune = 25, amountInOneRune = 100} , -- gfb
    ["manarune"] = {runeId = 2314, bpId = 3940, pricePerOneRune = 1800, amountInOneRune = 100},  -- manarune
    ["explo"] = {runeId = 2313, bpId = 2001, pricePerOneRune = 25, amountInOneRune = 100},  -- explo
    ["hmm"] = {runeId = 2311, bpId = 2001, pricePerOneRune = 25, amountInOneRune = 100}  -- hmm
}
                     
function onThingMove(creature, thing, oldpos, oldstackpos)
end

function onCreatureAppear(creature)
end

function onCreatureDisappear(cid, pos)
    if(isFocused(cid)) then
        selfSay('Good bye then.', cid)
        removeFocus(cid)
    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)
    runeLocator = 0
 
      if (msgcontains(msg, 'hi') and (not isFocused(cid))) and getDistanceToCreature(cid) < 4 then
          selfSay('Hello ' .. creatureGetName(cid) .. '! I am a special rune seller. I sell "runes" in backpacks. Feel free to ask me about "runes".',cid)
          addFocus(cid)
          talk_start = os.clock()
    elseif msgcontains(msg, 'runes') and isFandD(cid, 4) then
        msg = "I sell runes in backpacks of "
        for name in pairs(runes) do
            msg = msg..name..", "
        end
        msg = msg:sub(1, #msg - 2)..'.'
        selfSay(msg, cid)
      elseif isFandD(cid, 4) then
        --talk_start = os.clock()
        if msgcontains(msg, "bp") then
            for name in pairs(runes) do
                if msgcontains(msg, name) and runes[name] ~= nil then
                    runeLocator = name
                    break
                end
            end     
        elseif msgcontains(msg, 'bye') and isFandD(cid, 4) and getDistanceToCreature(cid) < 4 then
            selfSay('Good bye, ' .. creatureGetName(cid) .. '!',cid)
            removeFocus(cid)
            talk_start = 0
            move = true
        end
         
        if runeLocator == 0 and msgcontains(msg, "bp") then
            selfSay('lol u mad?',cid)
        else 
            BuyContainer(cid, runes[runeLocator].runeId, runes[runeLocator].amountInOneRune, (runes[runeLocator].pricePerOneRune * runes[runeLocator].amountInOneRune * 20), runes[runeLocator].bpId, 1)
        end
      end
end

function onCreatureChangeOutfit(creature)
end

function onThink()
    randmove = math.random(1,20)

    for i, focus in pairs(focuses) do
    if(focus > 0)then
        focus2 = focus
        move = false
    end
    if(focus ~= 0)then
        if getDistanceToCreature(focus) > 5 then
            selfSay('Good bye then.', focus)
            removeFocus(focus)
            move = true
        end
    end
    end
    if(focus2 == 0 or move)then
        cx, cy, cz = selfGetPosition()
            if randmove == 1 then
                nx = cx + 1
            end
            if randmove == 2 then
                nx = cx - 1
            end
            if randmove == 3 then
                ny = cy + 1
            end
            if randmove == 4 then
                ny = cy - 1
            end
            if randmove >= 5 then
                nx = cx
                ny = cy
            end
        moveToPosition(nx, ny, cz)
    end
end
dont work many error
NpcScript onThink: lua error:attempt to call a nil value backtrace and etc
error '#'
 
Back
Top