Spell [vJASS] Thunder Storm!

Vestras

Retired
Reaction score
248
Thunder Storm

vJASS: Yes.
GUI/JASS: JASS.
Systems: None.
Import difficulty: Easy-Medium.

"The caster makes multiple lightnings from above, and when they hit a target, the target is damaged. If a target dies while being hit by a lightning, a lightning ripples out from the location of the dying unit, to a random unit in a AoE."

Screenshot:


Code:

JASS:
scope ThunderStorm initializer init

//**************************************
// Thunder Storm Spell By Vestras      *
//                                     *
// Requirements:                       *
//                                     *
// NewGen v1.5a, the abilities, the    *
// dummy.                              *
//                                     *
// Credit me if using this spell.      *
//**************************************

globals
    private constant integer ThunderStorm_SpellID = 'A002'
    // Raw code of the spell.
    private constant integer ThunderStorm_DummyID = 'h000'
    // Raw code of the dummy.
    private constant integer ThunderStorm_DummyAbilID = 'A001'
    // Raw code of the dummy ability.
    private constant real ThunderStorm_AoE = 400.0
    // The AoE of the spell.
    private constant real ThunderStorm_Damage = 50.0
    // The Damage of the spell.
    private constant real ThunderStorm_Time = 5.0
    // The time between each lightning.
    private constant real ThunderStorm_Multi = 2.10
    // The damage multiplier.
    private constant real ThunderStorm_Divide = 3.30
    // The damage divider. Current damage is exactly 30.
    private constant boolean ThunderStorm_Show = true
    // Whether the trigger should show a text message to the player
    // if there are no units in range or not.

    // Below; Needed by the code, don't touch.
    private group ThunderStorm_Group = CreateGroup()
    private unit ThunderStorm_Target = null
    private unit ThunderStorm_Caster = null
    private rect ThunderStorm_Rect = null
endglobals

private constant function ThunderStorm_AttackType takes nothing returns attacktype
    return ATTACK_TYPE_NORMAL // The attack type of the damage
endfunction

private constant function ThunderStorm_DamageType takes nothing returns damagetype
    return DAMAGE_TYPE_UNIVERSAL // The damage type of the damage
endfunction

private constant function ThunderStorm_WeaponType takes nothing returns weapontype
    return WEAPON_TYPE_WHOKNOWS // The weapon type of the damage
endfunction

private constant function ThunderStorm_DamageMulti takes nothing returns real
    return ThunderStorm_Damage * ThunderStorm_Multi / ThunderStorm_Divide 
    // The defined damage times the defined multiplier divided by the defined divider.
endfunction

private function ThunderStorm_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ThunderStorm_SpellID
endfunction

private function ThunderStorm_BefCond2 takes nothing returns nothing
   if ( CountUnitsInGroup(ThunderStorm_Group) <= 0 ) then
         call DisplayTextToPlayer(GetOwningPlayer(ThunderStorm_Caster), 0.5, -0.5, "|cffffcc00No units to Strike.|r")
             if gg_snd_Error != null then
                 call StartSound(gg_snd_Error)
            endif
      endif
endfunction


private function ThunderStorm_ConditionsDies takes nothing returns boolean
   return ( IsUnitInGroup(GetDyingUnit(), ThunderStorm_Group) == true )
endfunction

private function ThunderStorm_GroupDies takes nothing returns nothing
    local unit u = GetEnumUnit()
    local location l = GetUnitLoc(u)
    local unit d = CreateUnitAtLoc(GetOwningPlayer(ThunderStorm_Caster), ThunderStorm_DummyID, l, 0)
    call SetUnitFlyHeight(d, 0.00, 100000000.0)
    call TriggerSleepAction(0.01)
    call UnitAddAbility(d, ThunderStorm_DummyAbilID)
    call IssueTargetOrderById(d, 852587, u) //forkedlightning
    call UnitApplyTimedLife(d, 'BTLF', 0.75)
    call UnitDamageTarget(ThunderStorm_Caster, u, ThunderStorm_DamageMulti(), false, true, ThunderStorm_AttackType(), ThunderStorm_DamageType(), ThunderStorm_WeaponType())
    set d=null
    set u=null
    call RemoveLocation(l)
    set l = null
