• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Need help with a trigger

Status
Not open for further replies.
Level 2
Joined
Feb 23, 2011
Messages
7
Hey peeps, Im trying to making this ability that deals damage (its based on the original ability forked lightning, actually its the same just different lightning effect) and restores hit points based either on the damage deal or perhaps something else havent think anything else. The whole idea is, when the hero casts forked lightning and hits lets say 8 targets, the hero restores hit points based on a % of the damage dealed (lil example - 8 targets x 300 = 2400 total damage and the hero restores 25% of that damage). I really cant think up of a trigger to do that, please help.
 
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

I saw this thread, so I start with a little coding, hope this is, what you was searching for =)

JASS:
library ForkedLightning initializer init requires TimerUtils

    globals
        private constant    integer     S_ID        = 'A000'   //This is the spell id (rawcode)
        
        private constant    attacktype  A           = ATTACK_TYPE_NORMAL
        private constant    damagetype  D           = DAMAGE_TYPE_NORMAL
        private constant    weapontype  W           = WEAPON_TYPE_WHOKNOWS
        
        private constant    real        L_DESTROY   = 0.20   //After this time, the lightning effect (L_SFT) is destroyed.
        
        private constant    string      L_SFX       = "AFOD"   // The lightning effect (here: Finger of Death)
        private constant    string      T_SFX       = "Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl"   // The effect on the targets (Here: Finger of Death Target)
        
        // Don't change the constants under this line please \\
        
        private constant    real        L_TIME      = 0.04
        private constant    group       G           = CreateGroup()
    endglobals
    
    private function damage takes integer level returns real // Here I set the damage to each target
        return 85. * level
    endfunction
    
    private function maxtargets takes integer level returns integer // Here I set the maximal possible targets of the spell
        return 5 + level
    endfunction
    
    private function area takes integer level returns real   // This is the area around the targets and picks all possible targets for the damage
        return 250.
    endfunction
    
    private function widgetlife takes integer level returns real  // This is the value, how many % the caster gets to life (0.25% of the complet dealed damage)
        return 0.25
    endfunction
    
    // Configuration ends here. Don't change something below, if you don't know, what to do! \\
    
    private struct ForkedLightning
        static thistype  TEMP
        unit             caster  = null
        unit             target  = null
        lightning array  l[8] // You have to change this value (8 here) into the maximal possible targets!!!!!!
        real             c       = 0.
        real             d       = 0.
        real             a       = 0.
        real             p       = 0.
        real             w       = 0.
        integer          i       = 0
        integer          mt      = 0
        integer          ct      = 0
        
        private static method filter takes nothing returns boolean
            local thistype this = TEMP
            local unit u = GetFilterUnit()
            
            if .ct <= .mt and GetWidgetLife(u) > 0.405 and IsUnitEnemy(u,GetOwningPlayer(.caster)) and IsUnitType(u,UNIT_TYPE_STRUCTURE) == false and IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) == false then
                set .l[.i] = AddLightning(L_SFX,true,GetUnitX(.caster),GetUnitY(.caster),GetUnitX(u),GetUnitY(u))
                call DestroyEffect(AddSpecialEffectTarget(T_SFX,u,"chest"))
                set .i = .i + 1
                set .ct = .ct + 1
                
                call UnitDamageTarget(.caster,u,.d,true,false,A,D,W)
            endif
            set .w = .ct * .d * .p
            call SetWidgetLife(.caster,GetWidgetLife(.caster) + .w)
            return false
        endmethod
        
        private static method Loop takes nothing returns nothing
            local timer t = GetExpiredTimer()
            local thistype this = GetTimerData(t)
            local integer i = 0
            
            set .c = .c + L_TIME
            call DisplayTimedTextToPlayer(Player(0),0.,0.,2.,R2S(.c))
            if .c >= L_DESTROY then
                loop
                    exitwhen i == .i
                    call DestroyLightning(.l[i])
                    set i = i + 1
                endloop
                call .destroy()
                call ReleaseTimer(t)
            endif
            set t = null
        endmethod
        
        static method create takes unit caster,unit target returns thistype
            local thistype this = .allocate()
            local timer t = NewTimer()
            
            set .caster = caster
            set .target = target
            set .d = damage(GetUnitAbilityLevel(.caster,S_ID))
            set .mt = maxtargets(GetUnitAbilityLevel(.caster,S_ID))
            set .a = area(GetUnitAbilityLevel(.caster,S_ID))
            set .p = widgetlife(GetUnitAbilityLevel(.caster,S_ID))
            
            set TEMP = this
            call GroupEnumUnitsInRange(G,GetUnitX(.target),GetUnitY(.target),.a,Condition(function ForkedLightning.filter))
            call SetTimerData(t,this)
            call TimerStart(t,L_TIME,true,function ForkedLightning.Loop)
            set t = null
            return this
        endmethod
    endstruct
    
    private function cast takes nothing returns boolean
        if GetSpellAbilityId() == S_ID then
            call ForkedLightning.create(GetTriggerUnit(),GetSpellTargetUnit())
        endif
        return false
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            exitwhen i == 16
            call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            set i = i + 1
        endloop
        call TriggerAddCondition(t,Condition(function cast))
        call Preload(L_SFX)
        call Preload(T_SFX)
        
        set t = null
    endfunction
endlibrary

Hope you can do something with this and this spell isn't maybe perfect in coding, but does his job =)

Greetings and Peace
Dr. Boom
 

Attachments

  • this.w3x
    23.8 KB · Views: 41
Status
Not open for further replies.
Top