Spell Lightning Strike

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Why is this approved? The spell is leaking Locations like hell. It creates more than 40-50 permanent handles on every use.

The function "Location(X, Y)" leaks twice in your code in addition to those leaks Tyrande reported!
Create a local Location and store the Location return in it, then remove the Location and set it to null.
Or use a global temporary Location variable;

Also, half of the variables stored to the struct are useless and could be done via locals or some few globals.
 

Hatebreeder

So many apples
Reaction score
381
This was approved a loooong time ago...
I'll remove them when I've got time... Until then, I guess somebody may put this into Graveyard.
 

muzzel

New Member
Reaction score
1
I fixed this spell, cause im gonna use it in my map. It now doesnt need ABC anymore and i hope all leaks are fixed.

Some changes i made (sry i thought about uploading it here after i already changed):
- only 1 level but damage can depend on stats
- i removed some comments

JASS:
library LightningStrike initializer InitTrig
    // Spell credits: Hatebreeder (thehelper.net)
    //=================================================================================
    // config:
    globals
        constant real STRIKE_PERIODIC = 0.05        // This determines the speed of the Timer
        constant integer STRIKE_ID = 'A01V'         // This is the Raw Code of the Ability
        constant integer STRIKE_ANGLES = 8          // This is the Number of Angles the Lightning Creates
        constant string STRIKE_LIGHTNING = "CLPB"   // Change this to change the look of the lightning
        constant string STRIKE_SFX_1 = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"              //Special effect 1
        constant string STRIKE_SFX_2 = "Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl"                  //Special effect 2
        constant string STRIKE_SFX_3 = "Abilities\\Weapons\\SpiritOfVengeanceMissile\\SpiritOfVengeanceMissile.mdl"//Special effect 3
        constant string STRIKE_SFX_4 = "Abilities\\Weapons\\Bolt\\BoltImpact.mdl"                                  //Special effect 4
        constant integer STRIKE_RADIUS = 180        // Determines the Max.Radius of the Lightning
    endglobals
    // damage dealt initially:
    private function DamageInitialAmount takes unit Caster, unit Target returns real
        return 50.
    endfunction
    // damage dealt over time:
    private function DamageTimeAmount takes unit Caster, unit Target returns real
        return 5.
    endfunction
    // end config
    //=================================================================================

    globals
        private hashtable TimerHash = InitHashtable()
    endglobals
    
    private struct Lightning
        unit Caster
        real Angle
        real TargetX
        real TargetY
        real TargetLocationX
        real TargetLocationY
        real TargetX2
        real TargetY2
        real Alpha
        integer Distance
        integer Integer
        group Group
        lightning array Zap[100]
    endstruct

    private function Trig_Lightning_Strike_Conditions takes nothing returns boolean
        return GetSpellAbilityId() == STRIKE_ID
    endfunction

    private function Trig_Lightning_Strike_Group takes nothing returns boolean
        return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false and IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD) == false
    endfunction

    private function Trig_Lightning_Strike_Timer takes nothing returns nothing
        local timer Timer = GetExpiredTimer()
        local unit PickedUnit
        local real PickedUnitX
        local real PickedUnitY
        local Lightning Data = LoadInteger(TimerHash, GetHandleId(Timer), 0)
        
        call GroupEnumUnitsInRange(Data.Group,Data.TargetLocationX,Data.TargetLocationY,Data.Distance,Condition(function Trig_Lightning_Strike_Group))
        loop
            set PickedUnit = FirstOfGroup(Data.Group)
            exitwhen PickedUnit == null
            if IsUnitEnemy(PickedUnit,GetOwningPlayer(Data.Caster)) then
                call UnitDamageTarget(Data.Caster,PickedUnit,DamageTimeAmount(Data.Caster, PickedUnit),false,true,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_LIGHTNING,WEAPON_TYPE_WHOKNOWS)
                set PickedUnitX = GetUnitX(PickedUnit)
                set PickedUnitY = GetUnitY(PickedUnit)
                call DestroyEffect(AddSpecialEffect(STRIKE_SFX_3,PickedUnitX,PickedUnitY))
            endif
            call GroupRemoveUnit(Data.Group, PickedUnit)
        endloop
        
        set PickedUnit = null
        
        set Data.Angle = 360/STRIKE_ANGLES
        set Data.Distance = Data.Distance + 14
        set Data.Alpha = Data.Alpha - 0.03
        
        loop
            exitwhen Data.Integer >= STRIKE_ANGLES
            set Data.TargetX = Data.TargetLocationX + Data.Distance * Cos(Data.Angle * bj_DEGTORAD * Data.Integer)
            set Data.TargetY = Data.TargetLocationY + Data.Distance * Sin(Data.Angle * bj_DEGTORAD * Data.Integer)
            set Data.TargetX2 = Data.TargetLocationX + Data.Distance * Cos(Data.Angle * bj_DEGTORAD * (1 + Data.Integer))
            set Data.TargetY2 = Data.TargetLocationY + Data.Distance * Sin(Data.Angle * bj_DEGTORAD * (1 + Data.Integer))
            call MoveLightning(Data.Zap[Data.Integer],false,Data.TargetX,Data.TargetY,Data.TargetX2,Data.TargetY2)
            call SetLightningColor(Data.Zap[Data.Integer],1,1,1,Data.Alpha)
            set Data.Integer = Data.Integer + 1
        endloop
        
        set Data.Integer = 0
        
        if Data.Distance >= STRIKE_RADIUS then
            loop
                exitwhen Data.Integer >= STRIKE_ANGLES
                call DestroyLightning(Data.Zap[Data.Integer])
                set Data.Integer = Data.Integer + 1
            endloop
            set Data.Integer = 0
            call FlushChildHashtable(TimerHash, GetHandleId(Timer))
            call Data.destroy()
            call PauseTimer(Timer)
            call DestroyTimer(Timer)
        endif
        set Timer = null
    endfunction

    private function Trig_Lightning_Strike_Actions takes nothing returns nothing
        local Lightning Data = Lightning.create()
        local timer Timer = CreateTimer()
        local unit PickedUnit
        
        set Data.Caster = GetTriggerUnit()
        set Data.Angle = 360/STRIKE_ANGLES
        set Data.Distance = 0
        set Data.Alpha = 1
        set Data.Group = CreateGroup()
        set Data.TargetLocationX = GetSpellTargetX()
        set Data.TargetLocationY = GetSpellTargetY()
        
        call DestroyEffect(AddSpecialEffect(STRIKE_SFX_1,Data.TargetLocationX,Data.TargetLocationY))
        call DestroyEffect(AddSpecialEffect(STRIKE_SFX_2,Data.TargetLocationX,Data.TargetLocationY))
        
        call GroupEnumUnitsInRange(Data.Group,Data.TargetLocationX,Data.TargetLocationY,STRIKE_RADIUS, Condition(function Trig_Lightning_Strike_Group))
        loop
            set PickedUnit = FirstOfGroup(Data.Group)
            exitwhen PickedUnit == null
            if IsUnitEnemy(PickedUnit,GetOwningPlayer(Data.Caster)) then
                call UnitDamageTarget(Data.Caster,PickedUnit,DamageInitialAmount(Data.Caster, PickedUnit),false,true,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_LIGHTNING,WEAPON_TYPE_WHOKNOWS)
                call DestroyEffect(AddSpecialEffectTarget(STRIKE_SFX_4,PickedUnit,"chest"))
            endif
            call GroupRemoveUnit(Data.Group, PickedUnit)
        endloop
        set PickedUnit = null
        
        loop
            exitwhen Data.Integer >= STRIKE_ANGLES
            set Data.TargetX = Data.TargetLocationX + Data.Distance * Cos(Data.Angle * bj_DEGTORAD * Data.Integer)
            set Data.TargetY = Data.TargetLocationY + Data.Distance * Sin(Data.Angle * bj_DEGTORAD * Data.Integer)
            set Data.TargetX2 = Data.TargetLocationX + Data.Distance * Cos(Data.Angle * bj_DEGTORAD * (1 + Data.Integer))
            set Data.TargetY2 = Data.TargetLocationY + Data.Distance * Sin(Data.Angle * bj_DEGTORAD * (1 + Data.Integer))
            set Data.Zap[Data.Integer] = AddLightning(STRIKE_LIGHTNING,false,Data.TargetX,Data.TargetY,Data.TargetX2,Data.TargetY2)
            call SetLightningColor(Data.Zap[Data.Integer],1,1,1,Data.Alpha)
            set Data.Integer = Data.Integer + 1
        endloop
        
        set Data.Integer = 0
        
        call SaveInteger(TimerHash, GetHandleId(Timer), 0, Data)
        call TimerStart(Timer,STRIKE_PERIODIC,true,function Trig_Lightning_Strike_Timer)
    endfunction
    private function InitTrig takes nothing returns nothing
        local trigger Lightning_Strike = CreateTrigger()
        call Preload("Abilities\\Weapons\\Bolt\\BoltImpact.mdl")
        call Preload("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl")
        call Preload("Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl")
        call Preload("Abilities\\Weapons\\SpiritOfVengeanceMissile\\SpiritOfVengeanceMissile.mdl")
        call TriggerRegisterAnyUnitEventBJ( Lightning_Strike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( Lightning_Strike, Condition( function Trig_Lightning_Strike_Conditions ) )
        call TriggerAddAction( Lightning_Strike, function Trig_Lightning_Strike_Actions )
    endfunction
endlibrary
 

SanKakU

Member
Reaction score
21
when i downloaded the test map and replaced the old trigger with this one and deleted the abc library and save the map and tested, i couldn't get in the game but got sent to the warcraft 3 main menu.

i also edited the ability id to be A000 like it is in the test map, should i instead create a new ability object?
 

muzzel

New Member
Reaction score
1
maybe you forgot some functions in map header?

And you dont need to create a new dummy ability, just change the STRIKE_ID in the sourcecode.
 

tanchunhung

New Member
Reaction score
2
How may i Download ABC and a Jass Preceptor

Hey all,
This is one of my first vJass Spell I will be submitting here.
Lightning Strike: Summons lightning from the skies, which crash apon a target Area. The lightning expands, dealing Damage to all enemy Units located in the circle.

Requires: ABC and a Jass Preceptor (New Gen)
Jass/GUI: vJass
MUI: Yes
Leakless: Not of that I am aware of

The Code:
JASS:
scope LightningStrike
//******************************************************************************************************
// How to Implement: Copy and Paste The Spell Lightning Strike                                         *
//                   Copy and Paste this Trigger                                                       *
//                   You Probobly need to change the Rawcode, so go in Object Editor, and Press CTRL+D *
//                   Change "STRIKE_ID" to that Value                                                  *
//                   ABC IS REQUIRED                                                                   *
//******************************************************************************************************
globals
    constant real STRIKE_PERIODIC = 0.05        // This determines the speed of the Timer
    constant integer STRIKE_ID = 'A000'         // This is the Raw Code of the Ability
    constant integer STRIKE_ANGLES = 8          // This is the Number of Angles the Lightning Creates
    constant string STRIKE_LIGHTNING = "CLPB"   // Change this to change the look of the lightning
    constant string STRIKE_SFX_1 = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"              //Special effect 1
    constant string STRIKE_SFX_2 = "Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl"                  //Special effect 2
    constant string STRIKE_SFX_3 = "Abilities\\Weapons\\SpiritOfVengeanceMissile\\SpiritOfVengeanceMissile.mdl"//Special effect 3
    constant string STRIKE_SFX_4 = "Abilities\\Weapons\\Bolt\\BoltImpact.mdl"                                  //Special effect 4
    constant integer STRIKE_RADIUS = 170        // Determines the Max.Radius of the Lightning
    constant integer STRIKE_RADIUS_ADD = 50     // Determines the increment Max.Radius of the lightning  
    constant integer STRIKE_DAMAGE_INIT = 35    // Determines the Damage dealt on cast
    constant integer STRIKE_DAMAGE = 4          // Determines the Damage taken over Time
endglobals

//========= Don't Edit anything under this line unless you know what you are doing ===========================================

private struct Lightning
unit Caster
real Angle
location Target
real TargetX
real TargetY
real TargetLocationX
real TargetLocationY
real TargetX2
real TargetY2
real Alpha
integer Distance
integer Integer
group Group
lightning array Zap[100]
endstruct

//===============Spell RawCode Func======================================
private function Trig_Lightning_Strike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == STRIKE_ID
endfunction

//===============Group Condition Func====================================
private function Trig_Lightning_Strike_Group takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false and IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD) == false
endfunction

