Tbol
Well-Known Member
- Joined
- Apr 7, 2019
- Messages
- 592
- Reaction score
- 64
I have a question: this code applies an effect (+/-) only when sendDistanceEffect reaches the target, and it applies the effect to the target. However, there's an issue—if the target changes position, such as moving one tile away, the effect is displayed at the original position instead of on the target. Is it possible to attach the effect to the creature so that it moves with the target even if their position changes?
LUA:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
function onGetFormulaValues(player, level, maglevel)
local min = (level * 5) + (maglevel * 12.5) + 25
local max = (level * 5) + (maglevel * 14) + 50
return -min, -max
end
combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
local function callback(creature, variant)
local target = Creature(variant:getNumber())
if not target then return false end
local creaturePos = creature:getPosition()
local targetPos = target:getPosition()
local distance = creaturePos:getDistance(targetPos)
local milliseconds = distance * 80
creaturePos:sendDistanceEffect(targetPos, 23)
addEvent(function()
combat:execute(creature, variant)
local effectPosition = targetPos + Position(1, 1, 0)
effectPosition:sendMagicEffect(986)
end, milliseconds)
return true
end
function onCastSpell(creature, variant)
return callback(creature, variant)
end