Spell Laser

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
I was kinda bored, watch over youtube, and made a very simple spell similar to the funny video I watched.

LASER v1.2a

Requires:
JassNewGen
TimerUtils

Description:
The dreadlord creates lightning towards the target up to a long range, damaging enemy units that will be hit.

Screenshots:
spellshot.jpg

Code:
JASS:
//////////////////////////////////
//LASER v1.2                    //
//    by: Nherwyziant           //
//==============================//
//Requires:                     //
//    T32                       //
//    GT                        //
//    Recycle                   //
//==============================//
//Credits:                      //
//    Jesus4Lyf                 //
//    Nestharus                 //
//    Vexorian                  //
//==============================//
//How to copy                   //
//    Copy the dummy unit       //
//    Copy the codes below      //
//    Set values to the desired //
//////////////////////////////////

scope Laser

    native UnitAlive takes unit id returns boolean

    globals
        private constant integer    RAWCODE     = 'A000'            //~Spell Rawcode
        private constant integer    DUMMY       = 'h000'            //~Shadow Dummy Rawcode
        
        private constant string     L_FX        = "AFOD"            //~The lightning effect
        private constant string     L_FX2       = "Abilities\\Weapons\\LavaSpawnMissile\\LavaSpawnMissile.mdl"           //~The effect on the happy trails
        private constant string     L_FX3       = "Abilities\\Weapons\\DemolisherFireMissile\\DemolisherFireMissile.mdl" //~The effect on hit
        private constant string     ANIMATION   = "spell third"     //The animation of the shadow
        
        private constant real       L_HEIGHT    = 225               //~Height of lightning.  Just right for Balnazzar <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
        private constant real       AOE         = 150               //~AoE of lightning
        private constant real       DURATION    = .75               //~DURATION OF SPELL ^___^
        private constant real       SHADOWLIFE  = 2.5               //~The duration of the shadow
        
        private constant attacktype ATK_TYPE    = ATTACK_TYPE_HERO  //~Attack type
        private constant damagetype DMG_TYPE    = DAMAGE_TYPE_MAGIC //~Damage type
    endglobals
    
    private function RANGE takes integer lvl returns real
        return 1000. + (lvl * 500.)
    endfunction
    
    private function DMG takes integer lvl returns real
        return lvl * 75.
    endfunction
    
