Units Get Damaged More Than Once

Status
Not open for further replies.

_whelp

New Member
Reaction score
54
In this spell, each unit gets damaged multiple times until they die.

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 = 'A000' //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
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
    private function onInit takes nothing returns nothing
        local region reg = CreateRegion()
        local integer i = 0
        set trig[0] = CreateTrigger()
        set trig[1] = trig[0] // wtf?
        call RegionAddRect(reg, GetWorldBounds()) // What for?
        
        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) // What is this about?
        set reg = null // Why have this var at all?
    endfunction

This doesn't make sense. And [LJASS]trig[0][/LJASS] is exactly the same as [LJASS]trig[1][/LJASS], which means your damage event will be added every time a unit is damaged, etc...

Use Damage or something, if you have trouble fixing it.
 

_whelp

New Member
Reaction score
54
Err... those useless things were there because I forgot to delete them -_-'

It works now by changing that one thing you said about the triggers...
Can someone lock this thread?
 
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top