Ir para conteúdo
Banner com Efeitos

Erro em Script de Spell [attempt to index a (boolean value)]

Featured Replies

Postado

Olá, fiz eu mesmo o script para uma spell em TFS 0.4.0 mas estou enfrentando um erro. O código funciona perfeitamente, o efeito é como eu queria e o dano também, mas quando a criatura morre a função continua buscando a posição do Target (posTarget) e como não encontra (já que o monstro está morto), ele me retorna um erro no console. Obs: enquanto a criatura está viva não há erro algum.

 

Eu sei que o erro é causado por esse motivo: a CreaturePosition não retornar um valor válido já que o monstro morreu, mas como eu faço para interromper essa verificação depois do bicho morto e evitar o erro no console? Já tentei comparar posTarget com "nil", "false", mas não faço ideia de como resolver isso, apesar de parecer simples. Segue imagem do erro e em seguida o código da spell:

 

Erro:

image.thumb.png.ec1600738a27b74acf553c3bafcf0e51.png

Spoiler

function doSendFlamingSphere(cid, target)

local effectType = 3 -- effect 
	
        local posTarget = getCreaturePosition(cid)
		local posEffect = {
			{x=posTarget.x, y=(posTarget.y)-1, z=posTarget.z},
			{x=(posTarget.x)+1, y=posTarget.y, z=posTarget.z},
			{x=posTarget.x, y=(posTarget.y)+1, z=posTarget.z},
			{x=(posTarget.x)-1, y=posTarget.y, z=posTarget.z},
			{x=posTarget.x, y=(posTarget.y)-1, z=posTarget.z}
		}
			for i=1, 4, 1 do
			addEvent(doSendDistanceShoot, 625*i, {x=posEffect[i].x, y=posEffect[i].y, z=posEffect[i].z}, {x=posEffect[i+1].x, y=posEffect[i+1].y, z=posEffect[i+1].z}, effectType)
			end
			
	return true
end

function onCastSpell(cid, var)

local target = getCreatureTarget(cid)
local mana = 8
local chance = 45
local repeticao = (getPlayerLevel(cid))-1
if repeticao > 8 then
local repeticao = 8
end

	if getCreatureMana(cid) >= mana or getPlayerAccess(cid) >= 3 then
			doAddCondition(cid, condition)
			if chance > math.random(1,100) then
			doCombat(cid, combat, var)
			end
			doCreatureAddMana(cid, -mana)
			doSendFlamingSphere(target)
			for i=1, repeticao, 1 do
			addEvent(doSendFlamingSphere, 2500*i, target)
			end
				for i=1, repeticao, 1 do
					if chance > math.random(1,100) then
					addEvent(doCombat, 2500*i, cid, combat, var)
					end
				end
	else
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
		doPlayerSendCancel(cid,"You don't have enough mana.")	
	end
	return true
end

 

Postado
function doSendFlamingSphere(cid, target)
	local effectType = 3 -- effect 
	local posTarget = getCreaturePosition(cid)
	local posEffect = {
		{x=posTarget.x, y=(posTarget.y)-1, z=posTarget.z},
		{x=(posTarget.x)+1, y=posTarget.y, z=posTarget.z},
		{x=posTarget.x, y=(posTarget.y)+1, z=posTarget.z},
		{x=(posTarget.x)-1, y=posTarget.y, z=posTarget.z},
		{x=posTarget.x, y=(posTarget.y)-1, z=posTarget.z}
	}
	for i=1, 4, 1 do
		if isCreature(cid) and isCreature(target) then
			addEvent(doSendDistanceShoot, 625*i, {x=posEffect[i].x, y=posEffect[i].y, z=posEffect[i].z}, {x=posEffect[i+1].x, y=posEffect[i+1].y, z=posEffect[i+1].z}, effectType)
		end
	end
	return true
end

function onCastSpell(cid, var)
	local target = getCreatureTarget(cid)
	local mana = 8
	local chance = 45
	local repeticao = (getPlayerLevel(cid))-1
	if repeticao > 8 then
		local repeticao = 8
	end
	if getCreatureMana(cid) >= mana or getPlayerAccess(cid) >= 3 then
		doAddCondition(cid, condition)
			if chance > math.random(1,100) then
				doCombat(cid, combat, var)
			end
		doCreatureAddMana(cid, -mana)
		doSendFlamingSphere(target)
		for i=1, repeticao, 1 do
			addEvent(doSendFlamingSphere, 2500*i, target)
		end
		for i=1, repeticao, 1 do
			if chance > math.random(1,100) then
				addEvent(doCombat, 2500*i, cid, combat, var)
			end
		end
	else
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
		doPlayerSendCancel(cid,"You don't have enough mana.")	
	end
	return true
