NO
dúvida

Target em area

Por nociam, 19 de mai. de 2015 em Scripts

resolvido
11
1.7k
nociamN
19 de maio de 2015 às 19:14

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.

zipter98Z
19 de maio de 2015 às 20:30

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 Maio 21 por zipter98

nociamN
19 de maio de 2015 às 21:28

fiz o teste mais ele sempre retorna print("There's no monsters targeting your summon.")?

zipter98Z
19 de maio de 2015 às 21:46

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
nociamN
19 de maio de 2015 às 23:04

Nao foi ainda.

zipter98Z
20 de maio de 2015 às 14:46

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
nociamN
20 de maio de 2015 às 23:10

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

 

zipter98Z
21 de maio de 2015 às 14:36
Melhor resposta

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 Maio 21 por zipter98

nociamN
21 de maio de 2015 às 17:16

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 Maio 21 por nociam

zipter98Z
21 de maio de 2015 às 17:45

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

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

Editado Maio 21 por zipter98

FurabioF
24 de maio de 2015 às 22:18

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.