Ir para conteúdo
  • 0

Spring Trap

Pergunta

Galera sera q alguem pode me ajudar? estou tendo problemas com alguns npcs do meu servidor. Eles funciona normal mais quando eu falo HI e vou pra bem longe sem falar bye eles ainda fica como se tivesse falando comigo, quando eu volto eles ainda estao esperando respostas de mim. 

 

E na distro fica varias vezes repetindo o mesmo erro

 

ERRO:

Spoiler

[Error - NpcScript Interface] 
data/npc/scripts/mayor2.lua:onThink
Description: 
data/npc/scripts/mayor2.lua:92: attempt to compare number with nil
stack traceback:
data/npc/scripts/mayor2.lua:92: in function <data/npc/scripts/mayor2.lua:83>

 

Script mayor2:

Spoiler

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') then

selfSay('Hey Can you give me 1 Bandit King Hood?.')    
          focus = cid
          talk_start = os.clock()

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

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

                        if msgcontains(msg, 'yes') then
            if getPlayerStorageValue(cid,6004) == 1 then
            
        selfSay('Sorry You Cant Do this quest.')    
            elseif msgcontains(msg, 'yes') then
                       if doPlayerRemoveItem(cid,5879,1) == 0 then
                       selfSay('Sorry Dont have that items.')    

else        
                if doPlayerAddItem(cid,5919,1) then
                
                    setPlayerStorageValue(cid,6004,1)
                                    selfSay('Thanks take this')
                    focus = 0
                    talk_start = 0

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

end
function onThink()
    doNpcSetCreatureFocus(focus)
      if (os.clock() - talk_start) > 45 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
 

 

Tem varios npc igual a esse que da esse erro na distro tem um parecido mais nao da, e esta a mesma coisa

 

Esse nao da erro:

Spoiler

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('Hey!.')
          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 and getCreatureCondition(cid, CONDITION_INFIGHT) == false then
        
            selfSay('I see you want to fight with me, But not in the town???')
            focus = cid
            talk_start = os.clock()
        

      elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
          selfSay('Sorry, ' .. getCreatureName(cid) .. '! ????????.')

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

            if msgcontains(msg, 'yes') then
                if getPlayerStorageValue(cid,8000) == 16 then
                    doTeleportThing(cid, { x=46, y=553, z=7})
                    selfSay('Yes!')
                    focus = 0
                    talk_start = 0
                else
                    selfSay('Sorry You Cant Do this saga.')
                end

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

function onThink()
    doNpcSetCreatureFocus(focus)
      if (os.clock() - talk_start) > 45 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
 

 

Rep + pra quem ajudar

@Danihcv @dalvorsn @Yan Liima

Editado por Spring Trap
Link para o comentário
Compartilhar em outros sites

Posts Recomendados

  • 0
12 horas atrás, Danihcv disse:

@Spring Trap, como que tá os arquivos .xml desses npcs?

 

Todos estão do mesmo jeito so muda o nome e a looktype

<npc name="Mayor" script="data/npc/scripts/mayor2.lua" walkinterval="2000" floorchange="0" access="5" level="1" maglevel="1">
    <health now="150" max="150"/>
    <look type="314" head="132" body="79" legs="97" feet="132" corpse="2212"/>
</npc>

 

Editado por Spring Trap
Link para o comentário
Compartilhar em outros sites

  • 0
local focus = 0local talk_start = 0local target = 0local following = falselocal attacking = falsefunction onThingMove(creature, thing, oldpos, oldstackpos)endfunction onCreatureAppear(creature)endfunction onCreatureDisappear(cid, pos)      if focus == cid then          selfSay('Good bye then.')          focus = 0          talk_start = 0      endendfunction onCreatureTurn(creature)endfunction msgcontains(txt, str)      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))endfunction onCreatureSay(cid, type, msg)      msg = string.lower(msg)    if msgcontains(msg, 'hi') then	selfSay('Hey Can you give me 1 Bandit King Hood?.')              focus = cid          talk_start = os.clock()      elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then          selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk to you in a minute.')    elseif focus == cid then        talk_start = os.clock()	if msgcontains(msg, 'yes') then        if getPlayerStorageValue(cid,6004) >= 1 then        selfSay('Sorry You Cant Do this quest.') return true            elseif not doPlayerRemoveItem(cid, 5879, 1) then        selfSay('Sorry Dont have that items.') return true    	end         doPlayerAddItem(cid,5919,1)         setPlayerStorageValue(cid,6004,1)         selfSay('Thanks take this')         focus = 0         talk_start = 0end     elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then            selfSay('Good bye, ' .. getCreatureName(cid) .. '!')            focus = 0            talk_start = 0        endendfunction onThink()    doNpcSetCreatureFocus(focus)      if (os.clock() - talk_start) > 45 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     endend

 

