lazarus321
Member
- Joined
- May 8, 2017
- Messages
- 209
- Reaction score
- 20
Hi guys,
I make one spell script with LoopCount but if select the target and deselect, the loop get error because no have target more. How can I fix this part?
Spell.
I make one spell script with LoopCount but if select the target and deselect, the loop get error because no have target more. How can I fix this part?
Spell.
C++:
local function sendHealingEffect(cid, position, loopCount)
local player = Player(cid)
local alvo = player:getTarget()
local alvopos = alvo:getPosition()
local nivel = player:getLevel()
local ml = player:getMagicLevel()
local efeito = math.random(2,8)
position:sendDistanceEffect(alvopos, efeito)
if efeito == 2 then
addEvent(function() doTargetCombatHealth(0, alvo, COMBAT_PHYSICALDAMAGE, -10, -30, CONST_ME_NONE) end, 1)
end
if efeito == 3 then
addEvent(function() doTargetCombatHealth(0, alvo, COMBAT_FIREDAMAGE, -10, -30, CONST_ME_NONE) end, 1)
end
if efeito == 4 then
addEvent(function() doTargetCombatHealth(0, alvo, COMBAT_ICEDAMAGE, -10, -30, CONST_ME_NONE) end, 1)
end
if efeito == 5 then
addEvent(function() doTargetCombatHealth(0, alvo, COMBAT_EARTHDAMAGE, -10, -30, CONST_ME_NONE) end, 1)
end
if efeito == 6 then
addEvent(function() doTargetCombatHealth(0, alvo, COMBAT_ENERGYDAMAGE, -10, -30, CONST_ME_NONE) end, 1)
end
if efeito == 7 then
addEvent(function() doTargetCombatHealth(0, alvo, COMBAT_HOLYDAMAGE, -10, -30, CONST_ME_NONE) end, 1)
end
if efeito == 8 then
addEvent(function() doTargetCombatHealth(0, alvo, COMBAT_DEATHDAMAGE, -10, -30, CONST_ME_NONE) end, 1)
end
end
function onCastSpell(creature, var)
local playerPos = creature:getPosition()
local qtd = math.floor((creature:getLevel() / 100) + (creature:getMagicLevel() / 10))
local alvo = creature:getTarget()
local alvopos = alvo:getPosition()
local loopCount = qtd
for i = 1, loopCount do
local position = Position(playerPos.x + math.random(-4, 4), playerPos.y + math.random(-4, 3), playerPos.z)
addEvent(doAreaCombatHealth, i * 125, creature:getId(), COMBAT_PHYSICALDAMAGE, position, 0, 0, 0, CONST_ME_NONE)
addEvent(sendHealingEffect, i * 125, creature:getId(), position, loopCount - i)
end
return true
end