endfunction

private function ThunderStorm_ActionsDies takes nothing returns nothing
     local unit d = GetDyingUnit()
     local unit u = ThunderStorm_Caster
     local group g2 = GetRandomSubGroup(1, ThunderStorm_Group)
            call ForGroup(g2, function ThunderStorm_GroupDies)
                 if ( ThunderStorm_Show == true ) then
                  call ThunderStorm_BefCond2()
        endif
endfunction

private function initdies takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddCondition(t, Condition(function ThunderStorm_ConditionsDies))
    call TriggerAddAction(t, function ThunderStorm_ActionsDies)
endfunction

private function ThunderStorm_GroupActions takes nothing returns nothing
    local unit u = GetEnumUnit()
    local unit d = CreateUnit(GetOwningPlayer(ThunderStorm_Caster), ThunderStorm_DummyID, GetRandomReal(GetRectMinX(ThunderStorm_Rect),GetRectMaxX(ThunderStorm_Rect)), GetRandomReal(GetRectMinY(ThunderStorm_Rect),GetRectMaxY(ThunderStorm_Rect)), 0)
    call UnitAddAbility(d, ThunderStorm_DummyAbilID)
    call IssueTargetOrderById(d, 852587, u) //forkedlightning
    call UnitApplyTimedLife(d, 'BTLF', 0.75)
    call UnitDamageTarget(ThunderStorm_Caster, u, ThunderStorm_DamageMulti(), false, true, ThunderStorm_AttackType(), ThunderStorm_DamageType(), ThunderStorm_WeaponType())
    set d=null
    set u=null
    call initdies()
endfunction

private function ThunderStorm_GroupConditions takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true ) and ( IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false ) and ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(ThunderStorm_Caster)) == true )
endfunction

private function ThunderStorm_BefCond1 takes nothing returns nothing
   if ( CountUnitsInGroup(ThunderStorm_Group) <= 0 ) then
         call DisplayTextToPlayer(GetOwningPlayer(ThunderStorm_Caster), 0.5, -0.5, "|cffffcc00No units to Strike.|r")
             if gg_snd_Error != null then
                 call StartSound(gg_snd_Error)
            endif
      endif
endfunction

private function ThunderStorm_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local location l = GetUnitLoc(u)
    set ThunderStorm_Caster = u
    set ThunderStorm_Rect = Rect( x - ThunderStorm_AoE*0.5, y - ThunderStorm_AoE*0.5, x + ThunderStorm_AoE*0.5, y + ThunderStorm_AoE*0.5 )
        set ThunderStorm_Group = GetUnitsInRangeOfLocMatching(ThunderStorm_AoE, l, Condition(function ThunderStorm_GroupConditions))
          call ForGroup(ThunderStorm_Group, function ThunderStorm_GroupActions)
            if ( ThunderStorm_Show == true ) then
                  call ThunderStorm_BefCond1()
        endif
      call GroupClear(ThunderStorm_Group)
      call RemoveRect(ThunderStorm_Rect)
    set u = null
endfunction

//================================================== =========================
private function init takes nothing returns nothing
    local trigger t = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function ThunderStorm_Conditions))
    call TriggerAddAction(t, function ThunderStorm_Actions)
endfunction

endscope

Enjoy..
 
Reaction score
456
(these are in misc order, because I just wrote what I noticed next and blabbablaba)

1.
The members are private, you can remove the ThunderStorm suffix from them.

2.
JASS:
call SetUnitFlyHeight(d, 0.00, 100000000.0)

Use 0.00 for rate, so it's instant.