Link para o comentário
Compartilhar em outros sites

  • 0
40 minutos atrás, Mendiguinho91 disse:
local focus = 0local talk_start = 0local target = 0local following = falselocal attacking = falsefunction onThingMove(creature, thing, oldpos, oldstackpos)endfunction onCreatureAppear(creature)endfunction onCreatureDisappear(cid, pos)      if focus == cid then          selfSay('Good bye then.')          focus = 0          talk_start = 0      endendfunction onCreatureTurn(creature)endfunction msgcontains(txt, str)      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))endfunction onCreatureSay(cid, type, msg)      msg = string.lower(msg)    if msgcontains(msg, 'hi') then	selfSay('Hey Can you give me 1 Bandit King Hood?.')              focus = cid          talk_start = os.clock()      elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then          selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk to you in a minute.')    elseif focus == cid then        talk_start = os.clock()	if msgcontains(msg, 'yes') then        if getPlayerStorageValue(cid,6004) >= 1 then        selfSay('Sorry You Cant Do this quest.') return true            elseif not doPlayerRemoveItem(cid, 5879, 1) then        selfSay('Sorry Dont have that items.') return true    	end         doPlayerAddItem(cid,5919,1)         setPlayerStorageValue(cid,6004,1)         selfSay('Thanks take this')         focus = 0         talk_start = 0end     elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then            selfSay('Good bye, ' .. getCreatureName(cid) .. '!')            focus = 0            talk_start = 0        endendfunction onThink()    doNpcSetCreatureFocus(focus)      if (os.clock() - talk_start) > 45 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     endend

 

 

Continua com o mesmo erro so que em outra linha

[Error - NpcScript Interface] data/npc/scripts/mayor2.lua:onThinkDescription: ata/npc/scripts/mayor2.lua:64: attempt to compare number with nilstack traceback:data/npc/scripts/mayor2.lua:64: in function <data/npc/scripts/mayor2.lua:55>

E nao tem como dar bye mais

 

O erro sempre causava quando o personagem nao dava BYE e ia pra bem longe. creio que seja erro de distance

Link para o comentário
Compartilhar em outros sites

  • 0

Gente eu descobri qual é o motivo do erro, na verdade todos os npcs igual a este estão dando erro, até o que eu disse q nao estava

Ele funciona normal se tu falar com o npc e tals e ir embora sem falar bye. O problema é que se você falar HI e ir em bora para outra posição Z ele vai fica dando erro na distro

até o jogador estiver na posição Z que o npc esta ai o npc irá dar good bye automaticamente

 

Achei que o outro npc nao estava dando erro porque ele fica na posição Z: 7 e nao tem escadas por perto para subir o solo e descer, já o mayor tinha por isso dava erro

 

Meu npc.lua

Spoiler

function selfIdle()
    following = false
    attacking = false

    selfAttackCreature(0)
    target = 0
end

function selfSayChannel(cid, message)
    return selfSay(message, cid, false)
end

function selfMoveToCreature(id)
    if(not id or id == 0) then
        return
    end

    local t = getCreaturePosition(id)
    if(not t.x or t.x == nil) then
        return
    end

    selfMoveTo(t.x, t.y, t.z)
    return
end

function getNpcDistanceToCreature(id)
    if(not id or id == 0) then
        selfIdle()
        return nil
    end

    local c = getCreaturePosition(id)
    if(not c.x or c.x == 0) then
        return nil
    end

    local s = getCreaturePosition(getNpcId())
    if(not s.x or s.x == 0 or s.z ~= c.z) then
        return nil
    end

    return math.max(math.abs(s.x - c.x), math.abs(s.y - c.y))
end

function doMessageCheck(message, keyword)
    if(type(keyword) == "table") then
        return table.isStrIn(keyword, message)
    end

    local a, b = message:lower():find(keyword:lower())
    if(a ~= nil and b ~= nil) then
        return true
    end

    return false
end

