Niloahs
Well-Known Member
- Joined
- Feb 10, 2020
- Messages
- 110
- Solutions
- 1
- Reaction score
- 81
When i disable the spell, just the animation stop but Combat Area still continues doing damage.
follow the gif below
SPELL
LIB
if someone can help, I would be very grateful!
follow the gif below
SPELL
Lua:
--[[#######################################################################################]]--
function doAreaCombatDamage(cid, attacker, combatType, position, min, max, effect)
--// Incase the creature disappears within 120-250ms time window
local creature = Creature(cid)
if not creature then
return
end
doAreaCombatHealth(attacker, combatType, position, 0, min, max, effect)
end
local running = {}
local function runSpell(cid, i, j, delay, radius, damageType, areaEffect, distanceEffect)
local player = Player(cid)
--// Player doesn't exist anymore
if not player or Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and bit.band(player:getGroup():getFlags(), PlayerFlag_IgnoreProtectionZone) == 0 then
stopEvent(running[player:getId()])
running[player:getId()] = nil
return
end
if i == j then
if getPlayerMana(cid) >= 50 then
i = 0
doPlayerAddMana(cid, -50)
else
stopEvent(running[player:getId()])
running[player:getId()] = nil
return
end
end
local center = player:getPosition()
local level = player:getLevel()
local maglevel = player:getMagicLevel()
local min = (level/10) + (maglevel * 0.05) + 25
local max = (level/10) + (maglevel * 0.1) + 50
local specs = Game.getSpectators(center, false, false, radius, radius, radius, radius)
--// Send effects and damage creatures within radius
local args = {nil, cid, damageType, nil, -min, -max, areaEffect}
for i = 1, #specs do
if specs[i]:isMonster() then
local specPos = specs[i]:getPosition()
args[1] = specs[i]:getId()
args[4] = specPos
addEvent(doAreaCombatDamage, 250 + (center:getDistance(specPos) * 7), unpack(args))
end
end
addEvent(runSpell, delay, cid, i+1, j, delay, radius, damageType, areaEffect, distanceEffect)
end
local function sendEffects(cid, delay, radius, areaEffect, distanceEffect, distanceEffectCentral)
local player = Player(cid)
if not player or Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and bit.band(player:getGroup():getFlags(), PlayerFlag_IgnoreProtectionZone) == 0 then
stopEvent(player:getId())
running[player:getId()] = nil
return
end
local pos = player:getPosition()
local offsets = {DIRECTION_NORTH, DIRECTION_NORTHEAST, DIRECTION_EAST, DIRECTION_SOUTHEAST, DIRECTION_SOUTH, DIRECTION_SOUTHWEST, DIRECTION_WEST, DIRECTION_NORTHWEST}
for i = 1, #offsets do
local fromPos = pos:setDirectionOffset(offsets[i], radius)
local toPos = pos:setDirectionOffset(offsets[i+1] or offsets[1], radius)
fromPos:sendDistanceEffect(toPos, distanceEffect)
local fromPos = pos:setDirectionOffset(offsets[i], 0)
local toPos = pos:setDirectionOffset(offsets[i+1] or offsets[1], radius)
fromPos:sendDistanceEffect(toPos, distanceEffectCentral)
end
pos:sendMagicEffect(areaEffect)
running[player:getId()] = addEvent(sendEffects, delay, cid, delay, radius, areaEffect, distanceEffect, distanceEffectCentral)
end
--[[#######################################################################################]]--
local config = {
rounds = 4, -- number of times the spell loops (effects & damage)
delay = 250, -- ms
radius = 3,
damageType = COMBAT_ENERGYDAMAGE,
areaEffect = CONST_ME_PURPLEENERGY,
distanceEffect = CONST_ANI_ENERGYBALL,
distanceEffectCentral = CONST_ANI_ENERGY
}
function onCastSpell(creature, variant)
local player = creature:getPlayer()
if not player then
return false
end
if running[player:getId()] == nil then
player:sendCancelMessage("expand static field")
sendEffects(player:getId(), config.delay, config.radius-1, config.areaEffect, config.distanceEffect, config.distanceEffectCentral)
runSpell(player:getId(), 0, config.rounds, config.delay, config.radius, config.damageType, config.areaEffect, config.distanceEffect)
else
stopEvent(running[player:getId()])
running[player:getId()] = nil
player:sendCancelMessage("compress static field")
end
return true
end
LIB
Lua:
Position.directionOffset = {
[DIRECTION_NORTH] = {x = 0, y = -1},
[DIRECTION_EAST] = {x = 1, y = 0},
[DIRECTION_SOUTH] = {x = 0, y = 1},
[DIRECTION_WEST] = {x = -1, y = 0},
[DIRECTION_SOUTHWEST] = {x = -1, y = 1},
[DIRECTION_SOUTHEAST] = {x = 1, y = 1},
[DIRECTION_NORTHWEST] = {x = -1, y = -1},
[DIRECTION_NORTHEAST] = {x = 1, y = -1}
}
function Position:setDirectionOffset(dir, radius)
local range = radius or 0
local tmp = Position.directionOffset[dir]
if not tmp then
return self
end
return Position(self.x + tmp.x + (tmp.x * range), self.y + tmp.y + (tmp.y * range), self.z)
end
if someone can help, I would be very grateful!