In this spell, each unit gets damaged multiple times until they die.
How come they don't get hit only once?
How come they don't get hit only once?
JASS:
scope SPELL initializer onInit
globals
private constant real radius = 500 //The range where units are affected
private constant integer abilId = 039;A000039; //The raw code of the spell
private constant string fx = "Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl"//The special effect
private constant attacktype atkType = ATTACK_TYPE_MAGIC //The attack type
private constant damagetype dmgType = DAMAGE_TYPE_MAGIC //The damage type
private constant weapontype weapType = WEAPON_TYPE_WHOKNOWS //The weapon type
endglobals
private function chance takes integer lvl returns real
return 1 * I2R(lvl) //How much chance the ability has to be triggered
endfunction
private function damage takes integer lvl returns real
return 50 + 25 * I2R(lvl)
endfunction
private function filter takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit()))
endfunction
globals
private trigger array trig[2]
private triggeraction array trigAct[2]
private group grp = CreateGroup()
private unit tempUnit
endglobals
private function conditions takes nothing returns boolean
return IsUnitEnemy(GetEventDamageSource(), GetOwningPlayer(GetTriggerUnit())) and GetUnitAbilityLevel(GetTriggerUnit(), abilId) > 0
endfunction
private function hasAbility takes nothing returns boolean
return GetUnitAbilityLevel(GetTriggerUnit(), abilId) > 0
endfunction
private function actions takes nothing returns nothing
local real random = GetRandomReal(0, 100)
set tempUnit = GetTriggerUnit()
call GroupEnumUnitsInRange(grp, GetUnitX(tempUnit), GetUnitY(tempUnit), radius, Condition(function filter))
if(random <= chance(GetUnitAbilityLevel(GetTriggerUnit(), abilId))) then
loop
set tempUnit = FirstOfGroup(grp)
exitwhen tempUnit == null
call GroupRemoveUnit(grp, tempUnit)
if(IsUnitType(tempUnit, UNIT_TYPE_MAGIC_IMMUNE) != true) then
call BJDebugMsg("hit")
call DestroyEffect(AddSpecialEffect(fx, GetUnitX(tempUnit), GetUnitY(tempUnit)))
call UnitDamageTarget(GetTriggerUnit(), tempUnit, damage(GetUnitAbilityLevel(GetTriggerUnit(), abilId)), false, false, atkType, dmgType, weapType)
endif
endloop
endif
call GroupClear(grp)
endfunction
private function registerUnit takes nothing returns nothing
call TriggerRegisterUnitEvent(trig[0], GetTriggerUnit(), EVENT_UNIT_DAMAGED)
endfunction
private function onInit takes nothing returns nothing
local region reg = CreateRegion()
local integer i = 0
set trig[0] = CreateTrigger()
set trig[1] = trig[0]
call RegionAddRect(reg, GetWorldBounds())
loop
exitwhen i == 16
call TriggerRegisterPlayerUnitEvent(trig[1], Player(i), EVENT_PLAYER_HERO_SKILL, null)
set i = i + 1
endloop
set trigAct[0] = TriggerAddAction(trig[0], function actions)
call TriggerAddCondition(trig[0], Condition(function conditions))
call TriggerAddCondition(trig[1], Condition(function hasAbility))
set trigAct[1] = TriggerAddAction(trig[1], function registerUnit)
call RemoveRegion(reg)
set reg = null
endfunction
endscope