function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
    local amount = amount or 1
    local subType = subType or 1
    local ignoreCap = ignoreCap and true or false

    local item = 0
    if(isItemStackable(itemid)) then
        if(isItemRune(itemid)) then
            amount = amount * subType
        end

        local count = amount
        repeat
            item = doCreateItemEx(itemid, math.min(100, count))
            if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
                return 0, 0
            end

            count = count - math.min(100, count)
        until count == 0
        return amount, 0
    end

    local a = 0
    if(inBackpacks) then
        local container = doCreateItemEx(backpack, 1)
        local b = 1
        for i = 1, amount do
            item = doAddContainerItem(container, itemid, subType)
            if(itemid == ITEM_PARCEL) then
                doAddContainerItem(item, ITEM_LABEL)
            end

            if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
                if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
                    b = b - 1
                    break
                end

                a = i
                if(amount > i) then
                    container = doCreateItemEx(backpack, 1)
                    b = b + 1
                end
            end
        end

        return a, b
    end

    for i = 1, amount do
        item = doCreateItemEx(itemid, subType)
        if(itemid == ITEM_PARCEL) then
            doAddContainerItem(item, ITEM_LABEL)
        end

        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
            break
        end

        a = i
    end

    return a, 0
end

function doRemoveItemIdFromPos(id, n, position)
    local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})
    if(thing.itemid ~= id) then
        return false
    end

    doRemoveItem(thing.uid, n)
    return true
end

function getNpcName()
    return getCreatureName(getNpcId())
end

function getNpcPos()
    return getCreaturePosition(getNpcId())
end

function selfGetPosition()
    local t = getNpcPos()
    return t.x, t.y, t.z
end

msgcontains = doMessageCheck
moveToPosition = selfMoveTo
moveToCreature = selfMoveToCreature
selfMoveToPosition = selfMoveTo
selfGotoIdle = selfIdle
isPlayerPremiumCallback = isPremium
doPosRemoveItem = doRemoveItemIdFromPos
doNpcBuyItem = doPlayerRemoveItem
doNpcSetCreatureFocus = selfFocus
getNpcCid = getNpcId
getDistanceTo = getNpcDistanceTo
getDistanceToCreature = getNpcDistanceToCreature
 

 

Um amigo meu disse pra mim tentar adaptar essa função:

function getDistanceToCreature(id)	if id == 0 or id == nil then		selfGotoIdle()	end	cx, cy, cz = getCreaturePosition(id)	if cx == nil then		return nil	end	sx, sy, sz = selfGetPosition()	return math.max(math.abs(sx-cx), math.abs(sy-cy))	end

Alguém pode ajudaaarr por favor nao sei o que fazer :/ 

 

@Danihcv pode ajudar?

Editado por Spring Trap
Link para o comentário
Compartilhar em outros sites

  • 0

@Spring Trap, fiz a adaptação. Vê se resolve:

Spoiler

 function selfIdle()
    following = false
    attacking = false

    selfAttackCreature(0)
    target = 0
end

function selfSayChannel(cid, message)
    return selfSay(message, cid, false)
end

function selfMoveToCreature(id)
    if(not id or id == 0) then
        return
    end

    local t = getCreaturePosition(id)
    if(not t.x or t.x == nil) then
        return
    end

    selfMoveTo(t.x, t.y, t.z)
    return
end

function getNpcDistanceToCreature(id)
	if id == 0 or id == nil then
		selfIdle()
	end

	cx, cy, cz = getCreaturePosition(id)
	if cx == nil then
		return nil
	end
sx, sy, sz = selfGetPosition()
	return math.max(math.abs(sx-cx), math.abs(sy-cy))
end

function doMessageCheck(message, keyword)
    if(type(keyword) == "table") then
        return table.isStrIn(keyword, message)
    end

    local a, b = message:lower():find(keyword:lower())
    if(a ~= nil and b ~= nil) then
        return true
    end

    return false
end

function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
    local amount = amount or 1
    local subType = subType or 1
    local ignoreCap = ignoreCap and true or false

    local item = 0
    if(isItemStackable(itemid)) then
        if(isItemRune(itemid)) then
            amount = amount * subType
        end

        local count = amount
        repeat
            item = doCreateItemEx(itemid, math.min(100, count))
            if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
                return 0, 0
            end

            count = count - math.min(100, count)
        until count == 0
        return amount, 0
    end

    local a = 0
    if(inBackpacks) then
        local container = doCreateItemEx(backpack, 1)
        local b = 1
        for i = 1, amount do
            item = doAddContainerItem(container, itemid, subType)
            if(itemid == ITEM_PARCEL) then
                doAddContainerItem(item, ITEM_LABEL)
            end

            if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
                if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
                    b = b - 1
                    break
                end

                a = i
                if(amount > i) then
                    container = doCreateItemEx(backpack, 1)
                    b = b + 1
                end
            end
        end

        return a, b
    end

    for i = 1, amount do
        item = doCreateItemEx(itemid, subType)
        if(itemid == ITEM_PARCEL) then
            doAddContainerItem(item, ITEM_LABEL)
        end

        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
            break
        end

        a = i
    end

    return a, 0
end

