Damage doesn't work?

Romek

Super Moderator
Reaction score
963
Post the rest of the code.
Is [ljass]onInit[/ljass] ever actually called/executed?
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
It's called. I've put a Debug between the trigger and the register call. It was displayed.

Here's the code.
JASS:

scope SunStrike initializer onInit

    globals
        private constant integer SPELL_ID = 'A000'
        private constant attacktype AT = ATTACK_TYPE_HERO
        private constant damagetype DT = DAMAGE_TYPE_FIRE
        private constant string EFFECT1 = "Abilities\\Spells\\Human\\MarkOfChaos\\MarkOfChaosTarget.mdl"
        private constant string EFFECT2 = "Abilities\\Weapons\\LavaSpawnMissile\\LavaSpawnMissile.mdl"
    endglobals
    
    private function GetChances takes integer level returns boolean
        return GetRandomInt(0, 100) <= 5. + 5. * level
    endfunction
    
    private struct data
    
        unit caster
        unit target
        real damage
        effect effec
        integer exec
        
        private method destroy takes nothing returns nothing
            set .caster = null
            set .target = null
            set .damage = 0.00
            set .effec = null
            set .exec = 0
        endmethod
    
        private static method Cond takes nothing returns boolean
            local integer level = GetUnitAbilityLevel(GetAttacker(), SPELL_ID)
            return level > 0 and GetChances(level)
        endmethod
        
        private method periodic takes nothing returns nothing
            set .exec = .exec + 1
            if (.exec > 640 or IsUnitType(.target, UNIT_TYPE_DEAD)) then
                call DestroyEffect(.effec)
                call .stopPeriodic()
                call .deallocate()
                call .destroy()
            endif
            call UnitDamageTarget(.caster, .target, .damage, true, false, AT, DT, null)
        endmethod
        
        private static method Acti takes nothing returns nothing
            local thistype this = thistype.allocate()
            local integer level = GetUnitAbilityLevel(GetAttacker(), SPELL_ID)
            set this.caster = GetAttacker()
            set this.target = GetTriggerUnit()
            set this.damage = 0.25 * I2R(level)
            set this.effec = AddSpecialEffectTarget(EFFECT2, this.target, "head")
            set this.exec = 0
            call DestroyEffect(AddSpecialEffectTarget(EFFECT1, this.target, "origin"))
            call this.startPeriodic()
        endmethod

        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call Damage_RegisterEvent(t)
            call TriggerAddCondition(t, Condition(function thistype.Cond))
            call TriggerAddAction(t, function thistype.Acti)
        endmethod
        
        implement T32x

    endstruct

endscope
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
Check is the conditions is ever run, and if it returns what it needs to run the actions.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Well, I tried many things. It's really the register that bugs. No the condition or action.

Fixed. The onInit method on my struct was colliding with T32x's one,

Now it causes and infinite loop. Help to fix please =)

JASS:
scope SunStrike initializer init

    globals
        private constant integer SPELL_ID = 'A000'
        private constant attacktype AT = ATTACK_TYPE_HERO
        private constant damagetype DT = DAMAGE_TYPE_FIRE
        private constant string EFFECT1 = "Abilities\\Spells\\Human\\MarkOfChaos\\MarkOfChaosTarget.mdl"
        private constant string EFFECT2 = "Abilities\\Weapons\\LavaSpawnMissile\\LavaSpawnMissile.mdl"
    endglobals
    
    private function GetChances takes integer level returns boolean
        return GetRandomInt(0, 100) <= 5 + 5 * level
    endfunction
    
    private struct data
    
        unit caster
        unit target
        real damage
        effect effec
        integer exec
        
        private method destroy takes nothing returns nothing
            set .caster = null
            set .target = null
            set .damage = 0.00
            set .effec = null
            set .exec = 0
        endmethod
    
        static method Cond takes nothing returns boolean
            local integer level = GetUnitAbilityLevel(GetEventDamageSource(), SPELL_ID)
            return level > 0 and GetChances(level)
        endmethod
        
        private method periodic takes nothing returns nothing
            set .exec = .exec + 1
            if (.exec > 640 or IsUnitType(.target, UNIT_TYPE_DEAD)) then
                call DestroyEffect(.effec)
                call .stopPeriodic()
                call .deallocate()
                call .destroy()
            endif
            call UnitDamageTarget(.caster, .target, .damage, true, false, AT, DT, null)
        endmethod
        
        static method Acti takes nothing returns nothing
            local thistype this = thistype.allocate()
            local integer level = GetUnitAbilityLevel(GetEventDamageSource(), SPELL_ID)
            set this.caster = GetEventDamageSource()
            set this.target = GetTriggerUnit()
            set this.damage = 0.25 * I2R(level)
            set this.effec = AddSpecialEffectTarget(EFFECT2, this.target, "head")
            set this.exec = 0
            call DestroyEffect(AddSpecialEffectTarget(EFFECT1, this.target, "origin"))
            call this.startPeriodic()
        endmethod
        
        implement T32x

    endstruct
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call Damage_RegisterEvent(t)
        call TriggerAddCondition(t, Condition(function data.Cond))
        call TriggerAddAction(t, function data.Acti)
    endfunction

endscope
 

Jesus4Lyf

Good Idea™
Reaction score
397
Fixed. The onInit method on my struct was colliding with T32x's one,
Actually, it's because JassHelper calls struct initialisers before library initialisers. I'll do that lame thing and implement the initialiser in Damage as a module onInit implemented in an array struct to make sure the Event is created before anything else needs it.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
I tought it was because T32 also uses the method onInit. W/o.

I found a way to escape the supar loop with damage.

Damage_Spell()
and then in conditions
Damage_IsSpell()==false

No infinite loop <3
 

Jesus4Lyf

Good Idea™
Reaction score
397
Yea. There's a few ways. You can call DisableTrigger(GetTriggeringTrigger()) and then EnableTrigger... after dealing the damage as well. If you want nothing at all to trigger off it, you can call Damage_EnableEvent(false) and then ...(true) after. :)

I updated Damage so it should now work if you try to register the Event in a struct onInit.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
I tried disabling the trigger and enabling back after. It was still bugging.

Thanks for your systems btw.

I've got AIDS, T32(felt in love with it), Damage and Event.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top