Spell Lightning Blast Ball

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
vJass: Yes.
MUI: Yes.
Laggless: Yes.
Leakless: Yes
Requires: NewGen Editor

Description: (Is copied from tooltip)
Summons a lightning ball that moves towards a target point enlarging and moves upwards.
When the ball reaches its target it crashes down and deals damage in an AoE

The damage increases the further from the caster the target is.
Screenshot:
LightningBallBlastMove.jpg


LightningBallBlastNova.jpg
Code:
JASS:
struct LightningBlastBall // Requires TimerUtils 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//              Implementing Instructions:
//  1: Create a trigger named LightningBlastBall and copy all this code into that trigger.
//  2: Import TimerUtils if you haven't them already imported into your map already.
//  3: Create the dummy unit and the ability
//  4: Set the SPELL_ID and DUMMY_ID to the ID's of your created dummy and ability.
//  5: Configure the spell the way you want it.
//
//
//  WARNING: If you see that the handle amount goes up in the handle counter that is NOT because this spell leaks.
//           It is because I do not remove the units, I kill them and then lets WC3 take care of them as they should be taken care of
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Configuration vars:
    private static constant integer SPELL_ID = 'A000' //the ID of the spell.   
    private static constant integer DUMMY_ID = 'h001' // the dummys ID
    
    private static constant real TIMER_PERIOD = 0.025      // How often the timer runs, increasing this will lower the speed of the balls.
    private static constant real SPEED = 10                // The speed of the lightning ball.
    private static constant real DAMAGE_INCREASE = 1.6     // This value is used to calculate the damage, the damage is calculated this way
                                                           // lvl*DAMAGE_INCREASE
    private static constant real HEIGHT_INCREASE = 7       // How much the dummy's height increases per interval.
    private static constant real DROP_SPEED_INCREASE = 7   // How much the drop speed increases per interval

    private static constant real START_SCALING = 0.40      // The size of the unit when the spell starts
    private static constant real SCALE_INCREASE = 0.03     // How much the units size increases every interval  
    
    private static constant real NOVA_RADIUS = 300         // The size of the nova that units gets damaged inside.
    private static constant integer NOVA_DUMMY_AMOUNT = 20 // The amount of dummies used in the Nova.
    private static constant real NOVA_SPEED = 15           // The speed of the units in the nova.
    private static constant real DAMAGE_RADIUS = 30        // The radius around the nova units that get damaged.
    private static constant real NOVA_DUMMY_SIZE = 8       // The size of the dummies used in the nova.
    
    private static constant string SOUND_PATH = "Abilities\\Spells\\Human\\StormBolt\\ThunderBoltMissileDeath.wav"
                                                           // The sound you want this spell to use.
    
// The damage filter, Edit this to make it target the types of units you want to
    private static constant method DamageFilter takes unit caster, unit target returns boolean
        return (IsUnitEnemy(target, GetOwningPlayer(caster))) and (IsUnitType(target, UNIT_TYPE_GROUND)) and (GetUnitState(target, UNIT_STATE_LIFE) > 0.405)
    endmethod 
    
// The Damage amount this spell deas, edit this to configure the damage you want it to deal.
    private static constant method DamageAmount takes integer lvl returns real
        return lvl*.DAMAGE_INCREASE
    endmethod