function doRemoveItemIdFromPos(id, n, position)
    local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})
    if(thing.itemid ~= id) then
        return false
    end

    doRemoveItem(thing.uid, n)
    return true
end

function getNpcName()
    return getCreatureName(getNpcId())
end

function getNpcPos()
    return getCreaturePosition(getNpcId())
end

function selfGetPosition()
    local t = getNpcPos()
    return t.x, t.y, t.z
end

msgcontains = doMessageCheck
moveToPosition = selfMoveTo
moveToCreature = selfMoveToCreature
selfMoveToPosition = selfMoveTo
selfGotoIdle = selfIdle
isPlayerPremiumCallback = isPremium
doPosRemoveItem = doRemoveItemIdFromPos
doNpcBuyItem = doPlayerRemoveItem
doNpcSetCreatureFocus = selfFocus
getNpcCid = getNpcId
getDistanceTo = getNpcDistanceTo
getDistanceToCreature = getNpcDistanceToCreature

 

 

Link para o comentário
Compartilhar em outros sites

  • 0
39 minutos atrás, Danihcv disse:

@Spring Trap, fiz a adaptação. Vê se resolve:

  Ocultar conteúdo
 function selfIdle()    following = false    attacking = false    selfAttackCreature(0)    target = 0endfunction selfSayChannel(cid, message)    return selfSay(message, cid, false)endfunction selfMoveToCreature(id)    if(not id or id == 0) then        return    end    local t = getCreaturePosition(id)    if(not t.x or t.x == nil) then        return    end    selfMoveTo(t.x, t.y, t.z)    returnendfunction getNpcDistanceToCreature(id)	if id == 0 or id == nil then		selfIdle()	end	cx, cy, cz = getCreaturePosition(id)	if cx == nil then		return nil	endsx, sy, sz = selfGetPosition()	return math.max(math.abs(sx-cx), math.abs(sy-cy))endfunction doMessageCheck(message, keyword)    if(type(keyword) == "table") then        return table.isStrIn(keyword, message)    end    local a, b = message:lower():find(keyword:lower())    if(a ~= nil and b ~= nil) then        return true    end    return falseendfunction doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)    local amount = amount or 1    local subType = subType or 1    local ignoreCap = ignoreCap and true or false    local item = 0    if(isItemStackable(itemid)) then        if(isItemRune(itemid)) then            amount = amount * subType        end        local count = amount        repeat            item = doCreateItemEx(itemid, math.min(100, count))            if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then                return 0, 0            end            count = count - math.min(100, count)        until count == 0        return amount, 0    end    local a = 0    if(inBackpacks) then        local container = doCreateItemEx(backpack, 1)        local b = 1        for i = 1, amount do            item = doAddContainerItem(container, itemid, subType)            if(itemid == ITEM_PARCEL) then                doAddContainerItem(item, ITEM_LABEL)            end            if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then                if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then                    b = b - 1                    break                end                a = i                if(amount > i) then                    container = doCreateItemEx(backpack, 1)                    b = b + 1                end            end        end        return a, b    end    for i = 1, amount do        item = doCreateItemEx(itemid, subType)        if(itemid == ITEM_PARCEL) then            doAddContainerItem(item, ITEM_LABEL)        end        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then            break        end        a = i    end    return a, 0endfunction doRemoveItemIdFromPos(id, n, position)    local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})    if(thing.itemid ~= id) then        return false    end    doRemoveItem(thing.uid, n)    return trueendfunction getNpcName()    return getCreatureName(getNpcId())endfunction getNpcPos()    return getCreaturePosition(getNpcId())endfunction selfGetPosition()    local t = getNpcPos()    return t.x, t.y, t.zendmsgcontains = doMessageCheckmoveToPosition = selfMoveTomoveToCreature = selfMoveToCreatureselfMoveToPosition = selfMoveToselfGotoIdle = selfIdleisPlayerPremiumCallback = isPremiumdoPosRemoveItem = doRemoveItemIdFromPosdoNpcBuyItem = doPlayerRemoveItemdoNpcSetCreatureFocus = selfFocusgetNpcCid = getNpcIdgetDistanceTo = getNpcDistanceTogetDistanceToCreature = getNpcDistanceToCreature

 

 

 

Deu erro ;/:

agora quando falo HI ele nao diz nada

 

ERRO:

Error - NpcScript Interface] data/npc/scripts/mayor2.lua:onCreatureSayDescription: stack traceback:data/npc/lib/npc.lua:40: in function 'getDistanceToCreature'data/npc/scripts/mayor2.lua:40: in function <data/npc/scripts/mayor2.lua:36>

