@Spring Trap, como que tá os arquivos .xml desses npcs?
info
Grupo: Conde
Registrado: 07/04/15
Posts: 926
Reputação: +335
Gênero: Masculino

info
Grupo: Campones
Registrado: 01/05/15
Posts: 49
Reputação: +2

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 Maio 30 por Spring Trap
info
Grupo: Campones
Registrado: 14/10/15
Posts: 42
Reputação: +14

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
info
Grupo: Campones
Registrado: 01/05/15
Posts: 49
Reputação: +2

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
info
Grupo: Campones
Registrado: 01/05/15
Posts: 49
Reputação: +2

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
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 Junho 1 por Spring Trap
info
Grupo: Conde
Registrado: 07/04/15
Posts: 926
Reputação: +335
Gênero: Masculino

@Spring Trap, fiz a adaptação. Vê se resolve:
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
Editado Junho 1 por Danihcv
info
Grupo: Campones
Registrado: 01/05/15
Posts: 49
Reputação: +2

39 minutos atrás, Danihcv disse:@Spring Trap, fiz a adaptação. Vê se resolve:
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 Junho 1 por Spring Trap
info
Grupo: Conde
Registrado: 07/04/15
Posts: 926
Reputação: +335
Gênero: Masculino

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:
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
Editado Junho 1 por Danihcv
info
Grupo: Campones
Registrado: 01/05/15
Posts: 49
Reputação: +2

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:
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 Junho 1 por Spring Trap
info
Grupo: Conde
Registrado: 07/04/15
Posts: 926
Reputação: +335
Gênero: Masculino

@Spring Trap, estranho... Tenta assim:
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
info
Grupo: Campones
Registrado: 01/05/15
Posts: 49
Reputação: +2

13 horas atrás, Danihcv disse:@Spring Trap, estranho... Tenta assim:
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
info
Grupo: Conde
Registrado: 07/04/15
Posts: 926
Reputação: +335
Gênero: Masculino

@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
info
Grupo: Campones
Registrado: 01/05/15
Posts: 49
Reputação: +2

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>
info
Grupo: Conde
Registrado: 07/04/15
Posts: 926
Reputação: +335
Gênero: Masculino

@Spring Trap, manda o script mayor2.lua, pq o erro foi nele.
Editado Junho 2 por Danihcv


info
Grupo: Campones
Registrado: 01/05/15
Posts: 49
Reputação: +2
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:
[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:
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:
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 Maio 30 por Spring Trap