Ir para conteúdo
  • 0

Target em area


nociam

Pergunta

Existe alguma funçao pra pegar todos os monstro que estão com target no meu monstro em uma area sem estar com target neles e claro?Por quero fazer uma magia aonde vai ir um efeito ate eles e ai vai trazer eles pra cima de min.

Link para o comentário
Compartilhar em outros sites

10 respostass a esta questão

Posts Recomendados

  • 0

A função em si está funcionando perfeitamente. Provavelmente você está testando-a sem um summon.

Remova isso:

print(getCreatureName(pid).." - "..isPlayer(pid) and "player" or isMonster(pid) and "monster" or isSummon(pid) and "summon" or "npc")

e troque:

local targeting = getMonstersTargetingCid(getCreatureSummons(cid)[1], 5, 5) --Área de dimensão 5x5 SQMs.

por:

local targeting = getMonstersTargetingCid(cid, 5, 5) --Área de dimensão 5x5 SQMs.

Assim, serão verificados os monstros que estão atacando você, o jogador.

Ah, e também uma pequena falta de atenção minha:

Troque:

 

print(getCreatureName(targeting).." is targeting your summon.")

por:

 

print(getCreatureName(pid).." is targeting your summon.")
Editado por zipter98
Link para o comentário
Compartilhar em outros sites

  • 0

Sendo x e y as dimensões da área e cid, logicamente, a criatura sob a qual a função será executada:

function getMonstersTargetingCid(cid, x, y)
    if not isCreature(cid) then
        return false
    end
    local spec, uid = getSpectators(getThingPos(cid), tonumber(x) or 1, tonumber(y) or 1), {}
    for _, pid in pairs(spec) do
        if pid ~= cid and isMonster(pid) and getCreatureTarget(pid) == cid then
            table.insert(uid, pid)
        end
    end
    return uid
end
Exemplo de uso:
local targeting = getMonstersTargetingCid(getCreatureSummons(cid)[1], 5, 5)      --Área de dimensão 5x5 SQMs.
if targeting and #targeting > 0 then
    for _, pid in pairs(targeting) do
        print(getCreatureName(pid).." is targeting your summon.")
    end
else
    print("There's no monsters targeting your summon.")
end
Editado por zipter98
Link para o comentário
Compartilhar em outros sites

  • 0

Alguns servidores têm problemas com o isMonster. Talvez seja o caso do seu.

Tente esta versão:

 

function getMonstersTargetingCid(cid, x, y)
    if not isCreature(cid) then
        return false
    end
    local spec, uid = getSpectators(getThingPos(cid), tonumber(x) or 1, tonumber(y) or 1), {}
    for _, pid in pairs(spec) do
        if pid ~= cid and not isPlayer(pid) and getCreatureTarget(pid) == cid then
            table.insert(uid, pid)
        end
    end
    return uid
end
Link para o comentário
Compartilhar em outros sites

  • 0

Use este código e informe o que for imprimido no console:

 

function getMonstersTargetingCid(cid, x, y)
    if not isCreature(cid) then
        return false
    end
    local spec, uid = getSpectators(getThingPos(cid), tonumber(x) or 1, tonumber(y) or 1), {}
    for _, pid in pairs(spec) do
        print(getCreatureName(pid).." - "..isPlayer(pid) and "player" or isMonster(pid) and "monster" or isSummon(pid) and "summon" or "npc")
        if pid ~= cid and not isPlayer(pid) and getCreatureTarget(pid) == cid then
            table.insert(uid, pid)
        end
    end
    return uid
end
Link para o comentário
Compartilhar em outros sites

  • 0

retorno There's no monsters targeting your summon.

 

jeito que coloquei na magia :

 

 

function getMonstersTargetingCid(cid, x, y)
if not isCreature(cid) then
return false
end
local spec, uid = getSpectators(getThingPos(cid), tonumber(x) or 1, tonumber(y) or 1), {}
for _, pid in pairs(spec) do
print(getCreatureName(pid).." - "..isPlayer(pid) and "player" or isMonster(pid) and "monster" or isSummon(pid) and "summon" or "npc")
if pid ~= cid and not isPlayer(pid) and getCreatureTarget(pid) == cid then
table.insert(uid, pid)
end
end
return uid
end

local targeting = getMonstersTargetingCid(getCreatureSummons(cid)[1], 5, 5) --Área de dimensão 5x5 SQMs.
if targeting and #targeting > 0 then
for _, pid in pairs(targeting) do
print(getCreatureName(targeting).." is targeting your summon.")
end
else
print("There's no monsters targeting your summon.")

end

 

Link para o comentário
Compartilhar em outros sites

  • 0

Obrigado agora posso fazer as magia que quero.

 

[21/05/2015 14:49:11] Charizard is targeting your summon.


Então ela funfo mas quero lhe pedir mais uma coisa como não tinha essa função tive que fazer uma gambiarra utilizando uma magia que tinha no servidor se pode dar uma olhada e me dizer qual delas fica mais estavel o le mais rapido ja que a sua foi usado for e a que tenho foi while preciso de uma luz de quem conhece do assunto pra me iluminar.

 

minha magia

 

 

local pos = getPosfromArea(cid, MilkDrink)
local n = 0

while n < #pos do
n = n+1
thing = {x=pos[n].x,y=pos[n].y,z=pos[n].z,stackpos=253}
local pid = getThingFromPosWithProtect(thing)
if isCreature(pid) then
if isSummon(cid) and (isSummon(pid) or isPlayer(pid)) then
if canAttackOther(cid, pid) == "Can" then
addEvent(sendEffWithProtect, 100, cid, pos[n], 694)
doDanoWithProtect(cid, STEELDAMAGE, pos[n], MilkDrink, -min, -max, 0)
sendDistanceShootWithProtect(cid, getThingPosWithDebug(cid), getThingPosWithDebug(pid), 85)
end
elseif ehMonstro(cid) or ehMonstro(pid) then
addEvent(sendEffWithProtect, 100, cid, pos[n], 694)
doDanoWithProtect(cid, STEELDAMAGE, pos[n], MilkDrink, -min, -max, 0)
sendDistanceShootWithProtect(cid, getThingPosWithDebug(cid), getThingPosWithDebug(pid), 85)
end
end

end

 

 

com a sua função

 

 

local targeting = getMonstersTargetingCid(cid, 10, 10) --Área de dimensão 5x5 SQMs.
if targeting and #targeting > 0 then
for _, pid in pairs(targeting) do
addEvent(sendEffWithProtect, 100, cid, getThingPosWithDebug(pid), 694)
doDanoWithProtect(cid, STEELDAMAGE, getThingPosWithDebug(pid), MilkDrink, -min, -max, 0)
sendDistanceShootWithProtect(cid, getThingPosWithDebug(cid), getThingPosWithDebug(pid), 85)
end
else
sendEffWithProtect(cid, getThingPosWithDebug(cid), 694)

end

 

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

  • 0

A versão que gasta menos memória é a segunda.

Digo isso julgando tanto os códigos apresentados quanto as funções utilizadas.

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

  • 0

Tópico resolvido ? se sim marque o post que mais te ajudou como melhor resposta.

 

You see!~


Tópico movido para a seção de dúvidas e pedidos resolvidos.
Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...