Tentei trocar a função la do mayor2 de getDistanceToCreature para getNpcDistanceToCreature e deu isso

[Error - NpcScript Interface] data/npc/scripts/mayor2.lua:onCreatureSayDescription: data/npc/lib/npc.lua:40: attempt to perform arithmetic on global 'cx' (a table value)stack traceback:data/npc/lib/npc.lua:40: in function 'getNpcDistanceToCreature'data/npc/scripts/mayor2.lua:40: in function <data/npc/scripts/mayor2.lua:36>

a linha 40 do mayor2 é essa

if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 and getCreatureCondition(cid, CONDITION_INFIGHT) == false then

Troquei por

if msgcontains(msg, 'hi') then

E o npc voltou falar comigo so que deu varios erros na distro:

[Error - NpcScript Interface] data/npc/scripts/mayor2.lua:onThinkDescription: data/npc/lib/npc.lua:40: attempt to perform arithmetic on global 'cx' (a table value)stack traceback:data/npc/lib/npc.lua:40: in function 'getNpcDistanceToCreature'data/npc/scripts/mayor2.lua:85: in function <data/npc/scripts/mayor2.lua:76>

 

Editado por Spring Trap
Link para o comentário
Compartilhar em outros sites

  • 0

O erro tava no código que teu amigo mandou (bem que eu tinha achado uma coisa estranha nele).

Vê se o npc.lua assim funciona:

Spoiler
function selfIdle()    following = false    attacking = false    selfAttackCreature(0)    target = 0endfunction selfSayChannel(cid, message)    return selfSay(message, cid, false)endfunction selfMoveToCreature(id)    if(not id or id == 0) then        return    end    local t = getCreaturePosition(id)    if(not t.x or t.x == nil) then        return    end    selfMoveTo(t.x, t.y, t.z)    returnendfunction getNpcDistanceToCreature(id)	if id == 0 or id == nil then		selfIdle()	end	c = getCreaturePosition(id)	if c == nil then		return nil	end	s = selfGetPosition()	return math.max(math.abs(s.x-c.x), math.abs(s.y-c.y))endfunction doMessageCheck(message, keyword)    if(type(keyword) == "table") then        return table.isStrIn(keyword, message)    end    local a, b = message:lower():find(keyword:lower())    if(a ~= nil and b ~= nil) then        return true    end    return falseendfunction doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)    local amount = amount or 1    local subType = subType or 1    local ignoreCap = ignoreCap and true or false    local item = 0    if(isItemStackable(itemid)) then        if(isItemRune(itemid)) then            amount = amount * subType        end        local count = amount        repeat            item = doCreateItemEx(itemid, math.min(100, count))            if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then                return 0, 0            end            count = count - math.min(100, count)        until count == 0        return amount, 0    end    local a = 0    if(inBackpacks) then        local container = doCreateItemEx(backpack, 1)        local b = 1        for i = 1, amount do            item = doAddContainerItem(container, itemid, subType)            if(itemid == ITEM_PARCEL) then                doAddContainerItem(item, ITEM_LABEL)            end            if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then                if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then                    b = b - 1                    break                end                a = i                if(amount > i) then                    container = doCreateItemEx(backpack, 1)                    b = b + 1                end            end        end        return a, b    end    for i = 1, amount do        item = doCreateItemEx(itemid, subType)        if(itemid == ITEM_PARCEL) then            doAddContainerItem(item, ITEM_LABEL)        end        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then            break        end        a = i    end    return a, 0endfunction doRemoveItemIdFromPos(id, n, position)    local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})    if(thing.itemid ~= id) then        return false    end    doRemoveItem(thing.uid, n)    return trueendfunction getNpcName()    return getCreatureName(getNpcId())endfunction getNpcPos()    return getCreaturePosition(getNpcId())endfunction selfGetPosition()    local t = getNpcPos()    return t.x, t.y, t.zendmsgcontains = doMessageCheckmoveToPosition = selfMoveTomoveToCreature = selfMoveToCreatureselfMoveToPosition = selfMoveToselfGotoIdle = selfIdleisPlayerPremiumCallback = isPremiumdoPosRemoveItem = doRemoveItemIdFromPosdoNpcBuyItem = doPlayerRemoveItemdoNpcSetCreatureFocus = selfFocusgetNpcCid = getNpcIdgetDistanceTo = getNpcDistanceTogetDistanceToCreature = getNpcDistanceToCreature

 

 

Link para o comentário
Compartilhar em outros sites

  • 0
7 minutos atrás, Danihcv disse:

O erro tava no código que teu amigo mandou (bem que eu tinha achado uma coisa estranha nele).

 