//Do not touch the remaining part, or else you will be a victim of a killer.

    
    private struct Data
    
        private static group            GROUP   = CreateGroup()
        private static thistype         this
        private static conditionfunc    cf
        
        unit caster
        unit shadow
        player p
        group dmgUnits
        real x
        real y
        real z
        real tx
        real ty
        real tz
        real angle
        real range
        real speed
        real dmg
        real cos
        real sin
        integer lvl
        integer ticks
        lightning l
        
        private static method DoDamage takes nothing returns boolean
            local thistype  this    = thistype.this
            local unit      u       = GetFilterUnit()
            if IsUnitEnemy(u,.p) and UnitAlive(u) and IsUnitType(u,UNIT_TYPE_STRUCTURE) == false and not IsUnitInGroup(u,.dmgUnits) then
                call UnitDamageTarget(.caster,u,.dmg,true,false,ATK_TYPE,DMG_TYPE,null)
                call DestroyEffect(AddSpecialEffectTarget(L_FX3,u,&quot;origin&quot;))
                call GroupAddUnit(.dmgUnits,u)
            endif
            return false
        endmethod
        
        private method periodic takes nothing returns nothing
            if .ticks &gt;= T32_Tick then
                set .tx = .tx + .cos
                set .ty = .ty + .sin
                set .tz = GetLocationZ(Location(.tx,.ty))
                if UnitAlive(.caster) then
                    call MoveLightningEx(.l,true,.x,.y,.z,.tx,.ty,.tz)
                    call DestroyEffect(AddSpecialEffect(L_FX2,.tx,.ty))
                    set thistype.this = this
                    call GroupEnumUnitsInRange(thistype.GROUP,.tx,.ty,AOE,thistype.cf)
                else
                    call DestroyLightning(.l)
                endif
            else
                call DestroyLightning(.l)
                call Group.release(.dmgUnits)
                set .caster = null
                set .l = null
            endif
        
        endmethod
        
        implement T32x
        
        private static method Action takes nothing returns boolean
            local thistype this = thistype.create()

            set .caster     = GetTriggerUnit()
            set .p          = GetOwningPlayer(.caster)
            set .x          = GetUnitX(.caster)
            set .y          = GetUnitY(.caster)
            set .z          = GetLocationZ(Location(.x,.y)) + L_HEIGHT + GetUnitFlyHeight(.caster)
            set .tx         = GetSpellTargetX()
            set .ty         = GetSpellTargetY()
            set .tz         = GetLocationZ(Location(.tx,.ty))
            set .lvl        = GetUnitAbilityLevel(.caster,RAWCODE)
            set .angle      = Atan2(.ty-.y,.tx-.x)
            set .range      = RANGE(.lvl)
            set .speed      = .range / R2I(DURATION/T32_PERIOD)
            set .dmg        = DMG(.lvl)
            set .cos        = .speed * Cos(.angle)
            set .sin        = .speed * Sin(.angle)
            set .l          = AddLightningEx(L_FX,true,.x,.y,.z,.x,.y,.tz)
            set .ticks      = T32_Tick + R2I(DURATION/T32_PERIOD)
            set .dmgUnits   = Group.get()
            set .tx         = .x
            set .ty         = .y
            
            call .startPeriodic()
            

            return false
        endmethod
        
        private static method Action2 takes nothing returns boolean
            local thistype this = thistype.create()
            set .caster         = GetTriggerUnit()
            set .p              = GetOwningPlayer(.caster)
            set .x              = GetUnitX(.caster)
            set .y              = GetUnitY(.caster)
            set .tx             = GetSpellTargetX()
            set .ty             = GetSpellTargetY()
            set .angle          = Atan2(.ty-.y,.tx-.x)
            set .shadow         = CreateUnit(.p,DUMMY,.x,.y,.angle*bj_RADTODEG)
            
            call SetUnitAnimation(.shadow,ANIMATION)
            call SetUnitVertexColor(.shadow,100,100,100,50)
            call SetUnitScale(.shadow,1.5,1.5,1.5)
            call UnitApplyTimedLife(.shadow,&#039;BTLF&#039;,SHADOWLIFE)
            call UnitAddAbility(.shadow,&#039;Amrf&#039;)
            call UnitRemoveAbility(.shadow,&#039;Amrf&#039;)
            call SetUnitFlyHeight(.shadow,GetUnitFlyHeight(.caster),0)
            
            //Optional only.==========================================================//
            call PlaySoundAtPointBJ(gg_snd_Ama_Firen_Mah_Lazar,100,Location(.x,.y),.z)         
            //========================================================================//
            
            set .shadow         = null
            set .caster         = null
            return false
        endmethod

        private static method onInit takes nothing returns nothing
            call GT_AddStartsEffectAction(function thistype.Action,RAWCODE)
            call GT_AddBeginsCastingAction(function thistype.Action2,RAWCODE)
            
            set thistype.cf = Condition(function thistype.DoDamage)
        endmethod

    endstruct
    
endscope

Changelog
v1.2a added .stopPeriodic()
v1.2 Fix bug when hero has different fly height, and more.
v1.1 Spell Makeover :D tnx to Kingkingyyk3 d(^.^)b
v1.0 Initial Release

NOTE: Made in 1.24. Spell recoded for better. If you found a problem with this spell, or a suggestion, just comment below :D
 

Executor

I see you
Reaction score
57
So, this is a nice looking shockwave ? :p

Hm, but I like the the cast animation, what about letting him not fire a line but half a circle:

JASS:
.
                                                  1
                                                    2
                                                      3
                                                        4
&lt;Caster&gt;                                                X Target Point
                                                        5
                                                      6
                                                   7

1-7: hit 1 first and 7 last.


Instead of TimerUtils : T32 and linked list?

JASS:
...
        set d.ul = GetUnitLoc(d.u)
        set d.ll = GetUnitLoc(d.u)
        set d.tl = GetSpellTargetLoc()
        set d.tf = bj_RADTODEG * Atan2(GetLocationY(d.tl) - GetLocationY(d.ul), GetLocationX(d.tl) - GetLocationX(d.ul))
        set x = GetLocationX(d.ul) + 2000 * Cos(d.tf * bj_DEGTORAD)
        set y = GetLocationY(d.ul) + 2000 * Sin(d.tf * bj_DEGTORAD)
        set d.d = Location(x,y)
        set d.l = AddLightningEx(FX, true, GetLocationX(d.ul), GetLocationY(d.ul), GetLocationZ(d.ul)+225,GetLocationX(d.ul), GetLocationY(d.ul), GetLocationZ(d.ul))
        // real x, real y? faster? no possible leak?
...


JASS:
...
        call PlaySoundAtPointBJ(gg_snd_Ama_Firen_Mah_Lazar,100,l,0)
        call CreateTextTagUnitBJ( &quot;Ama Firen Mah Lazar&quot;,u,0,10,100,100,100,0)
        call SetTextTagPermanentBJ(bj_lastCreatedTextTag,false)
        call SetTextTagLifespanBJ(bj_lastCreatedTextTag,2)
        call SetTextTagFadepointBJ(bj_lastCreatedTextTag,1)
        call SetTextTagVelocityBJ(bj_lastCreatedTextTag,64,90)
...

native SetTextTagPermanent(tt, flag)
native SetTextTagLifespan(tt, lifespan)
native SetTextTagFadepoint(tt, fadepoint)
// their BJs ONLY wrap


JASS:
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)

            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function cond))
        call TriggerAddAction(t, function Action)
        
        set t = CreateTrigger()
        set i = 0
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i),EVENT_PLAYER_UNIT_SPELL_CHANNEL,null)

            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function cond))
        call TriggerAddAction(t, function Actions)
        // in one loop? and are both events needed?!


