Hello and thanks for reading, I have tried to create a magic similar to the global chain.
Here is the code that does not work as it should, could someone please help me to complete it.
inside:
monster.lua
spells/chaintres.lua
The chain effect is incomplete and one of them does not receive damage.
could you make the chain effect hit both of them and they receive damage.
Here is the code that does not work as it should, could someone please help me to complete it.
inside:
monster.lua
Lua:monster.attacks = { {name ="chaintres", interval = 2000, chance = 100, minDamage = 1, maxDamage = 3, target = false} }
spells/chaintres.lua
Code:local combat = Combat() combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE) combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_PINK_ENERGY_SPARK) local spell = Spell("instant") function spell.onCastSpell(creature, var) local spectators = Game.getSpectators(creature:getPosition(), false, true, 7, 7, 7, 7) if #spectators == 0 then return false end local attackerPos = creature:getPosition() local initialTarget = nil local previousTarget = nil for _, spectator in pairs(spectators) do if not initialTarget then initialTarget = spectator end if previousTarget then local targetPos = spectator:getPosition() local path = previousTarget:getPosition():getPathTo(targetPos, 0, 0, true, true, 8) if path and #path > 0 then for i = 1, #path do attackerPos:getNextPosition(path[i], 1) attackerPos:sendMagicEffect(CONST_ME_PINK_ENERGY_SPARK) end combat:execute(previousTarget, Variant(targetPos)) end end previousTarget = spectator end if previousTarget and initialTarget then local targetPos = initialTarget:getPosition() local path = creature:getPosition():getPathTo(targetPos, 0, 0, true, true, 8) if path and #path > 0 then for i = 1, #path do attackerPos:getNextPosition(path[i], 1) attackerPos:sendMagicEffect(CONST_ME_PINK_ENERGY_SPARK) end combat:execute(creature, Variant(targetPos)) end end return true end spell:name("chaintres") spell:words("##1492") spell:isAggressive(true) spell:needTarget(false) spell:needLearn(true) spell:register()
The chain effect is incomplete and one of them does not receive damage.
could you make the chain effect hit both of them and they receive damage.