Vê se o npc.lua assim funciona:

  Ocultar conteúdo
function selfIdle()    following = false    attacking = false    selfAttackCreature(0)    target = 0endfunction selfSayChannel(cid, message)    return selfSay(message, cid, false)endfunction selfMoveToCreature(id)    if(not id or id == 0) then        return    end    local t = getCreaturePosition(id)    if(not t.x or t.x == nil) then        return    end    selfMoveTo(t.x, t.y, t.z)    returnendfunction getNpcDistanceToCreature(id)	if id == 0 or id == nil then		selfIdle()	end	c = getCreaturePosition(id)	if c == nil then		return nil	end	s = selfGetPosition()	return math.max(math.abs(s.x-c.x), math.abs(s.y-c.y))endfunction doMessageCheck(message, keyword)    if(type(keyword) == "table") then        return table.isStrIn(keyword, message)    end    local a, b = message:lower():find(keyword:lower())    if(a ~= nil and b ~= nil) then        return true    end    return falseendfunction doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)    local amount = amount or 1    local subType = subType or 1    local ignoreCap = ignoreCap and true or false    local item = 0    if(isItemStackable(itemid)) then        if(isItemRune(itemid)) then            amount = amount * subType        end        local count = amount        repeat            item = doCreateItemEx(itemid, math.min(100, count))            if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then                return 0, 0            end            count = count - math.min(100, count)        until count == 0        return amount, 0    end    local a = 0    if(inBackpacks) then        local container = doCreateItemEx(backpack, 1)        local b = 1        for i = 1, amount do            item = doAddContainerItem(container, itemid, subType)            if(itemid == ITEM_PARCEL) then                doAddContainerItem(item, ITEM_LABEL)            end            if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then                if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then                    b = b - 1                    break                end                a = i                if(amount > i) then                    container = doCreateItemEx(backpack, 1)                    b = b + 1                end            end        end        return a, b    end    for i = 1, amount do        item = doCreateItemEx(itemid, subType)        if(itemid == ITEM_PARCEL) then            doAddContainerItem(item, ITEM_LABEL)        end        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then            break        end        a = i    end    return a, 0endfunction doRemoveItemIdFromPos(id, n, position)    local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})    if(thing.itemid ~= id) then        return false    end    doRemoveItem(thing.uid, n)    return trueendfunction getNpcName()    return getCreatureName(getNpcId())endfunction getNpcPos()    return getCreaturePosition(getNpcId())endfunction selfGetPosition()    local t = getNpcPos()    return t.x, t.y, t.zendmsgcontains = doMessageCheckmoveToPosition = selfMoveTomoveToCreature = selfMoveToCreatureselfMoveToPosition = selfMoveToselfGotoIdle = selfIdleisPlayerPremiumCallback = isPremiumdoPosRemoveItem = doRemoveItemIdFromPosdoNpcBuyItem = doPlayerRemoveItemdoNpcSetCreatureFocus = selfFocusgetNpcCid = getNpcIdgetDistanceTo = getNpcDistanceTogetDistanceToCreature = getNpcDistanceToCreature

 

 

 

Agora deu esse:

[Error - NpcScript Interface] data/npc/scripts/mayor2.lua:onCreatureSayDescription: data/npc/lib/npc.lua:40: attempt to index global 's' (a number value)stack traceback:data/npc/lib/npc.lua:40: in function 'getNpcDistanceToCreature'data/npc/scripts/mayor2.lua:40: in function <data/npc/scripts/mayor2.lua:36>