JASS:
CheckMe(d.ll) == false
not CheckMe(d.ll)


JASS:
    private function CheckMe takes location dist returns boolean
        if GetLocationX(dist) &lt; MaxX and GetLocationX(dist) &gt; MinX and GetLocationY(dist) &lt; MaxY and GetLocationY(dist) &gt; MinY then
            return true
        else
            return false
        endif
    endfunction

    private function CheckMe takes location dist returns boolean
        return GetLocationX(dist) &lt; MaxX and GetLocationX(dist) &gt; MinX and GetLocationY(dist) &lt; MaxY and GetLocationY(dist) &gt; MinY
    endfunction



JASS:
//Range is constant 2000,       //
//due to some reason.           //
//I&#039;ll try to fix this soon.    //

        set x = GetLocationX(d.ul) + 2000 * Cos(d.tf * bj_DEGTORAD)
        set y = GetLocationY(d.ul) + 2000 * Sin(d.tf * bj_DEGTORAD)


JASS:
set d.tf = bj_RADTODEG * Atan2(GetLocationY(d.tl) - GetLocationY(d.ul), GetLocationX(d.tl) - GetLocationX(d.ul))
// if you would remove this bj_RADTODEG, you could remove every bj_DEGTORAD <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile    :)" loading="lazy" data-shortname=":)" />
set x = GetLocationX(d.ul) + 2000 * Cos(d.tf * bj_DEGTORAD)
set y = GetLocationY(d.ul) + 2000 * Sin(d.tf * bj_DEGTORAD)


And your spell lags, so why not use the 'normal' period of 0.03125?

JASS:
...
        private constant real INCREMENT     = 25          //~The spell speed
        private constant real TIMEOUT       = 0.03125        //~The spell timer

        private constant real TIMEOUT       = 0.03125     //~The spell timer
        private constant real INCREMENT     = 800 * TIMEOUT //~The spell speed

        // the same speed, but now you can modify TIMEOUT without changing the speed.
