Units Get Damaged More Than Once

Status
Not open for further replies.

_whelp

New Member
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™
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
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.
  • Varine Varine:
    Good luck to the hurricane path people. Is TH still in Houston?
  • Ghan Ghan:
    I think so
    +1
  • The Helper The Helper:
    Yeah we got nothing here did not even rain
  • Ghan Ghan:
    We could use some rain.
  • The Helper The Helper:
    I am not complaining though Hurricanes are not fun I have been through alot of them
  • Blackveiled Blackveiled:
    I evacuated for it just incase since I live in La Porte pretty much right on the water (in Houston area). Didn't see anything. It's a good thing for me anyways.
  • Ghan Ghan:
    It's too bad that Blizzard messed up so terribly with Reforged.
  • Ghan Ghan:
    Still has a 0.6 user metacritic score.
  • Ghan Ghan:
    (Out of 10)
  • Varine Varine:
    I haven't even tried it yet because everyone said it sucked. How do you get .6 out of ten?
  • The Helper The Helper:
    I am waiting for Dwarf Fortress to come out on Steam then I am on it.
  • Accname Accname:
    I play Dwarf Fortress from time to time.
  • Accname Accname:
    Its Okay.
  • Accname Accname:
    But the performance is sub-par. Does not seem to be well optimized.
  • Varine Varine:
    Is the Steam version coming with a graphical overlay or is it using the ASCII graphics still?
  • tom_mai78101 tom_mai78101:
    Steam version has the graphical overlay.
  • The Helper The Helper:
    Steam Version has graphics, a new interface and will be integrated in the steam mod stuff
  • Blackveiled Blackveiled:
    I didn't think WC3 Reforged was that bad. It pretty much did what it stated (to me at least), but then again I can care less about reforged campaigns and all that. I just care about gameplay.
  • Varine Varine:
    I think people were hoping for a resurgence in mod support. I have little interest in the actual game tbh
  • Varine Varine:
    Plus I know they added that Dota precedent clause where Blizzard can steal your shit which isn't cool.
  • Ghan Ghan:
    They sold Reforged to the community as primarily a huge graphical uplift with high res textures and redone cinematics.
  • Ghan Ghan:
    They even showed one of the redone cinematics at Blizzcon and that very cinematic wasn't even in the released game.
  • Ghan Ghan:
    So I think folks were angry about that.
  • Varine Varine:
    Didn't the backwards compatability have issues too?
  • Accname Accname:
    I never had any hopes for that. Blizzard is not the same company it was 10 years ago.

    Members online

    No members online now.

    Affiliates

    Hive Workshop
    Top