Ta foda man :( 

Editado por Spring Trap
Link para o comentário
Compartilhar em outros sites

  • 0

@Spring Trap, estranho... Tenta assim:

 

Spoiler



function selfIdle()
    following = false
    attacking = false

    selfAttackCreature(0)
    target = 0
end

function selfSayChannel(cid, message)
    return selfSay(message, cid, false)
end

function selfMoveToCreature(id)
    if(not id or id == 0) then
        return
    end

    local t = getCreaturePosition(id)
    if(not t.x or t.x == nil) then
        return
    end

    selfMoveTo(t.x, t.y, t.z)
    return
end

function getNpcDistanceToCreature(id)
	if id == 0 or id == nil then
		selfIdle()
	end

	c = getCreaturePosition(id)
	if c == nil then
		return nil
	end
	s = getNpcPos()
	return math.max(math.abs(s.x-c.x), math.abs(s.y-c.y))
end

function doMessageCheck(message, keyword)
    if(type(keyword) == "table") then
        return table.isStrIn(keyword, message)
    end

    local a, b = message:lower():find(keyword:lower())
    if(a ~= nil and b ~= nil) then
        return true
    end

    return false
end

function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
    local amount = amount or 1
    local subType = subType or 1
    local ignoreCap = ignoreCap and true or false

    local item = 0
    if(isItemStackable(itemid)) then
        if(isItemRune(itemid)) then
            amount = amount * subType
        end

        local count = amount
        repeat
            item = doCreateItemEx(itemid, math.min(100, count))
            if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
                return 0, 0
            end

            count = count - math.min(100, count)
        until count == 0
        return amount, 0
    end

    local a = 0
    if(inBackpacks) then
        local container = doCreateItemEx(backpack, 1)
        local b = 1
        for i = 1, amount do
            item = doAddContainerItem(container, itemid, subType)
            if(itemid == ITEM_PARCEL) then
                doAddContainerItem(item, ITEM_LABEL)
            end

            if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
                if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
                    b = b - 1
                    break
                end

                a = i
                if(amount > i) then
                    container = doCreateItemEx(backpack, 1)
                    b = b + 1
                end
            end
        end

        return a, b
    end

    for i = 1, amount do
        item = doCreateItemEx(itemid, subType)
        if(itemid == ITEM_PARCEL) then
            doAddContainerItem(item, ITEM_LABEL)
        end

        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
            break
        end

        a = i
    end

    return a, 0
end

function doRemoveItemIdFromPos(id, n, position)
    local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})
    if(thing.itemid ~= id) then
        return false
    end

    doRemoveItem(thing.uid, n)
    return true
end

function getNpcName()
    return getCreatureName(getNpcId())
end

function getNpcPos()
    return getCreaturePosition(getNpcId())
end

function selfGetPosition()
    local t = getNpcPos()
    return t.x, t.y, t.z
end

msgcontains = doMessageCheck
moveToPosition = selfMoveTo
moveToCreature = selfMoveToCreature
selfMoveToPosition = selfMoveTo
selfGotoIdle = selfIdle
isPlayerPremiumCallback = isPremium
doPosRemoveItem = doRemoveItemIdFromPos
doNpcBuyItem = doPlayerRemoveItem
doNpcSetCreatureFocus = selfFocus
getNpcCid = getNpcId
getDistanceTo = getNpcDistanceTo
getDistanceToCreature = getNpcDistanceToCreature

 

 

Link para o comentário
Compartilhar em outros sites

  • 0
13 horas atrás, Danihcv disse:

@Spring Trap, estranho... Tenta assim:

 

  Mostrar conteúdo oculto




function selfIdle()
    following = false
    attacking = false

    selfAttackCreature(0)
    target = 0
end

function selfSayChannel(cid, message)
    return selfSay(message, cid, false)
end

function selfMoveToCreature(id)
    if(not id or id == 0) then
        return
    end

    local t = getCreaturePosition(id)
    if(not t.x or t.x == nil) then
        return
    end

    selfMoveTo(t.x, t.y, t.z)
    return
end

function getNpcDistanceToCreature(id)
	if id == 0 or id == nil then
		selfIdle()
	end

	c = getCreaturePosition(id)
	if c == nil then
		return nil
	end
	s = getNpcPos()
	return math.max(math.abs(s.x-c.x), math.abs(s.y-c.y))
end

function doMessageCheck(message, keyword)
    if(type(keyword) == "table") then
        return table.isStrIn(keyword, message)
    end

    local a, b = message:lower():find(keyword:lower())
    if(a ~= nil and b ~= nil) then
        return true
    end

    return false
end

function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
    local amount = amount or 1
    local subType = subType or 1
    local ignoreCap = ignoreCap and true or false

    local item = 0
    if(isItemStackable(itemid)) then
        if(isItemRune(itemid)) then
            amount = amount * subType
        end

        local count = amount
        repeat
            item = doCreateItemEx(itemid, math.min(100, count))
            if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
                return 0, 0
            end

            count = count - math.min(100, count)
        until count == 0
        return amount, 0
    end

    local a = 0
    if(inBackpacks) then
        local container = doCreateItemEx(backpack, 1)
        local b = 1
        for i = 1, amount do
            item = doAddContainerItem(container, itemid, subType)
            if(itemid == ITEM_PARCEL) then
                doAddContainerItem(item, ITEM_LABEL)
            end

            if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
                if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
                    b = b - 1
                    break
                end

                a = i
                if(amount > i) then
                    container = doCreateItemEx(backpack, 1)
                    b = b + 1
                end
            end
        end

        return a, b
    end

    for i = 1, amount do
        item = doCreateItemEx(itemid, subType)
        if(itemid == ITEM_PARCEL) then
            doAddContainerItem(item, ITEM_LABEL)
        end

        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
            break
        end

        a = i
    end

    return a, 0