// Don't edit below this line if you don't know what you're doing.
        private static boolexpr RETURN_TRUE
        private static location globalLoc = Location(0,0)
        private static LightningBlastBall array LBB
        private real currX
        private real currY
        private real distdone = 0
        private real totaldist
        private real cos
        private real sin
        private real angle
        private real currheight = 0
        private real totaldrop
        private unit whichUnit
        private real currscale = .START_SCALING
        private real dropspeed = .DROP_SPEED_INCREASE
        private unit damager
        private real currdamage = 0
        private unit array novaUnits[.NOVA_DUMMY_AMOUNT]
        private real array novasin[.NOVA_DUMMY_AMOUNT]
        private real array novacos[.NOVA_DUMMY_AMOUNT]
        private real array novaUnitsX[.NOVA_DUMMY_AMOUNT]
        private real array novaUnitsY[.NOVA_DUMMY_AMOUNT]
        private boolean novaStarted = false
        private group damagedUnits
        private timer t
        
    private static method H2I takes handle h returns integer i
        return h
        return 0
    endmethod
    
    private static method create takes nothing returns LightningBlastBall
        local LightningBlastBall LBBT = .allocate()
        set LBBT.damagedUnits = CreateGroup()
        return LBBT
    endmethod
    
    private method onDestroy takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i >= .NOVA_DUMMY_AMOUNT
            call ShowUnit(.novaUnits<i>, false)
            call KillUnit(.novaUnits<i>)
            set .novaUnits<i> = null
            set i = i+1
        endloop
        call DestroyGroup(.damagedUnits)
        set .damagedUnits = null
        set .whichUnit = null
        set .damager = null
        call ReleaseTimer(.t)
    endmethod

    private static method Nova takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local LightningBlastBall l = .LBB[.H2I(t)-0x100000]
        local real totalAngle = 0
        local real between
        local integer i = 0
        local real scale = (l.currscale/.NOVA_DUMMY_AMOUNT)*.NOVA_DUMMY_SIZE
        local group unitsInRange = CreateGroup()
        local unit u
        if l.novaStarted == false then
            set between = 360/.NOVA_DUMMY_AMOUNT
            loop
                exitwhen totalAngle &gt;= 360
                set l.novacos<i> = .NOVA_SPEED * Cos(bj_DEGTORAD * totalAngle)
                set l.novasin<i> = .NOVA_SPEED * Sin(bj_DEGTORAD * totalAngle)
                set l.novaUnits<i> = CreateUnit(GetOwningPlayer(l.damager), .DUMMY_ID, l.currX, l.currY, totalAngle)
                set l.novaUnitsX<i> = GetUnitX(l.novaUnits<i>)
                set l.novaUnitsY<i> = GetUnitY(l.novaUnits<i>)
                call SetUnitScale(l.novaUnits<i>, scale,scale,scale)
                set totalAngle = totalAngle+between
                set i = i+1
            endloop
            set i = 1
            set l.novaStarted = true
        endif
        if l.distdone &gt;= .NOVA_RADIUS then                
            call l.destroy()
        else
            loop
                exitwhen i &gt;= .NOVA_DUMMY_AMOUNT
                set l.novaUnitsX<i> = l.novaUnitsX<i> + l.novacos<i>
                set l.novaUnitsY<i> = l.novaUnitsY<i> + l.novasin<i>
                call SetUnitX(l.novaUnits<i>, l.novaUnitsX<i>)
                call SetUnitY(l.novaUnits<i>, l.novaUnitsY<i>)
                call GroupClear(unitsInRange)
                call GroupEnumUnitsInRange(unitsInRange, l.novaUnitsX<i>, l.novaUnitsY<i>, .DAMAGE_RADIUS, .RETURN_TRUE)
                loop
                    set u = FirstOfGroup(unitsInRange)
                    exitwhen u == null
                    if .DamageFilter(l.damager, u) == true and IsUnitInGroup(u, l.damagedUnits) == false then
                        call UnitDamageTarget(l.damager, u, l.currdamage , false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null)
                    endif
                    call GroupRemoveUnit(unitsInRange, u)
                    call GroupAddUnit(l.damagedUnits, u)
                    set u = null
                endloop
                set i = i+1
            endloop
            set l.distdone = l.distdone + .NOVA_SPEED
        endif
        set unitsInRange = null
        set u = null
        set t = null
    endmethod
    
    private static method Drop takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local sound s
        local LightningBlastBall l = .LBB[.H2I(t)-0x100000]
        if l.currheight &gt;= l.totaldrop-.DROP_SPEED_INCREASE then
            set l.distdone = 0
            call PauseTimer(l.t)
            call TimerStart(l.t, .TIMER_PERIOD, true, function LightningBlastBall.Nova)
            call ShowUnit(l.whichUnit, false)
            call KillUnit(l.whichUnit)
            set s = CreateSound(.SOUND_PATH, false, true, true, 0,0,&quot;a&quot;)
            call SetSoundPosition(s, l.currX, l.currY, 0)
            call SetSoundVolume(s, 110)
            if (s != null) then
                call StartSound(s)
            endif
            call KillSoundWhenDone(s)
        else
            call SetUnitFlyHeight(l.whichUnit, l.totaldrop-l.currheight, 0)
            set l.currheight = l.currheight + l.dropspeed
            set l.dropspeed = l.dropspeed + .DROP_SPEED_INCREASE
        endif
        set t = null
        set s = null
    endmethod
    
    private static method TimerAct takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local LightningBlastBall l = .LBB[.H2I(t)-0x100000]
        if l.distdone &gt;= l.totaldist then
            set l.totaldrop = l.currheight
            set l.currheight = 0
            call PauseTimer(l.t)
            call TimerStart(l.t, .TIMER_PERIOD, true, function LightningBlastBall.Drop)
        else
            set l.currX = l.currX + l.cos
            set l.currY = l.currY + l.sin
            call SetUnitX(l.whichUnit, l.currX)
            call SetUnitY(l.whichUnit, l.currY)
            call SetUnitFlyHeight(l.whichUnit, l.currheight, 0)
            call SetUnitScale(l.whichUnit, l.currscale , l.currscale , l.currscale)
            set l.currscale = l.currscale + .SCALE_INCREASE
            set l.distdone = l.distdone + .SPEED
            set l.currheight = l.currheight + .HEIGHT_INCREASE
            set l.currdamage = l.currdamage + .DamageAmount(GetUnitAbilityLevel(l.damager, .SPELL_ID))
        endif
        set t = null
    endmethod
    
    private static method Actions takes nothing returns nothing
        local real tarx 
        local real tary
        local LightningBlastBall l = .create()
        local unit caster = GetSpellAbilityUnit()
        set l.t = NewTimer()
        set l.damager = caster
        set .globalLoc = GetSpellTargetLoc()
        set tarx = GetLocationX(.globalLoc)
        set tary = GetLocationY(.globalLoc)
        set l.currX = GetUnitX(caster)
        set l.currY = GetUnitY(caster)
        set l.angle = Atan2((tary - l.currY), (tarx - l.currX))
        set l.totaldist = SquareRoot((tarx-l.currX)*(tarx-l.currX) + (tary-l.currY)*(tary-l.currY))
        set l.sin = .SPEED * Sin(l.angle)
        set l.cos = .SPEED * Cos(l.angle)
        set l.whichUnit = CreateUnit(GetOwningPlayer(caster), .DUMMY_ID, l.currX, l.currY, l.angle*bj_RADTODEG)
        call SetUnitScale(l.whichUnit, .START_SCALING , .START_SCALING , .START_SCALING)
        set .LBB[.H2I(l.t)-0x100000] = l
        call TimerStart(l.t, .TIMER_PERIOD, true, function LightningBlastBall.TimerAct)
        set caster = null
        call RemoveLocation(.globalLoc)
        set .globalLoc = null
    endmethod
    
    private static method Cond takes nothing returns boolean
        return GetSpellAbilityId() == .SPELL_ID
    endmethod
    
    private static method BoolexprReturnTrue takes nothing returns boolean
        return true
    endmethod
    
    private static method onInit takes nothing returns nothing
        local trigger Trig = CreateTrigger()
        local integer i = 0
        set .RETURN_TRUE=Condition(function LightningBlastBall.BoolexprReturnTrue)
        loop
            call TriggerRegisterPlayerUnitEvent(Trig, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i+1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(Trig, Condition(function LightningBlastBall.Cond))
        call TriggerAddAction(Trig, function LightningBlastBall.Actions)

        endmethod
endstruct</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

Attachments

  • LightningBlastBall.w3x
    66.9 KB · Views: 343

Flare

Stops copies me!
Reaction score
662
Hmm, that's alot of code... I think I'll just wait for the screenshot :D

One thing that I noticed from the code though
JASS:
        loop
            call TriggerRegisterPlayerUnitEvent(Trig, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i+1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop


Why bother doing all that if you're still going to pass a null argument for the filter in TriggerRegisterPlayerUnitEvent? Not exactly a huge deal, but it's excessive work when you're just doing what the BJ is doing (and to be perfectly honest, the AnyUnitEventBJ isn't very bad)
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
I didn't feel like using the BJ, that would be the only BJ if I did :D
And I just copy pasted only changed "index" to "i" and added the event :p

Edit - Uploaded screenshots.
 

UndeadDragon

Super Moderator
Reaction score
447
I found a problem with the spell. After I cast it a lot of times repeatedly, for some reason, all the units that were made got re-created and they just stayed there. I got a screenshot below:

spellproblemgl6.jpg
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Fuck I must have uploaded wrong version..

They stay because the map recreates enemys for testing purpose lol. But somehow the dummies also got recreated.

Edit - In the uploaded version the if statement that should make the dummys not being recreated used a or instead of a and.. how nice.

Changed
 

UndeadDragon

Super Moderator
Reaction score
447
Yes, that would probably explain it.
 

Vestras

Retired
Reaction score
249
Haven't tested it yet, but personally I think that using methods for spells s pretty dumb, (no offense) like textmacros in spells, aye?
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Now when I tried it I actully liked it more then the usual way. It feels more ordered and I don't need to declare a extra struct :p
 

Flare

Stops copies me!
Reaction score
662
There's nothing wrong with using methods for it (apart from the long prefixes for stuff) but it looks awesome :D And there's nothing really bad about using textmacros in spells, especially if you want to quickly make a long list of similar things (like a series of elseif's that check a destructable type, for example), unless of course you're doing something stupid (like using a textmacro within a function, and said textmacro creates a new function)

Also,
Code:
call TimerStart(t, [B]0.025[/B], true, function LightningBlastBall.TimerAct)
Should be configurable, same applies in your TimerAct method - some people may need the timers to run at a higher frequency to avoid lag (not sure how much of a difference 0.5-1 sec will make)
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Ok I'll add that.

And I found out yesterday that you do not need to prefix static members inside a struct... All my copy and paste of the struct name was useless. :(

The only time static members needs to be prefixed inside a struct is: Timers, Conditions/Actions and when you create objects of the type of course. (This is what I found out in this spell.)

I will upload the edited version when more feedback comes.
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Added a onInit method to the struct so it doesn't need to be placed in a trigger named exactly the right name.
 

Drunken_God

Hopes to get back into Mapmaking with SC2 :)
Reaction score
106
hmm
could it be that your dummies have the worker classifcation?
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
I'm pretty sure that the user that uses this spell creates his own dummies.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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