3.
JASS:
    local location l = GetUnitLoc(u)
    local unit d = CreateUnitAtLoc(GetOwningPlayer(ThunderStorm_Caster), ThunderStorm_DummyID, l, 0)

Use reals instead.

4.
There is a wait in a callback function called "ThunderStorm_GroupDies".

5.
JASS:
    call IssueTargetOrderById(d, 852587, u) //forkedlightning

The order should be constant string.

6.
You were planning to get rid of the location leak in "ThunderStorm_Actions", right?

..

Too tired of writing more. Just remember, quality over quantity, think before doing. You can do mucha better.
 

Vestras

Retired
Reaction score
248
1 - It makes them more personal, it's intended.
2 - didn't know that.
3 - duh
4 - Intended.
5 - okay.
6 - Is there one?

> Too tired of writing more. Just remember, quality over quantity, think before doing. You can do mucha better.

I used two days on this spell..
 
Reaction score
456
1. If you want to keep the ThunderStorm suffix, why are the members private then?

4. You do know that waits in callbacks are usually not okay?

6. Look carefully.

>I used two days on this spell..
I did not mean that it's bad quality. But spell is perfect only when it cannot be improved =).
 

Vestras

Retired
Reaction score
248
1. If you want to keep the ThunderStorm suffix, why are the members private then?

4. You do know that waits in callbacks are usually not okay?

6. Look carefully.

>I used two days on this spell..
I did not mean that it's bad quality. But spell is perfect only when it cannot be improved =).

> I did not mean that it's bad quality. But spell is perfect only when it cannot be improved =).
And that's never :)

1 - Dunno.

4 - No?

6 - ah, crap.
 

emjlr3

Change can be a good thing
Reaction score
395
u never removed your location l

also, it seems like this whole spell could have been done in one function, yet you used an ass load, why?
 

Vestras

Retired
Reaction score
248
u never removed your location l

also, it seems like this whole spell could have been done in one function, yet you used an ass load, why?

Because there also comes lightnings when they die.
I figured that leak out :)
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
also, it seems like this whole spell could have been done in one function, yet you used an ass load, why?

Second.

One thing, why on earth are you using seperate functions for the Damagetypes etc?
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
This could still be rewritten using about 1/10 the amount of functions you're using here. Other than that I guess it's a fairly decent spell.
 

soulreaping

New Member
Reaction score
17
Wow, you were actually using IsUnitAliveBJ and GetUnitsInRangeOfLocMatching.

BJs = bad and you used a few more.

Inline them because they slow down.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
There is always ways to work your way around the BJs (at least most of the times)
JASS:

if GetWidgetLife (widget) > .405 then


If I recall correctly that's how to check wether a unit is alive or not.
 

Flare

Stops copies me!
Reaction score
662
> I know. There isn't natives for them.

Use the TESH function list. It's there to be used. If you notice, there is a native for GetUnitsInRangeOfLocMatching. Apart from a few exceptions, all BJ's call a native (there are 2 text tag BJs that don't call another function, but do a little math instead)

JASS:
function GetUnitsInRangeOfLocMatching takes real radius, location whichLocation, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRangeOfLoc(g, whichLocation, radius, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction


Looks nice from screenshot, I'll try it out later when I have more time

Also:
JASS:
//**************************************
// Thunder Storm Spell By Vestras      *
//                                     *
// Requirements:                       *
//                                     *
// NewGen v1.5a, the abilities, the    *
// dummy.                              *
//                                     *
// Credit me if using this spell.      *
//**************************************


What abilities exactly? What dummies exactly? You should give the exact WE name of the spells. You should elaborate on how exactly someone would go about importing the spell successfully (like changing rawcodes around, and other seemingly small but important things :))

I used two days on this spell..

Your point? :p
 
1

131ackout

Guest
the ability

its all right

but blue lightning?

makes more of like a frost lightning storm
 
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