end

function doRemoveItemIdFromPos(id, n, position)
    local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})
    if(thing.itemid ~= id) then
        return false
    end

    doRemoveItem(thing.uid, n)
    return true
end

function getNpcName()
    return getCreatureName(getNpcId())
end

function getNpcPos()
    return getCreaturePosition(getNpcId())
end

function selfGetPosition()
    local t = getNpcPos()
    return t.x, t.y, t.z
end

msgcontains = doMessageCheck
moveToPosition = selfMoveTo
moveToCreature = selfMoveToCreature
selfMoveToPosition = selfMoveTo
selfGotoIdle = selfIdle
isPlayerPremiumCallback = isPremium
doPosRemoveItem = doRemoveItemIdFromPos
doNpcBuyItem = doPlayerRemoveItem
doNpcSetCreatureFocus = selfFocus
getNpcCid = getNpcId
getDistanceTo = getNpcDistanceTo
getDistanceToCreature = getNpcDistanceToCreature

 

 

 

Funcionou man pqp obrigado mesmo, de coracao man sempre salvando minha vida kk <3

Agora ta de boa nao da mais erro e o npc funciona normal

 

So que mais pra frente daria bug nao ne?

ja que o original e esse:

function getNpcDistanceToCreature(id)
	if(not id or id == 0) then
		selfIdle()
		return nil
	end

	local c = getCreaturePosition(id)
	if(not c.x or c.x == 0) then
		return nil
	end

	local s = getCreaturePosition(getNpcId())
	if(not s.x or s.x == 0 or s.z ~= c.z) then
		return nil
	end

	return math.max(math.abs(s.x - c.x), math.abs(s.y - c.y))
end

E tu fez uma function bem menor

Link para o comentário
Compartilhar em outros sites

  • 0

@Spring Trap, faltou eu botar um return nil.

Eu reli a function original aí, e a minha function ficou menor pq eu tinha pensado que uma checagem ali era desnecessária, mas não é não.
A function correta ficaria assim:

function getNpcDistanceToCreature(id)
	if id == 0 or id == nil then
		selfIdle()
		return nil
	end

	c = getCreaturePosition(id)
	if c == nil then
		return nil
	end

	s = getNpcPos()
	if s.z ~= c.z then
		return nil
	end
	return math.max(math.abs(s.x-c.x), math.abs(s.y-c.y))
end

 

Link para o comentário
Compartilhar em outros sites

  • 0
1 hora atrás, Danihcv disse:

@Spring Trap, faltou eu botar um return nil.

Eu reli a function original aí, e a minha function ficou menor pq eu tinha pensado que uma checagem ali era desnecessária, mas não é não.
A function correta ficaria assim:


function getNpcDistanceToCreature(id)
	if id == 0 or id == nil then
		selfIdle()
		return nil
	end

	c = getCreaturePosition(id)
	if c == nil then
		return nil
	end

	s = getNpcPos()
	if s.z ~= c.z then
		return nil
	end
	return math.max(math.abs(s.x-c.x), math.abs(s.y-c.y))
end

 

 

ERRO

[Error - NpcScript Interface] 
data/npc/scripts/mayor2.lua:onThink
Description: 
data/npc/scripts/mayor2.lua:85: attempt to compare number with nil
stack traceback:
data/npc/scripts/mayor2.lua:85: in function <data/npc/scripts/mayor2.lua:76>

 

Link para o comentário
Compartilhar em outros sites

  • 0

@Danihcv então nao e so ele ta dando em todos  o erro de antes voltou. Quando vou pra outra posicao Z ele da o erro

 

Spoiler

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 and getCreatureCondition(cid, CONDITION_INFIGHT) == false then
        selfSay('Hey Can you give me 1 Bandit King Hood?.')    
          focus = cid
          talk_start = os.clock()

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

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

            if msgcontains(msg, 'yes') then
            if getPlayerStorageValue(cid,6004) == 1 then
            selfSay('Sorry You Cant Do this quest.')    
            elseif msgcontains(msg, 'yes') then
            if doPlayerRemoveItem(cid,5879,1) == 0 then
            selfSay('Sorry Dont have that items.')    
            else        
            if doPlayerAddItem(cid,5919,1) then
            setPlayerStorageValue(cid,6004,1)
            selfSay('Thanks take this')
            focus = 0
            talk_start = 0
      end
   end
end
        
elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
            selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
            focus = 0
            talk_start = 0
        end
    end
end
function onThink()
    doNpcSetCreatureFocus(focus)
      if (os.clock() - talk_start) > 45 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
 

 

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...