...
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
ya, i know about that constant range, i'm trying to calculate the time for the animation and the time for moving thingy, so I can give a different range for it :) lemme fix those things later, or tomorrow. Kinda busy.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
scope Laser
//Requires T32, GT, Recycle
    native UnitAlive takes unit id returns boolean
    
    globals
        private constant integer RAWCODE    = &#039;A000&#039;      //~The spell rawcode
        private constant string FX          = &quot;AFOD&quot;      //~The lightning effect
        private constant string FX2         = &quot;Abilities\\Weapons\\LavaSpawnMissile\\LavaSpawnMissile.mdl&quot;            //~The effect when lightning is moving
        private constant string FX3         = &quot;Abilities\\Weapons\\DemolisherFireMissile\\DemolisherFireMissile.mdl&quot;           //~The effect when enemy is hit
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_HERO
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_MAGIC
    endglobals
    
    private function Damage takes integer lvl returns real
        return 75. * lvl
    endfunction
    
    private function AoE takes integer lvl returns real
        return 150. + (0. * lvl)
    endfunction
    
    private function Speed takes integer lvl returns real
        return 800. + (0. * lvl)
    endfunction
    
    private struct Data
        private static group enumGroup = CreateGroup()
        private static conditionfunc cf
        private static thistype this
        unit cs
        real x
        real y
        real tx
        real ty
        real damage
        real aoe
        real spd
        real cos
        real sin
        real angle
        real dx
        real dy
        integer lv
        integer tick
        group damagedUnits
        lightning l
        player p
        
        private static method Effects takes nothing returns boolean
            local thistype this = thistype.this
            local unit u = GetFilterUnit()
            if IsUnitEnemy(u,.p) and UnitAlive(u) and IsUnitType(u,UNIT_TYPE_STRUCTURE) == false and not IsUnitInGroup(u,.damagedUnits) then
                call UnitDamageTarget(.cs,u,.damage,false,false,ATTACK_TYPE,DAMAGE_TYPE,null)
                call DestroyEffect(AddSpecialEffectTarget(FX3,u,&quot;origin&quot;))
                call GroupAddUnit(.damagedUnits,u)
            endif
            return false
        endmethod
        
        private method periodic takes nothing returns nothing
            if .tick &gt;= T32_Tick then
                set .tx = .tx + .cos
                set .ty = .ty + .sin
                call MoveLightning(.l,true,.x,.y,.tx,.ty)
                call DestroyEffect(AddSpecialEffect(FX2,.tx,.ty))
                set thistype.this = this
                call GroupEnumUnitsInRange(thistype.enumGroup,.tx,.ty,.aoe,thistype.cf)
            else
                call DestroyLightning(.l)
                call Group.release(.damagedUnits)
                set .l = null
            endif
        endmethod
        
        implement T32x
        
        private static method act takes nothing returns boolean
            local thistype this = thistype.create()
            set .cs = GetTriggerUnit()
            set .x = GetUnitX(.cs)
            set .y = GetUnitY(.cs)
            set .tx = GetSpellTargetX()
            set .ty = GetSpellTargetY()
            set .lv = GetUnitAbilityLevel(.cs,RAWCODE)
            set .damage = Damage(.lv)
            set .aoe = AoE(.lv)
            set .spd = Speed(.lv) / T32_FPS
            set .dy = .ty - .y
            set .dx = .tx - .x
            set .angle = Atan2(.dy,.dx)
            set .cos = .spd * Cos(.angle)
            set .sin = .spd * Sin(.angle)
            set .l = AddLightning(FX,true,.x,.y,.x,.y)
            set .damagedUnits = Group.get()
            set .tick = T32_Tick + R2I(SquareRoot(.dx * .dx + .dy * .dy) / .spd)
            set .tx = .x
            set .ty = .y
            set .p = GetOwningPlayer(.cs)
            call .startPeriodic()
            return false
        endmethod
        
        private static method onInit takes nothing returns nothing
            call GT_AddStartsEffectAction(function thistype.act, RAWCODE)
            
            set thistype.cf = Condition(function thistype.Effects)
        endmethod
    endstruct

endscope

Recoded it. This is more efficient.
 

Executor

I see you
Reaction score
57
Greetz, good job.

But why don't you use the 'auto recycle' of the struct? When creating a new instance check whether group is null and create a new group. Now simply don't destroy the group when deallocationg. Finish.
 

Sickle

New Member
Reaction score
13
>>Nothing is wrong with TimerUtils.

T32 is better for this application, however.
 

Executor

I see you
Reaction score
57
It's wrong that he uses one timer per instance and not one global timer (with or without T32), which loops all structs periodically (thats why I said linked list :)).
 

LearningCode

New Member
Reaction score
24
Look like cool!:thup:

But you should remove BJs

JASS:
        call PlaySoundAtPointBJ(gg_snd_Ama_Firen_Mah_Lazar,100,l,0)
        call CreateTextTagUnitBJ( &quot;Ama Firen Mah Lazar&quot;,u,0,10,100,100,100,0)
        call SetTextTagPermanentBJ(bj_lastCreatedTextTag,false)
        call SetTextTagLifespanBJ(bj_lastCreatedTextTag,2)
        call SetTextTagFadepointBJ(bj_lastCreatedTextTag,1)
        call SetTextTagVelocityBJ(bj_lastCreatedTextTag,64,90)

:p
EDIT: +rep!

JASS:

        local texttag tag 
        local real tagspd = 64 * 0.071 / 128
        local real rad = 1.57
        local real x = tagspd * Cos(rad)
        local real y = tagspd * Sin(rad)
        
        call PlaySoundAtPointBJ(gg_snd_Ama_Firen_Mah_Lazar,100,l,0)
        
        set tag = call CreateTextTagUnitBJ( &quot;Ama Firen Mah Lazar&quot;,u,0,10,100,100,100,0)
        call SetTextTagPermanent(tag,false)
        call SetTextTagLifespan(tag,2.)
        call SetTextTagFadepoint(tag,1.)
        call SetTextTagVelocity(tag,x,y)
        set tag = null


Like this? o.0
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Nothing is wrong with TimerUtils.
Actually using T32 also reduces your usage of handle. T32 consists of 1 trigger, 1 timer, 1 linked list per struct.

Short period :
T32

Short period(other than T32) :
KT2, TT

Long period :
TimerUtils/ABC
KT2 does not performs well in long period because of it's big allocation code and it needs to "hack" in the linked list of data.
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
Updated again! I fix bug on fly heights. Well, test the map again lewl/
 
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