//================Timer Function=========================================
private function Trig_Lightning_Strike_Timer takes nothing returns nothing
    local timer Timer = GetExpiredTimer()
    local unit PickedUnit
    local real PickedUnitX
    local real PickedUnitY
    local Lightning Data = GetTimerStructA(Timer)
    
    call GroupEnumUnitsInRange(Data.Group,Data.TargetLocationX,Data.TargetLocationY,Data.Distance,Condition(function Trig_Lightning_Strike_Group))
    loop
        set PickedUnit = FirstOfGroup(Data.Group)
        exitwhen PickedUnit == null
        if IsUnitEnemy(PickedUnit,GetOwningPlayer(Data.Caster)) then
            call UnitDamageTarget(Data.Caster,PickedUnit,STRIKE_DAMAGE,false,true,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_LIGHTNING,WEAPON_TYPE_WHOKNOWS)
            set PickedUnitX = GetUnitX(PickedUnit)
            set PickedUnitY = GetUnitY(PickedUnit)
            call DestroyEffect(AddSpecialEffectLoc(STRIKE_SFX_3,Location(PickedUnitX,PickedUnitY)))
        endif
        call GroupRemoveUnit(Data.Group, PickedUnit)
    endloop
    
    set PickedUnit = null
    
    set Data.Angle = 360/STRIKE_ANGLES
    set Data.Distance = Data.Distance + 14
    set Data.Alpha = Data.Alpha - 0.03
    
    loop
        exitwhen Data.Integer >= STRIKE_ANGLES
        set Data.TargetX = GetLocationX(Data.Target) + Data.Distance * Cos(Data.Angle * bj_DEGTORAD * Data.Integer)
        set Data.TargetY = GetLocationY(Data.Target) + Data.Distance * Sin(Data.Angle * bj_DEGTORAD * Data.Integer)
        set Data.TargetX2 = GetLocationX(Data.Target) + Data.Distance * Cos(Data.Angle * bj_DEGTORAD * (1 + Data.Integer))
        set Data.TargetY2 = GetLocationY(Data.Target) + Data.Distance * Sin(Data.Angle * bj_DEGTORAD * (1 + Data.Integer))
        call MoveLightning(Data.Zap[Data.Integer],false,Data.TargetX,Data.TargetY,Data.TargetX2,Data.TargetY2)
        call SetLightningColor(Data.Zap[Data.Integer],1,1,1,Data.Alpha)
        set Data.Integer = Data.Integer + 1
    endloop
    
    set Data.Integer = 0
    
    if Data.Distance >= STRIKE_RADIUS + STRIKE_RADIUS_ADD * GetUnitAbilityLevel(Data.Caster,STRIKE_ID) then
        loop
            exitwhen Data.Integer >= STRIKE_ANGLES
            call DestroyLightning(Data.Zap[Data.Integer])
            set Data.Integer = Data.Integer + 1
        endloop
        call RemoveLocation(Data.Target)
        set Data.Integer = 0
        call ClearTimerStructA(Timer)
        call Data.destroy()
        call PauseTimer(Timer)
        call DestroyTimer(Timer)
    endif
    set Timer = null