end

 

 

Te ajudei ?? Que tal fazer uma contribuição ?

Doar

Postado
function doSendFlamingSphere(cid, target)
	local effectType = 3 -- effect 
	local posTarget = getCreaturePosition(cid)
	local posEffect = {
		{x=posTarget.x, y=(posTarget.y)-1, z=posTarget.z},
		{x=(posTarget.x)+1, y=posTarget.y, z=posTarget.z},
		{x=posTarget.x, y=(posTarget.y)+1, z=posTarget.z},
		{x=(posTarget.x)-1, y=posTarget.y, z=posTarget.z},
		{x=posTarget.x, y=(posTarget.y)-1, z=posTarget.z}
	}
	for i=1, 4, 1 do
		if isCreature(cid) and isCreature(target) then
			addEvent(doSendDistanceShoot, 625*i, {x=posEffect[i].x, y=posEffect[i].y, z=posEffect[i].z}, {x=posEffect[i+1].x, y=posEffect[i+1].y, z=posEffect[i+1].z}, effectType)
		end
	end
	return true
end

function onCastSpell(cid, var)
	local target = getCreatureTarget(cid)
	local mana = 8
	local chance = 45
	local repeticao = (getPlayerLevel(cid))-1
	if repeticao > 8 then
		local repeticao = 8
	end
	if getCreatureMana(cid) >= mana or getPlayerAccess(cid) >= 3 then
		doAddCondition(cid, condition)
			if chance > math.random(1,100) then
				doCombat(cid, combat, var)
			end
		doCreatureAddMana(cid, -mana)
    	if isCreature(cid) and isCreature(target) then
			doSendFlamingSphere(target)
      	end
		for i=1, repeticao, 1 do
      		if isCreature(cid) and isCreature(target) then
				addEvent(doSendFlamingSphere, 2500*i, target)
          	end
		end
		for i=1, repeticao, 1 do
			if chance > math.random(1,100) then
				addEvent(doCombat, 2500*i, cid, combat, var)
			end
		end
	else
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
		doPlayerSendCancel(cid,"You don't have enough mana.")	
	end
	return true
end
Citar

 

 

 

Te ajudei ?? Que tal fazer uma contribuição ?

Doar

Postado
  • Autor
4 hours ago, DboExplorer said:

function doSendFlamingSphere(cid, target)
	local effectType = 3 -- effect 
	local posTarget = getCreaturePosition(cid)
	local posEffect = {
		{x=posTarget.x, y=(posTarget.y)-1, z=posTarget.z},
		{x=(posTarget.x)+1, y=posTarget.y, z=posTarget.z},
		{x=posTarget.x, y=(posTarget.y)+1, z=posTarget.z},
		{x=(posTarget.x)-1, y=posTarget.y, z=posTarget.z},
		{x=posTarget.x, y=(posTarget.y)-1, z=posTarget.z}
	}
	for i=1, 4, 1 do
		if isCreature(cid) and isCreature(target) then
			addEvent(doSendDistanceShoot, 625*i, {x=posEffect[i].x, y=posEffect[i].y, z=posEffect[i].z}, {x=posEffect[i+1].x, y=posEffect[i+1].y, z=posEffect[i+1].z}, effectType)
		end
	end
	return true
end

function onCastSpell(cid, var)
	local target = getCreatureTarget(cid)
	local mana = 8
	local chance = 45
	local repeticao = (getPlayerLevel(cid))-1
	if repeticao > 8 then
		local repeticao = 8
	end
	if getCreatureMana(cid) >= mana or getPlayerAccess(cid) >= 3 then
		doAddCondition(cid, condition)
			if chance > math.random(1,100) then
				doCombat(cid, combat, var)
			end
		doCreatureAddMana(cid, -mana)
    	if isCreature(cid) and isCreature(target) then
			doSendFlamingSphere(target)
      	end
		for i=1, repeticao, 1 do
      		if isCreature(cid) and isCreature(target) then
				addEvent(doSendFlamingSphere, 2500*i, target)
          	end
		end
		for i=1, repeticao, 1 do
			if chance > math.random(1,100) then
				addEvent(doCombat, 2500*i, cid, combat, var)
			end
		end
	else
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
		doPlayerSendCancel(cid,"You don't have enough mana.")	
	end
	return true
end

 

 

Com esse código o erro persiste o mesmo e o efeito da magia nem sai.

 

Estou tentando resolver aqui, já coloquei verificação de isCreature na função da sendFlamingSphere, já tentei colocar a verificação dentro do script da spell no onSay, já tentei verificar se o targetPos era igual e/ou diferente nil e false, etc... enfim, não consigo resolver. 

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo