Okay, I've screwed my spell trigger up =)

SineCosine

I'm still looking for my Tangent
Reaction score
77
Be kind now..
I've been trying to get a spell to Damage nearby enemies and heal allies (and the caster) based on the formula:

(Damage * No. of enemies hit) / (No. of allies nearby + 1)

= Total damage dealt / (No. of allies nearby + 1)

The thing is, one value is stuck at 10.00
That is, the totaldmg value

I know there is a better way to do what I'm doing..
But I don't know what that other much better way is, so I'm asking for help here in hopes that someone will enlighten me.

I don't mind starting from scratch, it isn't exactly a lot of code, but I just need a little nudge in the right direction :)

method GroupReverse is where my problem is, about mid-way through the code

JASS:
scope ReversedA initializer RAInit

    struct RA
        private static RA data = 0
        private static RA data2 = 0
        
        unit caster
        
        player playcast
        
        group TBRA = CreateGroup()
        
        integer ticks
        integer AbilityLevel
        
        real casterx
        real castery
        real damage
        real heal
        
        real totaldmg
        
        integer allies
        integer healself
        
        static method GroupHeal takes nothing returns boolean
            local RA r = RA.data2
            local unit u = GetFilterUnit()
            
            set r.heal = (r.totaldmg / r.allies)
            
            if IsUnitEnemy(u, r.playcast) == false then
                call SetWidgetLife(u, GetWidgetLife(u) + r.heal)
            endif
            
            if r.healself == 0 then
                call SetWidgetLife(r.caster, GetWidgetLife(r.caster) + r.heal)
                set r.healself = 1
            endif
            
            set u = null
            return false
        endmethod
        
        static method GroupReverse takes nothing returns boolean
            local RA r = RA.data
            local unit u = GetFilterUnit()
            
            set r.heal = 0
            set r.totaldmg = 0
            set r.allies = 1
            set r.healself = 0
            
            if IsUnitEnemy(u, r.playcast) == true then
                call UnitDamageTarget(r.caster, u, r.damage, true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_DIVINE, null)
                set r.totaldmg = r.totaldmg + r.damage
                
                call BJDebugMsg(R2S(r.totaldmg)) //This value is eternally stuck at 10.00
            endif
            
            if IsUnitEnemy(u, r.playcast) == false then
                set r.allies = r.allies + 1
            endif
            
            set RA.data2 = r
           
            set u = null
            return false
        endmethod
        
        private method periodic takes nothing returns nothing
            local RA r = this
            
            if r.ticks == 32 or  r.ticks == 64 or r.ticks == 96 or r.ticks == 128 or r.ticks == 160 then
                set r.casterx = GetUnitX(r.caster)
                set r.castery = GetUnitY(r.caster)
                set RA.data = r
                call GroupEnumUnitsInRange(r.TBRA, r.casterx, r.castery, 500.00, function RA.GroupReverse)
                call GroupEnumUnitsInRange(r.TBRA, r.casterx, r.castery, 500.00, function RA.GroupHeal)
            endif
            
            if r.ticks == 161 then
                call r.stopPeriodic()
                call r.destroy()
            endif
            
            set r.ticks = r.ticks + 1
        endmethod
        
        implement T32x
        
        static method RAACT takes nothing returns nothing
            local RA r = RA.allocate()
            
            set r.caster = GetTriggerUnit()
            set r.playcast = GetTriggerPlayer()
            set r.ticks = 0
            set r.AbilityLevel = GetUnitAbilityLevel(r.caster, 'A004')
            set r.casterx = GetUnitX(r.caster)
            set r.castery = GetUnitY(r.caster)
            set r.damage = (r.AbilityLevel * 5.00) + 5.00
            
            call r.startPeriodic()
        endmethod
        
    endstruct
    private function RACond takes nothing returns boolean
        return GetSpellAbilityId() == 'A004'
    endfunction
    
    private function RAInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
        exitwhen i == 4
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i+1
        endloop
        
        call TriggerAddCondition(t, Condition(function RACond))
        call TriggerAddAction(t, function RA.RAACT)
    endfunction

endscope


[EDIT]
I got the spell to work the way I wanted it to.
But I'd still like to know if there is a much better way to do things

All enemies are Orc race
JASS:
scope ReversedA initializer RAInit

    struct RA
        private static RA data = 0
        private static RA data2 = 0
        
        unit caster
        
        player playcast
        
        group TBRA = CreateGroup()
        
        integer ticks
        integer AbilityLevel
        
        real casterx
        real castery
        real damage
        real heal
        
        integer allies
        integer healself
        integer enemies
        
        static method GroupHeal takes nothing returns boolean
            local RA r = RA.data2
            local unit u = GetFilterUnit()
            
            set r.heal = ((r.damage * r.enemies) / r.allies)
            
            if IsUnitEnemy(u, r.playcast) == false and IsUnitType(u, UNIT_TYPE_STRUCTURE) == false and IsUnitType(u, UNIT_TYPE_TOWNHALL) == false then
                call SetWidgetLife(u, GetWidgetLife(u) + r.heal)
            endif
            
            if r.healself == 0 then
                call SetWidgetLife(r.caster, GetWidgetLife(r.caster) + r.heal)
                set r.healself = 1
            endif
            
            call BJDebugMsg(R2S(r.allies))
            
            set u = null
            return false
        endmethod
        
        static method GroupReverse takes nothing returns boolean
            local RA r = RA.data
            local unit u = GetFilterUnit()
            
            set r.heal = 0
            set r.healself = 0

            
            if IsUnitEnemy(u, r.playcast) == true and IsUnitRace(u, RACE_ORC) == true then
                call UnitDamageTarget(r.caster, u, r.damage, true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_DIVINE, null)
                set r.enemies = r.enemies + 1
            endif
            
            if IsUnitEnemy(u, r.playcast) == false and IsUnitType(u, UNIT_TYPE_STRUCTURE) == false and IsUnitType(u, UNIT_TYPE_TOWNHALL) == false then
                set r.allies = r.allies + 1
            endif
            
            set RA.data2 = r
            
            set u = null
            return false
        endmethod
        
        private method periodic takes nothing returns nothing
            local RA r = this
            
            if r.ticks == 32 or  r.ticks == 64 or r.ticks == 96 or r.ticks == 128 or r.ticks == 160 then
                set r.casterx = GetUnitX(r.caster)
                set r.castery = GetUnitY(r.caster)
                set r.enemies = 0
                set r.allies= 0
                set RA.data = r
                call GroupEnumUnitsInRange(r.TBRA, r.casterx, r.castery, 500.00, function RA.GroupReverse)
                call GroupEnumUnitsInRange(r.TBRA, r.casterx, r.castery, 500.00, function RA.GroupHeal)
            endif
            
            if r.ticks == 161 then
                call r.stopPeriodic()
                call r.destroy()
            endif
            
            set r.ticks = r.ticks + 1
        endmethod
        
        implement T32x
        
        static method RAACT takes nothing returns nothing
            local RA r = RA.allocate()
            
            set r.caster = GetTriggerUnit()
            set r.playcast = GetTriggerPlayer()
            set r.ticks = 0
            set r.AbilityLevel = GetUnitAbilityLevel(r.caster, 'A004')
            set r.casterx = GetUnitX(r.caster)
            set r.castery = GetUnitY(r.caster)
            set r.damage = (r.AbilityLevel * 5.00) + 5.00
            
            call UnitAddAbility(r.caster, 'A002')
            call UnitAddAbility(r.caster, 'A003')
            call UnitAddAbility(r.caster, 'A005')
            
            call r.startPeriodic()
        endmethod
        
        method onDestroy takes nothing returns nothing
            call UnitRemoveAbility(.caster, 'A002')
            call UnitRemoveAbility(.caster, 'A003')
            call UnitRemoveAbility(.caster, 'A005')
            
            set .caster = null
            call GroupClear(.TBRA)
            call DestroyGroup(.TBRA)
            set .TBRA = null
        endmethod
    endstruct
    private function RACond takes nothing returns boolean
        return GetSpellAbilityId() == 'A004'
    endfunction
    
    private function RAInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
        exitwhen i == 4
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i+1
        endloop
        
        call TriggerAddCondition(t, Condition(function RACond))
        call TriggerAddAction(t, function RA.RAACT)
    endfunction

endscope
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top