endfunction

//================Main Function==========================================
private function Trig_Lightning_Strike_Actions takes nothing returns nothing
    local Lightning Data = Lightning.create()
    local timer Timer = CreateTimer()
    local unit PickedUnit
    
    set Data.Caster = GetTriggerUnit()
    set Data.Angle = 360/STRIKE_ANGLES
    set Data.Distance = 0
    set Data.Alpha = 1
    set Data.Group = CreateGroup()
    set Data.Target = GetSpellTargetLoc()
    set Data.TargetLocationX = GetLocationX(Data.Target)
    set Data.TargetLocationY = GetLocationY(Data.Target)
    
    call DestroyEffect(AddSpecialEffectLoc(STRIKE_SFX_1,Location(Data.TargetLocationX,Data.TargetLocationY)))
    call DestroyEffect(AddSpecialEffectLoc(STRIKE_SFX_2,Location(Data.TargetLocationX,Data.TargetLocationY)))
    
    call GroupEnumUnitsInRange(Data.Group,Data.TargetLocationX,Data.TargetLocationY,STRIKE_RADIUS + STRIKE_RADIUS_ADD,Condition(function Trig_Lightning_Strike_Group))
    loop
        set PickedUnit = FirstOfGroup(Data.Group)
        exitwhen PickedUnit == null
        if IsUnitEnemy(PickedUnit,GetOwningPlayer(Data.Caster)) then
            call UnitDamageTarget(Data.Caster,PickedUnit,STRIKE_DAMAGE_INIT * GetUnitAbilityLevel(Data.Caster,STRIKE_ID),false,true,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_LIGHTNING,WEAPON_TYPE_WHOKNOWS)
            call DestroyEffect(AddSpecialEffectTarget(STRIKE_SFX_4,PickedUnit,"chest"))
        endif
        call GroupRemoveUnit(Data.Group, PickedUnit)
    endloop
    
    set PickedUnit = null
    
    loop
        exitwhen Data.Integer >= STRIKE_ANGLES
        set Data.TargetX = GetLocationX(Data.Target) + Data.Distance * Cos(Data.Angle * bj_DEGTORAD * Data.Integer)
        set Data.TargetY = GetLocationY(Data.Target) + Data.Distance * Sin(Data.Angle * bj_DEGTORAD * Data.Integer)
        set Data.TargetX2 = GetLocationX(Data.Target) + Data.Distance * Cos(Data.Angle * bj_DEGTORAD * (1 + Data.Integer))
        set Data.TargetY2 = GetLocationY(Data.Target) + Data.Distance * Sin(Data.Angle * bj_DEGTORAD * (1 + Data.Integer))
        set Data.Zap[Data.Integer] = AddLightning(STRIKE_LIGHTNING,false,Data.TargetX,Data.TargetY,Data.TargetX2,Data.TargetY2)
        call SetLightningColor(Data.Zap[Data.Integer],1,1,1,Data.Alpha)
        set Data.Integer = Data.Integer + 1
    endloop
    
    set Data.Integer = 0
    
    call SetTimerStructA(Timer, Data)
    
    call TimerStart(Timer,STRIKE_PERIODIC,true,function Trig_Lightning_Strike_Timer)
endfunction
//===========================================================================
function InitTrig_Lightning_Strike takes nothing returns nothing
    local trigger Lightning_Strike = CreateTrigger(  )
    call Preload("Abilities\\Weapons\\Bolt\\BoltImpact.mdl")
    call Preload("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl")
    call Preload("Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl")
    call Preload("Abilities\\Weapons\\SpiritOfVengeanceMissile\\SpiritOfVengeanceMissile.mdl")
    call TriggerRegisterAnyUnitEventBJ( Lightning_Strike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( Lightning_Strike, Condition( function Trig_Lightning_Strike_Conditions ) )
    call TriggerAddAction( Lightning_Strike, function Trig_Lightning_Strike_Actions )
endfunction
endscope
And a Pic in Action:
Clipboard02-2.jpg

I hope you like it ! Have fun ! =)

Uh oh i dont know where download ABC and a Jass Preceptor (New Gen) so i cant play that!
 

Prince.Zero

New Member
Reaction score
1
JASS:

private function Trig_Lightning_Strike_Group takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false and IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD) == false
endfunction


Could be

JASS:

private function Trig_Lightning_Strike_Group takes nothing returns boolean
    return (not(IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE))) and so on
endfunction


JASS:
if IsUnitEnemy(PickedUnit,GetOwningPlayer(Data.Caster)) then


What if the unit is invisible or something else? You may wanna add more filters, or add some constants at the top regarding filters.
constant boolean HitInvisibles = false

smth like that

JASS:

function InitTrig_Lightning_Strike takes nothing returns nothing


Since you're using vJass, you could rename this to
JASS:
private function init takes nothing returns nothing

and initialize it at the library/scope declaration
JASS:

library MyLightning initializer init



Anyway, cool idea, gj
 

Laiev

Hey Listen!!
Reaction score
188
JASS:
private function Trig_Lightning_Strike_Group takes nothing returns boolean
    return (not(IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE))) and so on
endfunction


could be

JASS:
private function Trig_Lightning_Strike_Group takes nothing returns boolean
    return not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and ...
endfunction


do you know that you're saying things obvious that people know?

since rename function to init and initialize it with library/scope name is the same as leave the name of the trigger

and if you wanna an extra filter, add it :)
 

Prince.Zero

New Member
Reaction score
1
JASS:
private function Trig_Lightning_Strike_Group takes nothing returns boolean
    return (not(IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE))) and so on
endfunction


could be

JASS:
private function Trig_Lightning_Strike_Group takes nothing returns boolean
    return not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and ...
endfunction


do you know that you're saying things obvious that people know?

since rename function to init and initialize it with library/scope name is the same as leave the name of the trigger

and if you wanna an extra filter, add it :)

You don't get it. It isn't about how nice it will look.
It's about the damn import to a map.
If you don't name your trigger the same with the init_trig function
it W-O-N-T work.

So what i stated is some "help" for newbies
 
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